Skip to content

Commit

Permalink
Fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MartijnMuijsers committed Feb 12, 2024
1 parent 928fc8e commit b44cd63
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Fiddle - https://fiddlemc.org

diff --git a/src/main/java/org/fiddlemc/fiddle/material/OrderedEmptyMaterial.java b/src/main/java/org/fiddlemc/fiddle/material/OrderedEmptyMaterial.java
new file mode 100644
index 0000000000000000000000000000000000000000..0847d6bce01e09c3058beb2617a5dedc62fcf56f
index 0000000000000000000000000000000000000000..1f399711d91de87bf40e06536fdd2fcf9ff25450
--- /dev/null
+++ b/src/main/java/org/fiddlemc/fiddle/material/OrderedEmptyMaterial.java
@@ -0,0 +1,1880 @@
@@ -0,0 +1,1937 @@
+// Fiddle start - modifiable Bukkit enums - Material - remember original order
+
+package org.fiddlemc.fiddle.material;
Expand Down Expand Up @@ -47,6 +47,19 @@ index 0000000000000000000000000000000000000000..0847d6bce01e09c3058beb2617a5dedc
+ POLISHED_DEEPSLATE,
+ CALCITE,
+ TUFF,
+ TUFF_SLAB,
+ TUFF_STAIRS,
+ TUFF_WALL,
+ CHISELED_TUFF,
+ POLISHED_TUFF,
+ POLISHED_TUFF_SLAB,
+ POLISHED_TUFF_STAIRS,
+ POLISHED_TUFF_WALL,
+ TUFF_BRICKS,
+ TUFF_BRICK_SLAB,
+ TUFF_BRICK_STAIRS,
+ TUFF_BRICK_WALL,
+ CHISELED_TUFF_BRICKS,
+ DRIPSTONE_BLOCK,
+ GRASS_BLOCK,
+ DIRT,
Expand Down Expand Up @@ -116,6 +129,10 @@ index 0000000000000000000000000000000000000000..0847d6bce01e09c3058beb2617a5dedc
+ EXPOSED_COPPER,
+ WEATHERED_COPPER,
+ OXIDIZED_COPPER,
+ CHISELED_COPPER,
+ EXPOSED_CHISELED_COPPER,
+ WEATHERED_CHISELED_COPPER,
+ OXIDIZED_CHISELED_COPPER,
+ CUT_COPPER,
+ EXPOSED_CUT_COPPER,
+ WEATHERED_CUT_COPPER,
Expand All @@ -132,6 +149,10 @@ index 0000000000000000000000000000000000000000..0847d6bce01e09c3058beb2617a5dedc
+ WAXED_EXPOSED_COPPER,
+ WAXED_WEATHERED_COPPER,
+ WAXED_OXIDIZED_COPPER,
+ WAXED_CHISELED_COPPER,
+ WAXED_EXPOSED_CHISELED_COPPER,
+ WAXED_WEATHERED_CHISELED_COPPER,
+ WAXED_OXIDIZED_CHISELED_COPPER,
+ WAXED_CUT_COPPER,
+ WAXED_EXPOSED_CUT_COPPER,
+ WAXED_WEATHERED_CUT_COPPER,
Expand Down Expand Up @@ -207,7 +228,7 @@ index 0000000000000000000000000000000000000000..0847d6bce01e09c3058beb2617a5dedc
+ CHISELED_SANDSTONE,
+ CUT_SANDSTONE,
+ COBWEB,
+ GRASS,
+ SHORT_GRASS,
+ FERN,
+ AZALEA,
+ FLOWERING_AZALEA,
Expand Down Expand Up @@ -734,6 +755,14 @@ index 0000000000000000000000000000000000000000..0847d6bce01e09c3058beb2617a5dedc
+ BAMBOO_DOOR,
+ CRIMSON_DOOR,
+ WARPED_DOOR,
+ COPPER_DOOR,
+ EXPOSED_COPPER_DOOR,
+ WEATHERED_COPPER_DOOR,
+ OXIDIZED_COPPER_DOOR,
+ WAXED_COPPER_DOOR,
+ WAXED_EXPOSED_COPPER_DOOR,
+ WAXED_WEATHERED_COPPER_DOOR,
+ WAXED_OXIDIZED_COPPER_DOOR,
+ IRON_TRAPDOOR,
+ OAK_TRAPDOOR,
+ SPRUCE_TRAPDOOR,
Expand All @@ -746,6 +775,14 @@ index 0000000000000000000000000000000000000000..0847d6bce01e09c3058beb2617a5dedc
+ BAMBOO_TRAPDOOR,
+ CRIMSON_TRAPDOOR,
+ WARPED_TRAPDOOR,
+ COPPER_TRAPDOOR,
+ EXPOSED_COPPER_TRAPDOOR,
+ WEATHERED_COPPER_TRAPDOOR,
+ OXIDIZED_COPPER_TRAPDOOR,
+ WAXED_COPPER_TRAPDOOR,
+ WAXED_EXPOSED_COPPER_TRAPDOOR,
+ WAXED_WEATHERED_COPPER_TRAPDOOR,
+ WAXED_OXIDIZED_COPPER_TRAPDOOR,
+ OAK_FENCE_GATE,
+ SPRUCE_FENCE_GATE,
+ BIRCH_FENCE_GATE,
Expand Down Expand Up @@ -975,6 +1012,7 @@ index 0000000000000000000000000000000000000000..0847d6bce01e09c3058beb2617a5dedc
+ RED_BED,
+ BLACK_BED,
+ COOKIE,
+ CRAFTER,
+ FILLED_MAP,
+ SHEARS,
+ MELON_SLICE,
Expand Down Expand Up @@ -1006,6 +1044,7 @@ index 0000000000000000000000000000000000000000..0847d6bce01e09c3058beb2617a5dedc
+ BAT_SPAWN_EGG,
+ BEE_SPAWN_EGG,
+ BLAZE_SPAWN_EGG,
+ BREEZE_SPAWN_EGG,
+ CAT_SPAWN_EGG,
+ CAMEL_SPAWN_EGG,
+ CAVE_SPIDER_SPAWN_EGG,
Expand Down Expand Up @@ -1289,6 +1328,24 @@ index 0000000000000000000000000000000000000000..0847d6bce01e09c3058beb2617a5dedc
+ SHELTER_POTTERY_SHERD,
+ SKULL_POTTERY_SHERD,
+ SNORT_POTTERY_SHERD,
+ COPPER_GRATE,
+ EXPOSED_COPPER_GRATE,
+ WEATHERED_COPPER_GRATE,
+ OXIDIZED_COPPER_GRATE,
+ WAXED_COPPER_GRATE,
+ WAXED_EXPOSED_COPPER_GRATE,
+ WAXED_WEATHERED_COPPER_GRATE,
+ WAXED_OXIDIZED_COPPER_GRATE,
+ COPPER_BULB,
+ EXPOSED_COPPER_BULB,
+ WEATHERED_COPPER_BULB,
+ OXIDIZED_COPPER_BULB,
+ WAXED_COPPER_BULB,
+ WAXED_EXPOSED_COPPER_BULB,
+ WAXED_WEATHERED_COPPER_BULB,
+ WAXED_OXIDIZED_COPPER_BULB,
+ TRIAL_SPAWNER,
+ TRIAL_KEY,
+ WATER,
+ LAVA,
+ TALL_SEAGRASS,
Expand Down Expand Up @@ -1902,26 +1959,26 @@ index 0000000000000000000000000000000000000000..0847d6bce01e09c3058beb2617a5dedc
+}
diff --git a/src/test/java/org/fiddlemc/fiddle/material/OrderedEmptyMaterialTest.java b/src/test/java/org/fiddlemc/fiddle/material/OrderedEmptyMaterialTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..41728dd38bd9f3a98a91e4848016a4068521eac6
index 0000000000000000000000000000000000000000..0f93abaf6239d8a4ffe0a4a3ba5843a950a2fffe
--- /dev/null
+++ b/src/test/java/org/fiddlemc/fiddle/material/OrderedEmptyMaterialTest.java
@@ -0,0 +1,20 @@
+package org.fiddlemc.fiddle.material;
+
+import org.bukkit.Material;
+import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class OrderedEmptyMaterialTest {
+
+ @Test
+ public void equalsOriginalOrder() {
+ var materialValues = Material.values();
+ var orderedEmptyMaterialValues = OrderedEmptyMaterial.values();
+ assertEquals("OrderedEmptyMaterial has the same number of values as Material", materialValues.length, orderedEmptyMaterialValues.length);
+ assertEquals(materialValues.length, orderedEmptyMaterialValues.length, "OrderedEmptyMaterial has a different number of values as Material");
+ for (int i = 0; i < materialValues.length; i++) {
+ assertEquals("The OrderedEmptyMaterial instance at ordinal " + i + " has the same name as the Material value at that ordinal", materialValues[i].name(), orderedEmptyMaterialValues[i].name());
+ assertEquals(materialValues[i].name(), orderedEmptyMaterialValues[i].name(), "The OrderedEmptyMaterial instance at ordinal " + i + " has a different name as the Material value at that ordinal");
+ }
+ }
+
Expand Down
16 changes: 8 additions & 8 deletions patches/server/0032-Cache-Block-and-Item-registry-key.patch
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,16 @@ index e74f8c9b43894534fe624988ec9a3ca190ae5770..ac34e35521bb6772d25d1d5f43b9edd0
+
}
diff --git a/src/test/java/org/fiddlemc/fiddle/block/PerBlockTest.java b/src/test/java/org/fiddlemc/fiddle/block/PerBlockTest.java
index 4ad77f8ce7b43b5b54d7f7d1f9dfdebdd0ca9d8f..bc9f7245a13a8a336cda803c8b23010098e7d83d 100644
index 4ad77f8ce7b43b5b54d7f7d1f9dfdebdd0ca9d8f..cc59e81f1670e34f357d96c9be316af382322301 100644
--- a/src/test/java/org/fiddlemc/fiddle/block/PerBlockTest.java
+++ b/src/test/java/org/fiddlemc/fiddle/block/PerBlockTest.java
@@ -5,6 +5,9 @@ package org.fiddlemc.fiddle.block;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.level.block.Block;
import org.bukkit.support.AbstractTestingBase;
+import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;

