diff options
Diffstat (limited to 'src/test/java')
3 files changed, 66 insertions, 0 deletions
diff --git a/src/test/java/de/hysky/skyblocker/utils/PosUtilsTest.java b/src/test/java/de/hysky/skyblocker/utils/PosUtilsTest.java index 1f433af3..470ea079 100644 --- a/src/test/java/de/hysky/skyblocker/utils/PosUtilsTest.java +++ b/src/test/java/de/hysky/skyblocker/utils/PosUtilsTest.java @@ -1,5 +1,7 @@ package de.hysky.skyblocker.utils; +import com.google.gson.JsonObject; +import de.hysky.skyblocker.SkyblockerMod; import net.minecraft.util.math.BlockPos; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -11,6 +13,11 @@ public class PosUtilsTest { } @Test + void testParsePosJson() { + Assertions.assertEquals(PosUtils.parsePosJson(SkyblockerMod.GSON.fromJson("{\"x\":-1,\"y\":0,\"z\":1}", JsonObject.class)), new BlockPos(-1, 0, 1)); + } + + @Test void testGetPosString() { Assertions.assertEquals(PosUtils.getPosString(new BlockPos(-1, 0, 1)), "-1,0,1"); } diff --git a/src/test/java/de/hysky/skyblocker/utils/waypoint/WaypointCategoryTest.java b/src/test/java/de/hysky/skyblocker/utils/waypoint/WaypointCategoryTest.java new file mode 100644 index 00000000..65304e0c --- /dev/null +++ b/src/test/java/de/hysky/skyblocker/utils/waypoint/WaypointCategoryTest.java @@ -0,0 +1,39 @@ +package de.hysky.skyblocker.utils.waypoint; + +import com.google.gson.JsonElement; +import com.mojang.serialization.JsonOps; +import de.hysky.skyblocker.SkyblockerMod; +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; + +public class WaypointCategoryTest { + @BeforeAll + static void beforeAll() { + SharedConstants.createGameVersion(); + Bootstrap.initialize(); + } + + @Test + void testCodecEncode() { + WaypointCategory category = new WaypointCategory("category", "hub", List.of(new NamedWaypoint(BlockPos.ORIGIN, "waypoint", new float[]{0f, 0.5f, 1f}, false), new NamedWaypoint(new BlockPos(-1, 0, 1), "waypoint", new float[]{0f, 0f, 0f}, true))); + Object categoryJson = WaypointCategory.CODEC.encodeStart(JsonOps.INSTANCE, category).result().orElseThrow(); + String expectedJson = "{\"name\":\"category\",\"island\":\"hub\",\"waypoints\":[{\"pos\":[0,0,0],\"name\":\"waypoint\",\"colorComponents\":[0.0,0.5,1.0],\"shouldRender\":false},{\"pos\":[-1,0,1],\"name\":\"waypoint\",\"colorComponents\":[0.0,0.0,0.0],\"shouldRender\":true}]}"; + + Assertions.assertEquals(expectedJson, categoryJson.toString()); + } + + @Test + void testCodecDecode() { + String categoryJson = "{\"name\":\"category\",\"island\":\"hub\",\"waypoints\":[{\"pos\":[0,0,0],\"name\":\"waypoint\",\"colorComponents\":[0.0,0.5,1.0],\"shouldRender\":false},{\"pos\":[-1,0,1],\"name\":\"waypoint\",\"colorComponents\":[0.0,0.0,0.0],\"shouldRender\":true}]}"; + WaypointCategory category = WaypointCategory.CODEC.parse(JsonOps.INSTANCE, SkyblockerMod.GSON.fromJson(categoryJson, JsonElement.class)).result().orElseThrow(); + WaypointCategory expectedCategory = new WaypointCategory("category", "hub", List.of(new NamedWaypoint(BlockPos.ORIGIN, "waypoint", new float[]{0f, 0.5f, 1f}, false), new NamedWaypoint(new BlockPos(-1, 0, 1), "waypoint", new float[]{0f, 0f, 0f}, true))); + + Assertions.assertEquals(expectedCategory, category); + } +} diff --git a/src/test/java/de/hysky/skyblocker/utils/waypoint/WaypointsTest.java b/src/test/java/de/hysky/skyblocker/utils/waypoint/WaypointsTest.java new file mode 100644 index 00000000..91470224 --- /dev/null +++ b/src/test/java/de/hysky/skyblocker/utils/waypoint/WaypointsTest.java @@ -0,0 +1,20 @@ +package de.hysky.skyblocker.utils.waypoint; + +import de.hysky.skyblocker.skyblock.waypoint.Waypoints; +import net.minecraft.util.math.BlockPos; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.Collection; +import java.util.List; + +public class WaypointsTest { + @Test + void testFromSkytilsBase64() { + String waypointCategoriesSkytilsBase64 = "eyJjYXRlZ29yaWVzIjpbeyJuYW1lIjoiY2F0ZWdvcnkiLCJ3YXlwb2ludHMiOlt7Im5hbWUiOiJ3YXlwb2ludCIsIngiOjAsInkiOjAsInoiOjAsImVuYWJsZWQiOmZhbHNlLCJjb2xvciI6MzMwMjMsImFkZGVkQXQiOjF9LHsibmFtZSI6MSwieCI6LTEsInkiOjAsInoiOjEsImVuYWJsZWQiOnRydWUsImNvbG9yIjowLCJhZGRlZEF0IjoxfV0sImlzbGFuZCI6Imh1YiJ9XX0="; + Collection<WaypointCategory> waypointCategories = Waypoints.fromSkytilsBase64(waypointCategoriesSkytilsBase64); + Collection<WaypointCategory> expectedWaypointCategories = List.of(new WaypointCategory("category", "hub", List.of(new NamedWaypoint(BlockPos.ORIGIN, "waypoint", new float[]{0f, 0.5f, 1f}, false), new NamedWaypoint(new BlockPos(-1, 0, 1), "1", new float[]{0f, 0f, 0f}, true)))); + + Assertions.assertEquals(expectedWaypointCategories, waypointCategories); + } +} |