aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorKevin <92656833+kevinthegreat1@users.noreply.github.com>2025-06-07 10:33:06 +0800
committerGitHub <noreply@github.com>2025-06-06 22:33:06 -0400
commitbf0aa92552375465d9269c615d6ead54e74fbf0e (patch)
tree1c8bb0f9ef0f9b1e64effbc293b7750776b58985 /src/test/java
parent40f99f5e1863dc47433e75f7def3cbc30dcd6bf3 (diff)
downloadSkyblocker-bf0aa92552375465d9269c615d6ead54e74fbf0e.tar.gz
Skyblocker-bf0aa92552375465d9269c615d6ead54e74fbf0e.tar.bz2
Skyblocker-bf0aa92552375465d9269c615d6ead54e74fbf0e.zip
Verify json files (#1310)
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/de/hysky/skyblocker/VerifyJsonTest.java141
1 files changed, 141 insertions, 0 deletions
diff --git a/src/test/java/de/hysky/skyblocker/VerifyJsonTest.java b/src/test/java/de/hysky/skyblocker/VerifyJsonTest.java
new file mode 100644
index 00000000..81045238
--- /dev/null
+++ b/src/test/java/de/hysky/skyblocker/VerifyJsonTest.java
@@ -0,0 +1,141 @@
+package de.hysky.skyblocker;
+
+import com.google.gson.*;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.io.InputStreamReader;
+
+public class VerifyJsonTest {
+ private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
+
+ @Test
+ void verifyKuudraPearlWaypoints() {
+ @SuppressWarnings("DataFlowIssue")
+ JsonObject waypoints = GSON.fromJson(new InputStreamReader(this.getClass().getResourceAsStream("/assets/skyblocker/crimson/kuudra/pearl_waypoints.json")), JsonObject.class);
+
+ verifyBlockPosObjectArray(waypoints.get("waypoints"));
+ }
+
+ @Test
+ void verifyKuudraSafeSpotWaypoints() {
+ @SuppressWarnings("DataFlowIssue")
+ JsonObject waypoints = GSON.fromJson(new InputStreamReader(this.getClass().getResourceAsStream("/assets/skyblocker/crimson/kuudra/safe_spot_waypoints.json")), JsonObject.class);
+
+ verifyBlockPosObjectArray(waypoints.get("waypoints"));
+ }
+
+ @Test
+ void verifyDungeonRooms() {
+ @SuppressWarnings("DataFlowIssue")
+ JsonObject rooms = GSON.fromJson(new InputStreamReader(this.getClass().getResourceAsStream("/assets/skyblocker/dungeons/dungeonrooms.json")), JsonObject.class);
+
+ Assertions.assertFalse(rooms.isEmpty());
+ rooms.asMap().forEach((roomKey, roomElement) -> {
+ if (roomKey.equals("copyright") || roomKey.equals("license")) return;
+ Assertions.assertTrue(roomElement.isJsonObject());
+ JsonObject room = roomElement.getAsJsonObject();
+ Assertions.assertTrue(room.getAsJsonPrimitive("category").isString());
+ Assertions.assertTrue(room.getAsJsonPrimitive("secrets").isNumber());
+ Assertions.assertTrue(room.getAsJsonPrimitive("fairysoul").isBoolean());
+ });
+ }
+
+ @Test
+ void verifySecretLocations() {
+ @SuppressWarnings("DataFlowIssue")
+ JsonObject rooms = GSON.fromJson(new InputStreamReader(this.getClass().getResourceAsStream("/assets/skyblocker/dungeons/secretlocations.json")), JsonObject.class);
+
+ Assertions.assertFalse(rooms.isEmpty());
+ rooms.asMap().forEach((secretKey, roomElement) -> {
+ if (secretKey.equals("copyright") || secretKey.equals("license")) return;
+ Assertions.assertTrue(roomElement.isJsonArray());
+ JsonArray room = roomElement.getAsJsonArray();
+ Assertions.assertFalse(room.isEmpty());
+
+ room.forEach(secretElement -> {
+ verifyBlockPosObject(secretElement);
+
+ JsonObject secret = secretElement.getAsJsonObject();
+ Assertions.assertTrue(secret.getAsJsonPrimitive("secretName").isString());
+ Assertions.assertTrue(secret.getAsJsonPrimitive("category").isString());
+ });
+ });
+ }
+
+ @Test
+ void verifyGoldorWaypoints() {
+ @SuppressWarnings("DataFlowIssue")
+ JsonArray waypoints = GSON.fromJson(new InputStreamReader(this.getClass().getResourceAsStream("/assets/skyblocker/dungeons/goldorwaypoints.json")), JsonArray.class);
+
+ Assertions.assertFalse(waypoints.isEmpty());
+ waypoints.forEach(goldorWaypoint -> {
+ Assertions.assertTrue(goldorWaypoint.isJsonObject());
+ JsonObject waypoint = goldorWaypoint.getAsJsonObject();
+ Assertions.assertTrue(waypoint.getAsJsonPrimitive("kind").isString());
+ Assertions.assertTrue(waypoint.getAsJsonPrimitive("phase").isNumber());
+ Assertions.assertTrue(waypoint.getAsJsonPrimitive("name").isString());
+ verifyBlockPos(waypoint.get("pos"));
+ });
+ }
+
+ @Test
+ void verifyEnigmaSoulWaypoints() {
+ @SuppressWarnings("DataFlowIssue")
+ JsonObject waypoints = GSON.fromJson(new InputStreamReader(this.getClass().getResourceAsStream("/assets/skyblocker/rift/enigma_soul_waypoints.json")), JsonObject.class);
+
+ verifyBlockPosObjectArray(waypoints.get("waypoints"));
+ }
+
+ @Test
+ void verifyMirrorverseWaypoints() {
+ @SuppressWarnings("DataFlowIssue")
+ JsonObject waypoints = GSON.fromJson(new InputStreamReader(this.getClass().getResourceAsStream("/assets/skyblocker/rift/mirrorverse_waypoints.json")), JsonObject.class);
+
+ Assertions.assertTrue(waypoints.get("sections").isJsonArray());
+ JsonArray sections = waypoints.get("sections").getAsJsonArray();
+ Assertions.assertFalse(sections.isEmpty());
+
+ sections.forEach(sectionElement -> {
+ Assertions.assertTrue(sectionElement.isJsonObject());
+ JsonObject section = sectionElement.getAsJsonObject();
+ Assertions.assertTrue(section.getAsJsonPrimitive("name").isString());
+ verifyBlockPosObjectArray(section.get("waypoints"));
+ });
+ }
+
+ @Test
+ void verifyRelics() {
+ @SuppressWarnings("DataFlowIssue")
+ JsonObject relics = GSON.fromJson(new InputStreamReader(this.getClass().getResourceAsStream("/assets/skyblocker/spidersden/relics.json")), JsonObject.class);
+
+ verifyBlockPosObjectArray(relics.get("locations"));
+ }
+
+ static void verifyBlockPosObjectArray(JsonElement posArrayElement) {
+ Assertions.assertTrue(posArrayElement.isJsonArray());
+ JsonArray posArray = posArrayElement.getAsJsonArray();
+ Assertions.assertFalse(posArray.isEmpty());
+ posArray.forEach(VerifyJsonTest::verifyBlockPosObject);
+ }
+
+ static void verifyBlockPosObject(JsonElement posElement) {
+ Assertions.assertTrue(posElement.isJsonObject());
+ JsonObject pos = posElement.getAsJsonObject();
+ Assertions.assertTrue(pos.getAsJsonPrimitive("x").isNumber());
+ Assertions.assertTrue(pos.getAsJsonPrimitive("y").isNumber());
+ Assertions.assertTrue(pos.getAsJsonPrimitive("z").isNumber());
+ }
+
+ /**
+ * Verifies the compact json form of block pos created by {@link net.minecraft.util.math.BlockPos#CODEC}.
+ */
+ static void verifyBlockPos(JsonElement posElement) {
+ Assertions.assertTrue(posElement.isJsonArray());
+ JsonArray pos = posElement.getAsJsonArray();
+ Assertions.assertEquals(3, pos.size());
+ Assertions.assertTrue(pos.get(0).getAsJsonPrimitive().isNumber());
+ Assertions.assertTrue(pos.get(1).getAsJsonPrimitive().isNumber());
+ Assertions.assertTrue(pos.get(2).getAsJsonPrimitive().isNumber());
+ }
+}