public class PerBlockTest extends AbstractTestingBase {

Expand All @@ -147,23 +147,23 @@ index 4ad77f8ce7b43b5b54d7f7d1f9dfdebdd0ca9d8f..bc9f7245a13a8a336cda803c8b230100
+ @Test
+ public void keyInBlockRegistry() {
+ for (Block block : getBlocks()) {
+ assertEquals("Lookup value equals keyInBlockRegistry for " + block, BuiltInRegistries.BLOCK.getKey(block), block.keyInBlockRegistry);
+ assertEquals(BuiltInRegistries.BLOCK.getKey(block), block.keyInBlockRegistry, "Lookup value does not equal keyInBlockRegistry for " + block);
+ }
+ }
+ // Fiddle end - cache registry keys as fields - block
+
}
diff --git a/src/test/java/org/fiddlemc/fiddle/item/PerItemTest.java b/src/test/java/org/fiddlemc/fiddle/item/PerItemTest.java
index d1d9ee8190fa648efacea96ddaf5b55801e2ade7..ee38ae7143ebb5c05e51ab31956a6023f558625b 100644
index d1d9ee8190fa648efacea96ddaf5b55801e2ade7..799295777aaa2ed7d90b8a2a37c1dc30cfc3bf72 100644
--- a/src/test/java/org/fiddlemc/fiddle/item/PerItemTest.java
+++ b/src/test/java/org/fiddlemc/fiddle/item/PerItemTest.java
@@ -5,6 +5,9 @@ package org.fiddlemc.fiddle.item;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.item.Item;
import org.bukkit.support.AbstractTestingBase;
+import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;

