diff options
author | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2023-12-22 23:29:43 +0800 |
---|---|---|
committer | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2023-12-22 23:57:52 +0800 |
commit | 05e6d2eca5f8d3f1f3a6201eeed9f64847572670 (patch) | |
tree | b19ea1a4f9689c8f178484b2ca43db0c1946caa1 /src/test/java/de/hysky/skyblocker/skyblock/dungeon | |
parent | 69082b40918af3ac4e24d38ebda95a24247e0ded (diff) | |
download | Skyblocker-05e6d2eca5f8d3f1f3a6201eeed9f64847572670.tar.gz Skyblocker-05e6d2eca5f8d3f1f3a6201eeed9f64847572670.tar.bz2 Skyblocker-05e6d2eca5f8d3f1f3a6201eeed9f64847572670.zip |
Add fabric loader junit and ItemUtilsTest
Diffstat (limited to 'src/test/java/de/hysky/skyblocker/skyblock/dungeon')
-rw-r--r-- | src/test/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypointTest.java | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypointTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypointTest.java index 4c81bfb4..12bfe98b 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypointTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypointTest.java @@ -4,8 +4,11 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.mojang.serialization.JsonOps; +import net.minecraft.Bootstrap; +import net.minecraft.SharedConstants; import net.minecraft.util.math.BlockPos; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import java.util.List; @@ -13,47 +16,52 @@ import java.util.List; public class SecretWaypointTest { private final Gson gson = new Gson(); - //These tests throw java.lang.NoClassDefFoundError - /*@Test + @BeforeAll + public static void setup() { + SharedConstants.createGameVersion(); + Bootstrap.initialize(); + } + + @Test void testCodecSerialize() { - SecretWaypoint waypoint = new SecretWaypoint(0, SecretWaypoint.Category.DEFAULT, "name", BlockPos.ORIGIN); + SecretWaypoint waypoint = new SecretWaypoint(0, SecretWaypoint.Category.DEFAULT, "name", new BlockPos(-1, 0, 1)); JsonElement json = SecretWaypoint.CODEC.encodeStart(JsonOps.INSTANCE, waypoint).result().orElseThrow(); - String expectedJson = "{\"secretIndex\":0,\"category\":\"default\",\"name\":{\"text\":\"name\"},\"pos\":[0,0,0]}"; + String expectedJson = "{\"secretIndex\":0,\"category\":\"default\",\"name\":\"name\",\"pos\":[-1,0,1]}"; Assertions.assertEquals(expectedJson, json.toString()); } @Test void testCodecDeserialize() { - String json = "{\"secretIndex\":0,\"category\":\"default\",\"name\":{\"text\":\"name\"},\"pos\":[0,0,0]}"; + String json = "{\"secretIndex\":0,\"category\":\"default\",\"name\":\"name\",\"pos\":[-1,0,1]}"; SecretWaypoint waypoint = SecretWaypoint.CODEC.parse(JsonOps.INSTANCE, gson.fromJson(json, JsonElement.class)).result().orElseThrow(); - SecretWaypoint expectedWaypoint = new SecretWaypoint(0, SecretWaypoint.Category.DEFAULT, "name", BlockPos.ORIGIN); + SecretWaypoint expectedWaypoint = new SecretWaypoint(0, SecretWaypoint.Category.DEFAULT, "name", new BlockPos(-1, 0, 1)); - equal(expectedWaypoint, waypoint); + Assertions.assertEquals(expectedWaypoint, waypoint); } @Test void testListCodecSerialize() { - List<SecretWaypoint> waypoints = List.of(new SecretWaypoint(0, SecretWaypoint.Category.DEFAULT, "name", BlockPos.ORIGIN), new SecretWaypoint(1, SecretWaypoint.Category.CHEST, "name", new BlockPos(-1, 0, 1))); + List<SecretWaypoint> waypoints = List.of(new SecretWaypoint(0, SecretWaypoint.Category.DEFAULT, "name", new BlockPos(-1, 0, 1)), new SecretWaypoint(1, SecretWaypoint.Category.CHEST, "name", new BlockPos(2, 0, -2))); JsonElement json = SecretWaypoint.LIST_CODEC.encodeStart(JsonOps.INSTANCE, waypoints).result().orElseThrow(); - String expectedJson = "[{\"secretIndex\":0,\"category\":\"default\",\"name\":{\"text\":\"name\"},\"pos\":[0,0,0]},{\"secretIndex\":1,\"category\":\"chest\",\"name\":{\"text\":\"name\"},\"pos\":[-1,0,1]}]"; + String expectedJson = "[{\"secretIndex\":0,\"category\":\"default\",\"name\":\"name\",\"pos\":[-1,0,1]},{\"secretIndex\":1,\"category\":\"chest\",\"name\":\"name\",\"pos\":[2,0,-2]}]"; Assertions.assertEquals(expectedJson, json.toString()); } @Test void testListCodecDeserialize() { - String json = "[{\"secretIndex\":0,\"category\":\"default\",\"name\":{\"text\":\"name\"},\"pos\":[0,0,0]},{\"secretIndex\":1,\"category\":\"chest\",\"name\":{\"text\":\"name\"},\"pos\":[-1,0,1]}]"; + String json = "[{\"secretIndex\":0,\"category\":\"default\",\"name\":\"name\",\"pos\":[-1,0,1]},{\"secretIndex\":1,\"category\":\"chest\",\"name\":\"name\",\"pos\":[2,0,-2]}]"; List<SecretWaypoint> waypoints = SecretWaypoint.LIST_CODEC.parse(JsonOps.INSTANCE, gson.fromJson(json, JsonElement.class)).result().orElseThrow(); - List<SecretWaypoint> expectedWaypoints = List.of(new SecretWaypoint(0, SecretWaypoint.Category.DEFAULT, "name", BlockPos.ORIGIN), new SecretWaypoint(1, SecretWaypoint.Category.CHEST, "name", new BlockPos(-1, 0, 1))); + List<SecretWaypoint> expectedWaypoints = List.of(new SecretWaypoint(0, SecretWaypoint.Category.DEFAULT, "name", new BlockPos(-1, 0, 1)), new SecretWaypoint(1, SecretWaypoint.Category.CHEST, "name", new BlockPos(2, 0, -2))); Assertions.assertEquals(expectedWaypoints.size(), waypoints.size()); for (int i = 0; i < expectedWaypoints.size(); i++) { SecretWaypoint expectedWaypoint = expectedWaypoints.get(i); SecretWaypoint waypoint = waypoints.get(i); - equal(expectedWaypoint, waypoint); + Assertions.assertEquals(expectedWaypoint, waypoint); } - }*/ + } @Test void testGetCategory() { @@ -70,11 +78,4 @@ public class SecretWaypointTest { SecretWaypoint.Category category = SecretWaypoint.Category.get(waypointJson); Assertions.assertEquals(SecretWaypoint.Category.DEFAULT, category); } - - private static void equal(SecretWaypoint expectedWaypoint, SecretWaypoint waypoint) { - Assertions.assertEquals(expectedWaypoint.secretIndex, waypoint.secretIndex); - Assertions.assertEquals(expectedWaypoint.category, waypoint.category); - Assertions.assertEquals(expectedWaypoint.name, waypoint.name); - Assertions.assertEquals(expectedWaypoint.pos, waypoint.pos); - } } |