diff --git a/common/build.gradle b/common/build.gradle index 5ecbcd83..1dcec64d 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -11,8 +11,9 @@ dependencies { // Architectury API. This is optional, and you can comment it out if you don't need it. //modImplementation "dev.architectury:architectury:$rootProject.architectury_api_version" - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.2' + testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.2' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.2' } test { diff --git a/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/AnimatableTextureTest.java b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/AnimatableTextureTest.java new file mode 100644 index 00000000..78cf0589 --- /dev/null +++ b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/AnimatableTextureTest.java @@ -0,0 +1,68 @@ +package io.github.amerebagatelle.mods.nuit.skybox; + +import com.mojang.serialization.JsonOps; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class AnimatableTextureTest { + @ParameterizedTest + @ValueSource(strings = { + """ + { + "texture": "test:resourcelocation" + } + """, + """ + { + "texture": "test:resourcelocation", + "gridColumns": 1 + } + """, + """ + { + "texture": "test:resourcelocation", + "gridRows": 1 + } + """, + """ + { + "texture": "test:resourcelocation", + "duration": 1 + } + """, + """ + { + "texture": "test:resourcelocation", + "interpolate": true + } + """, + """ + { + "texture": "test:resourcelocation", + "frameDuration": { + "1": 10, + "2": 20 + } + } + """ + }) + public void testCorrectParse(String json) { + var jsonOb = JsonTestHelper.readJson(json); + assertDoesNotThrow(() -> AnimatableTexture.CODEC.decode(JsonOps.INSTANCE, jsonOb).getOrThrow().getFirst()); + } + + @ParameterizedTest + @ValueSource(strings = { + """ + { + } + """, + }) + public void testIncorrectParse(String json) { + var jsonOb = JsonTestHelper.readJson(json); + assertThrows(IllegalStateException.class, () -> AnimatableTexture.CODEC.decode(JsonOps.INSTANCE, jsonOb).getOrThrow().getFirst()); + } +} diff --git a/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/BlendTest.java b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/BlendTest.java new file mode 100644 index 00000000..1d7a9eac --- /dev/null +++ b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/BlendTest.java @@ -0,0 +1,110 @@ +package io.github.amerebagatelle.mods.nuit.skybox; + +import com.mojang.serialization.JsonOps; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +public class BlendTest { + @ParameterizedTest + @ValueSource(strings = { + """ + { + } + """, + """ + { + "blend": "add" + } + """, + """ + { + "blend": "subtract" + } + """, + """ + { + "blend": "multiply" + } + """, + """ + { + "blend": "screen" + } + """, + """ + { + "blend": "replace" + } + """, + """ + { + "blend": "normal" + } + """, + """ + { + "blend": "burn" + } + """, + """ + { + "blend": "dodge" + } + """, + """ + { + "blend": "disable" + } + """, + """ + { + "blend": "decorations" + } + """, + """ + { + "blend": "custom", + "blender": { + } + } + """, + """ + { + "blend": "custom", + "blender": { + "separateFunction": true + } + } + """, + """ + { + "blend": "custom", + "blender": { + "sourceFactor": 1 + } + } + """, + """ + { + "blend": "custom", + "blender": { + "equation": 32775 + } + } + """, + """ + { + "blend": "custom", + "blender": { + "alphaEnabled": false + } + } + """ + }) + public void testCorrectParse(String json) { + var jsonOb = JsonTestHelper.readJson(json); + assertDoesNotThrow(() -> Blend.CODEC.decode(JsonOps.INSTANCE, jsonOb).getOrThrow().getFirst()); + } +} diff --git a/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/BlenderTest.java b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/BlenderTest.java new file mode 100644 index 00000000..b88d8505 --- /dev/null +++ b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/BlenderTest.java @@ -0,0 +1,41 @@ +package io.github.amerebagatelle.mods.nuit.skybox; + +import com.mojang.serialization.JsonOps; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +public class BlenderTest { + @ParameterizedTest + @ValueSource(strings = { + """ + { + } + """, + """ + { + "separateFunction": true + } + """, + """ + { + "sourceFactor": 1 + } + """, + """ + { + "equation": 32775 + } + """, + """ + { + "alphaEnabled": false + } + """ + }) + public void testCorrectParse(String json) { + var jsonOb = JsonTestHelper.readJson(json); + assertDoesNotThrow(() -> Blender.CODEC.decode(JsonOps.INSTANCE, jsonOb).getOrThrow().getFirst()); + } +} diff --git a/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/FadeTest.java b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/FadeTest.java new file mode 100644 index 00000000..93388b41 --- /dev/null +++ b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/FadeTest.java @@ -0,0 +1,38 @@ +package io.github.amerebagatelle.mods.nuit.skybox; + +import com.mojang.serialization.JsonOps; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +public class FadeTest { + @ParameterizedTest + @ValueSource(strings = { + """ + { + } + """, + """ + { + "alwaysOn": false + } + """, + """ + { + "duration": 24000 + } + """, + """ + { + "keyFrames": { + "1000": 10, + "3000": 20 + } + }""" + }) + public void testCorrectParse(String json) { + var jsonOb = JsonTestHelper.readJson(json); + assertDoesNotThrow(() -> Fade.CODEC.decode(JsonOps.INSTANCE, jsonOb).getOrThrow().getFirst()); + } +} diff --git a/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/JsonTestHelper.java b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/JsonTestHelper.java new file mode 100644 index 00000000..5f168891 --- /dev/null +++ b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/JsonTestHelper.java @@ -0,0 +1,15 @@ +package io.github.amerebagatelle.mods.nuit.skybox; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; + +public class JsonTestHelper { + public static final Gson GSON = new GsonBuilder() + .setLenient() + .create(); + + public static JsonObject readJson(String json) { + return GSON.fromJson(json, JsonObject.class); + } +} diff --git a/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/MetadataTest.java b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/MetadataTest.java new file mode 100644 index 00000000..f06c0392 --- /dev/null +++ b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/MetadataTest.java @@ -0,0 +1,70 @@ +package io.github.amerebagatelle.mods.nuit.skybox; + +import com.mojang.serialization.JsonOps; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class MetadataTest { + @ParameterizedTest + @ValueSource(strings = { + """ + { + "schemaVersion": 1, + "type": "monocolor" + } + """, + """ + { + "schemaVersion": 1, + "type": "square-textured" + } + """, + """ + { + "schemaVersion": 1, + "type": "multi-textured" + } + """, + """ + { + "schemaVersion": 1, + "type": "overworld" + } + """, + """ + { + "schemaVersion": 1, + "type": "end" + } + """ + }) + public void testCorrectParse(String json) { + var jsonOb = JsonTestHelper.readJson(json); + assertDoesNotThrow(() -> Metadata.CODEC.decode(JsonOps.INSTANCE, jsonOb).getOrThrow().getFirst()); + } + + @ParameterizedTest + @ValueSource(strings = { + """ + { + } + """, + """ + { + "schemaVersion": 1 + } + """, + """ + { + "type": "overworld" + } + """ + }) + public void testIncorrectParse(String json) { + var jsonOb = JsonTestHelper.readJson(json); + assertThrows(IllegalStateException.class, () -> Metadata.CODEC.decode(JsonOps.INSTANCE, jsonOb).getOrThrow().getFirst()); + } +} diff --git a/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/MinMaxTest.java b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/MinMaxTest.java new file mode 100644 index 00000000..37390bf2 --- /dev/null +++ b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/MinMaxTest.java @@ -0,0 +1,52 @@ +package io.github.amerebagatelle.mods.nuit.skybox; + +import com.mojang.serialization.JsonOps; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class MinMaxTest { + @ParameterizedTest + @ValueSource(strings = { + """ + { + "min": 1, + "max": 2 + } + """ + }) + public void testCorrectParse(String json) { + var jsonOb = JsonTestHelper.readJson(json); + assertDoesNotThrow(() -> MinMaxEntry.CODEC.decode(JsonOps.INSTANCE, jsonOb).getOrThrow().getFirst()); + } + + @ParameterizedTest + @ValueSource(strings = { + """ + { + } + """, + """ + { + "min": 1 + } + """, + """ + { + "max": 1 + } + """, + """ + { + "min": 2, + "max": 1 + } + """ + }) + public void testIncorrectParse(String json) { + var jsonOb = JsonTestHelper.readJson(json); + assertThrows(IllegalStateException.class, () -> MinMaxEntry.CODEC.decode(JsonOps.INSTANCE, jsonOb).getOrThrow().getFirst()); + } +} diff --git a/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/RGBATest.java b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/RGBATest.java new file mode 100644 index 00000000..672c58b4 --- /dev/null +++ b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/RGBATest.java @@ -0,0 +1,66 @@ +package io.github.amerebagatelle.mods.nuit.skybox; + +import com.mojang.serialization.JsonOps; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class RGBATest { + @ParameterizedTest + @ValueSource(strings = { + """ + { + "red": 0.0, + "blue": 1.0, + "green": 0.0 + } + """, + """ + { + "red": 0.0, + "blue": 1.0, + "green": 0.0, + "alpha": 0.5 + } + """ + }) + public void testCorrectParse(String json) { + var jsonOb = JsonTestHelper.readJson(json); + assertDoesNotThrow(() -> RGBA.CODEC.decode(JsonOps.INSTANCE, jsonOb).getOrThrow().getFirst()); + } + + @ParameterizedTest + @ValueSource(strings = { + """ + { + } + """, + """ + { + "red": 0.0 + } + """, + """ + { + "blue": 1.0 + } + """, + """ + { + "blue": 0.0, + "green": 0.0 + } + """, + """ + { + "alpha": 0.5 + } + """ + }) + public void testIncorrectParse(String json) { + var jsonOb = JsonTestHelper.readJson(json); + assertThrows(IllegalStateException.class, () -> RGBA.CODEC.decode(JsonOps.INSTANCE, jsonOb).getOrThrow().getFirst()); + } +} diff --git a/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/RotationTest.java b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/RotationTest.java new file mode 100644 index 00000000..2f35a70a --- /dev/null +++ b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/RotationTest.java @@ -0,0 +1,56 @@ +package io.github.amerebagatelle.mods.nuit.skybox; + +import com.mojang.serialization.JsonOps; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +public class RotationTest { + @ParameterizedTest + @ValueSource(strings = { + """ + { + } + """, + """ + { + "skyboxRotation": false + } + """, + """ + { + "static": [0, 90, 0] + } + """, + """ + { + "axis": [0, 90, 0] + } + """, + """ + { + "timeShift": [0, 90, 0] + } + """, + """ + { + "rotationSpeedX": 1 + } + """, + """ + { + "rotationSpeedY": 0.5 + } + """, + """ + { + "rotationSpeedZ": 0.25 + } + """ + }) + public void testCorrectParse(String json) { + var jsonOb = JsonTestHelper.readJson(json); + assertDoesNotThrow(() -> Rotation.CODEC.decode(JsonOps.INSTANCE, jsonOb).getOrThrow().getFirst()); + } +} diff --git a/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/TextureTest.java b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/TextureTest.java new file mode 100644 index 00000000..e5724ce5 --- /dev/null +++ b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/TextureTest.java @@ -0,0 +1,21 @@ +package io.github.amerebagatelle.mods.nuit.skybox; + +import com.google.gson.JsonPrimitive; +import com.mojang.serialization.JsonOps; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +public class TextureTest { + @ParameterizedTest + @ValueSource(strings = { + """ + "test:id" + """ + }) + public void testCorrectParse(String json) { + var jsonOb = JsonTestHelper.GSON.fromJson(json, JsonPrimitive.class); + assertDoesNotThrow(() -> Texture.CODEC.decode(JsonOps.INSTANCE, jsonOb).getOrThrow().getFirst()); + } +} diff --git a/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/WeatherTest.java b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/WeatherTest.java new file mode 100644 index 00000000..5253fec4 --- /dev/null +++ b/common/src/test/java/io/github/amerebagatelle/mods/nuit/skybox/WeatherTest.java @@ -0,0 +1,17 @@ +package io.github.amerebagatelle.mods.nuit.skybox; + +import com.google.gson.JsonPrimitive; +import com.mojang.serialization.JsonOps; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +public class WeatherTest { + @ParameterizedTest + @EnumSource(Weather.class) + public void testCorrectParse(Weather weatherType) { + var jsonOb = JsonTestHelper.GSON.fromJson(weatherType.toString(), JsonPrimitive.class); + assertDoesNotThrow(() -> Weather.CODEC.decode(JsonOps.INSTANCE, jsonOb).getOrThrow().getFirst()); + } +} diff --git a/docs/testing.md b/docs/testing.md index a209d440..49b792c1 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -4,13 +4,13 @@ All of these tests will be run before a release, but the ## Unit Tests -The unit tests are run on every PR. They are not extensive, as this is a largely visual mod. +The unit tests are run on every PR. They are not exhaustive of every possibility. +They also cannot test the most important parts of the mod, as this is a largely visual mod. ## Visual Tests -In the root directory, there is a folder called `testpacks/`. This folder contains several resource packs useful for -testing the mod. Each of the affected resource packs should be tested when submitting a PR. Below is documentation -for the purpose of each of the resource packs. +In the root directory, there is a folder called `testpacks/`. This folder contains several resource packs useful for +testing the mod. Below is documentation for the purpose of each of the resource packs. ### [MonoColorSkybox](../testpacks/MonoColorSkybox)