public class PerItemTest extends AbstractTestingBase {

Expand All @@ -175,7 +175,7 @@ index d1d9ee8190fa648efacea96ddaf5b55801e2ade7..ee38ae7143ebb5c05e51ab31956a6023
+ @Test
+ public void keyInItemRegistry() {
+ for (Item item : getItems()) {
+ assertEquals("Lookup value equals keyInItemRegistry for " + item, BuiltInRegistries.ITEM.getKey(item), item.keyInItemRegistry);
+ assertEquals(BuiltInRegistries.ITEM.getKey(item), item.keyInItemRegistry, "Lookup value does not equal keyInItemRegistry for " + item);
+ }
+ }
+ // Fiddle end - cache registry keys as fields - item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ index 94ff1dd6849f1e4f225254ff5c36421c7632b897..c5a0911cd33229c8a952293aacfc30b2

}
diff --git a/src/test/java/org/fiddlemc/fiddle/block/PerBlockTest.java b/src/test/java/org/fiddlemc/fiddle/block/PerBlockTest.java
index bc9f7245a13a8a336cda803c8b23010098e7d83d..f6d757b6401b19ce66037442e0b40530fe5e7782 100644
index cc59e81f1670e34f357d96c9be316af382322301..51c4f8d436fb54bca00abb6f14753641e8f1bae7 100644
--- a/src/test/java/org/fiddlemc/fiddle/block/PerBlockTest.java
+++ b/src/test/java/org/fiddlemc/fiddle/block/PerBlockTest.java
@@ -24,4 +24,26 @@ public class PerBlockTest extends AbstractTestingBase {
Expand All @@ -264,8 +264,8 @@ index bc9f7245a13a8a336cda803c8b23010098e7d83d..f6d757b6401b19ce66037442e0b40530
+ @Test
+ public void indexInBlockRegistry() {
+ for (Block block : getBlocks()) {
+ assertEquals("Lookup value equals indexInBlockRegistry for " + block, BuiltInRegistries.BLOCK.getId(block), block.indexInBlockRegistry);
+ assertEquals("Lookup value equals indexInVanillaOnlyBlockRegistry for " + block, Block.VANILLA_ONLY_BLOCK_REGISTRY.getId(block), block.indexInVanillaOnlyBlockRegistry);
+ assertEquals(BuiltInRegistries.BLOCK.getId(block), block.indexInBlockRegistry, "Lookup value does not equal indexInBlockRegistry for " + block);
+ assertEquals(Block.VANILLA_ONLY_BLOCK_REGISTRY.getId(block), block.indexInVanillaOnlyBlockRegistry, "Lookup value does not equal indexInVanillaOnlyBlockRegistry for " + block);
+ }
+ }
+ // Fiddle end - cache registry indices as fields - block
Expand All @@ -275,16 +275,16 @@ index bc9f7245a13a8a336cda803c8b23010098e7d83d..f6d757b6401b19ce66037442e0b40530
+ public void indexInBlockStateRegistry() {
+ for (Block block : getBlocks()) {
+ for (var state : block.getStateDefinition().getPossibleStates()) {
+ assertEquals("Lookup value equals indexInBlockStateRegistry for " + state, Block.BLOCK_STATE_REGISTRY.getId(state), state.indexInBlockStateRegistry);
+ assertEquals("Lookup value equals indexInVanillaOnlyBlockStateRegistry for " + state, Block.VANILLA_ONLY_BLOCK_STATE_REGISTRY.getId(state), state.indexInVanillaOnlyBlockStateRegistry);
+ assertEquals(Block.BLOCK_STATE_REGISTRY.getId(state), state.indexInBlockStateRegistry, "Lookup does not equal indexInBlockStateRegistry for " + state);
+ assertEquals(Block.VANILLA_ONLY_BLOCK_STATE_REGISTRY.getId(state), state.indexInVanillaOnlyBlockStateRegistry, "Lookup value does not equal indexInVanillaOnlyBlockStateRegistry for " + state);
+ }
+ }
+ }
+ // Fiddle start - cache registry indices as fields - block state
+
}
diff --git a/src/test/java/org/fiddlemc/fiddle/item/PerItemTest.java b/src/test/java/org/fiddlemc/fiddle/item/PerItemTest.java
index ee38ae7143ebb5c05e51ab31956a6023f558625b..0fa9b94adb8fa061cf294f94a84245509ffd7de9 100644
index 799295777aaa2ed7d90b8a2a37c1dc30cfc3bf72..227e5d9c75791b6472feac1323cbab40fb76f655 100644
--- a/src/test/java/org/fiddlemc/fiddle/item/PerItemTest.java
+++ b/src/test/java/org/fiddlemc/fiddle/item/PerItemTest.java
@@ -24,4 +24,14 @@ public class PerItemTest extends AbstractTestingBase {
Expand All @@ -295,8 +295,8 @@ index ee38ae7143ebb5c05e51ab31956a6023f558625b..0fa9b94adb8fa061cf294f94a8424550
+ @Test
+ public void indexInItemRegistry() {
+ for (Item item : getItems()) {
+ assertEquals("Lookup value equals indexInItemRegistry for " + item, BuiltInRegistries.ITEM.getId(item), item.indexInItemRegistry);
+ assertEquals("Lookup value equals indexInVanillaOnlyItemRegistry for " + item, Item.VANILLA_ONLY_ITEM_REGISTRY.getId(item), item.indexInVanillaOnlyItemRegistry);
+ assertEquals(BuiltInRegistries.ITEM.getId(item), item.indexInItemRegistry, "Lookup value does not equal indexInItemRegistry for " + item);
+ assertEquals(Item.VANILLA_ONLY_ITEM_REGISTRY.getId(item), item.indexInVanillaOnlyItemRegistry, "Lookup value does not equal indexInVanillaOnlyItemRegistry for " + item);
+ }
+ }
+ // Fiddle end - cache registry indices as fields - item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ Fiddle - https://fiddlemc.org

diff --git a/src/test/java/org/fiddlemc/fiddle/material/legacy/PerLegacyMaterialTest.java b/src/test/java/org/fiddlemc/fiddle/material/legacy/PerLegacyMaterialTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..95e539a0c7ede3a4bed906a6e624ab328480d0e6
index 0000000000000000000000000000000000000000..3087de012e42239a362b612bb9474c3d8dd2ab10
--- /dev/null
+++ b/src/test/java/org/fiddlemc/fiddle/material/legacy/PerLegacyMaterialTest.java
@@ -0,0 +1,38 @@
@@ -0,0 +1,39 @@
+// Fiddle - modifiable Bukkit enums - Material - make legacy conversion complete - tests
+
+package org.fiddlemc.fiddle.material.legacy;
+
+import org.bukkit.Material;
+import org.bukkit.craftbukkit.legacy.CraftLegacy;
+import org.bukkit.support.AbstractTestingBase;
+import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+
+import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Does a number of sanity checks on {@linkplain Material#isLegacy() legacy} {@link Material}s.
Expand All @@ -46,16 +47,16 @@ index 0000000000000000000000000000000000000000..95e539a0c7ede3a4bed906a6e624ab32
+ var nonLegacy = CraftLegacy.fromLegacy(material, itemPriority);
+
+ // then
+ assertNotNull("Non-legacy is non-null for " + material + " with item priority = " + itemPriority, nonLegacy);
+ assertEquals("Non-legacy is non-air (unless original is legacy air) for " + material + " with item priority = " + itemPriority,material == Material.LEGACY_AIR, nonLegacy == Material.AIR);
+ assertNotNull(nonLegacy, "Non-legacy mapping is null for " + material + " with item priority = " + itemPriority);
+ assertEquals(material == Material.LEGACY_AIR, nonLegacy == Material.AIR, "Non-legacy mapping is air while original is non-air (or the other way around) for " + material + " with item priority = " + itemPriority);
+ }
+ }
+ }
+
+}
diff --git a/src/test/java/org/fiddlemc/fiddle/material/legacy/PerNonLegacyMaterialTest.java b/src/test/java/org/fiddlemc/fiddle/material/legacy/PerNonLegacyMaterialTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..4a0b27c8472e8f694841a7dd76066e5023c17148
index 0000000000000000000000000000000000000000..bee17680ef980db47e3ea84f273be73b549420ee
--- /dev/null
+++ b/src/test/java/org/fiddlemc/fiddle/material/legacy/PerNonLegacyMaterialTest.java
@@ -0,0 +1,38 @@
Expand All @@ -66,12 +67,12 @@ index 0000000000000000000000000000000000000000..4a0b27c8472e8f694841a7dd76066e50
+import org.bukkit.Material;
+import org.bukkit.craftbukkit.legacy.CraftLegacy;
+import org.bukkit.support.AbstractTestingBase;
+import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.function.Predicate;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Does a number of sanity checks on {@linkplain Material#isLegacy() non-legacy Materials}.
Expand All @@ -91,7 +92,7 @@ index 0000000000000000000000000000000000000000..4a0b27c8472e8f694841a7dd76066e50
+ var nonLegacy = CraftLegacy.fromLegacy(material, itemPriority);
+
+ // then
+ assertEquals("Non-legacy is self for " + material + " with item priority = " + itemPriority, material, nonLegacy);
+ assertEquals(material, nonLegacy, "Non-legacy mapping is not self for " + material + " with item priority = " + itemPriority);
+ }
+ }
+ }
Expand Down
Loading

0 comments on commit b44cd63

Please sign in to comment.