improve checking handled tags in itemmeta

This commit is contained in:
Jake Potrebic
2023-07-10 16:10:15 -07:00
parent 50b91c7359
commit ae4acc6aeb
33 changed files with 225 additions and 158 deletions

View File

@@ -97,7 +97,7 @@ public class DeprecatedItemMetaCustomValueTest {
CraftMetaItem.Applicator compound = new CraftMetaItem.Applicator();
itemMeta.applyToItem(compound);
assertEquals(itemMeta, new CraftMetaItem(compound.build()));
assertEquals(itemMeta, new CraftMetaItem(compound.build(), null)); // Paper
}
@Test

View File

@@ -0,0 +1,33 @@
package org.bukkit.craftbukkit.inventory;
import io.github.classgraph.ClassGraph;
import io.github.classgraph.ClassInfo;
import io.github.classgraph.ClassInfoList;
import io.github.classgraph.ScanResult;
import org.bukkit.support.environment.AllFeatures;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
// in cb package because of package-private stuff
@AllFeatures
class MetaHandledTagsTest {
@Test
public void checkAllMetasHaveHandledTags() {
try (final ScanResult result = new ClassGraph()
.whitelistPackages("org.bukkit.craftbukkit.inventory")
.enableClassInfo().scan()) {
final ClassInfoList subclasses = result.getSubclasses(CraftMetaItem.class.getName());
assertFalse(subclasses.isEmpty(), "found 0 sub types");
for (final ClassInfo subclass : subclasses) {
final Class<CraftMetaItem> clazz = subclass.loadClass(CraftMetaItem.class);
CraftMetaItem.getTopLevelHandledDcts(clazz); // load into map
assertTrue(CraftMetaItem.HANDLED_DCTS_PER_TYPE.containsKey(clazz), subclass.getName() + " not found in handled tags map");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -131,7 +131,7 @@ public class PersistentDataContainerTest {
CraftMetaItem.Applicator compound = new CraftMetaItem.Applicator();
itemMeta.applyToItem(compound);
assertEquals(itemMeta, new CraftMetaItem(compound.build()));
assertEquals(itemMeta, new CraftMetaItem(compound.build(), null)); // Paper
}
@Test
@@ -464,7 +464,7 @@ public class PersistentDataContainerTest {
@Test
public void testEmptyListApplicationToAnyType() throws IOException {
final CraftMetaItem craftItem = new CraftMetaItem(DataComponentPatch.EMPTY);
final CraftMetaItem craftItem = new CraftMetaItem(DataComponentPatch.EMPTY, null); // Paper
final PersistentDataContainer container = craftItem.getPersistentDataContainer();
container.set(PersistentDataContainerTest.requestKey("list"), PersistentDataType.LIST.strings(), List.of());
@@ -477,7 +477,7 @@ public class PersistentDataContainerTest {
final CraftMetaItem.Applicator storage = new CraftMetaItem.Applicator();
craftItem.applyToItem(storage);
final CraftMetaItem readItem = new CraftMetaItem(storage.build());
final CraftMetaItem readItem = new CraftMetaItem(storage.build(), null); // Paper
final PersistentDataContainer readContainer = readItem.getPersistentDataContainer();
assertTrue(readContainer.has(PersistentDataContainerTest.requestKey("list"), PersistentDataType.LIST.strings()));