1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

[CI skip] Some unit test changes

This commit is contained in:
TheBusyBiscuit 2022-01-04 01:30:21 +01:00
parent eac32ac94c
commit 5c1dda32a4
4 changed files with 26 additions and 8 deletions

View File

@ -155,6 +155,21 @@ public enum MinecraftVersion {
return false;
}
/**
* Unit-Test only code.
* Running #isAtLeast(...) should always be meaningful.
* If the provided version equals the lowest supported version, then
* this will essentially always return true and result in a tautology.
* This is most definitely an oversight from us and should be fixed, therefore
* we will trigger an exception.
*
* In order to not disrupt server operations, this exception is only thrown during
* unit tests since the oversight itself will be harmless.
*/
if (this == UNIT_TEST && version.ordinal() == 0) {
throw new IllegalArgumentException("Version " + version + " is the lowest supported version already!");
}
return this.ordinal() >= version.ordinal();
}

View File

@ -58,4 +58,10 @@ class TestMinecraftVersion {
Assertions.assertThrows(IllegalArgumentException.class, () -> MinecraftVersion.MINECRAFT_1_14.isBefore(null));
}
@Test
@DisplayName("Test warning system for lowest supported version checks")
void testLowestSupportedVersion() {
Assertions.assertThrows(IllegalArgumentException.class, () -> MinecraftVersion.UNIT_TEST.isAtLeast(MinecraftVersion.MINECRAFT_1_14));
}
}

View File

@ -6,25 +6,24 @@ import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
class TestWikiResource {
@Test
@DisplayName("Test wiki.json file format")
void testWikiJson() throws IOException {
JsonParser parser = new JsonParser();
Pattern pattern = Pattern.compile("[A-Z_0-9]+");
// Here we test for any Syntax errors in our wiki.json file
try (BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/wiki.json"), StandardCharsets.UTF_8))) {
JsonElement json = parser.parse(reader);
JsonElement json = JsonUtils.parseString(reader.lines().collect(Collectors.joining("")));
Assertions.assertTrue(json.isJsonObject());
for (Map.Entry<String, JsonElement> entry : json.getAsJsonObject().entrySet()) {

View File

@ -24,10 +24,10 @@ import org.junit.jupiter.params.provider.MethodSource;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.utils.JsonUtils;
import be.seeseemelk.mockbukkit.MockBukkit;
@ -66,8 +66,7 @@ class TestBiomeMapCompatibility {
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(Slimefun.class.getResourceAsStream(path), StandardCharsets.UTF_8))) {
JsonParser parser = new JsonParser();
JsonArray biomes = parser.parse(reader.lines().collect(Collectors.joining(""))).getAsJsonArray();
JsonArray biomes = JsonUtils.parseString(reader.lines().collect(Collectors.joining(""))).getAsJsonArray();
compatibilityMap.put(version, biomes);
} catch (IOException x) {
@ -161,8 +160,7 @@ class TestBiomeMapCompatibility {
String path = "/biome-maps/" + name + ".json";
try (BufferedReader reader = new BufferedReader(new InputStreamReader(Slimefun.class.getResourceAsStream(path), StandardCharsets.UTF_8))) {
JsonParser parser = new JsonParser();
JsonArray root = parser.parse(reader.lines().collect(Collectors.joining(""))).getAsJsonArray();
JsonArray root = JsonUtils.parseString(reader.lines().collect(Collectors.joining(""))).getAsJsonArray();
for (JsonElement element : root) {
JsonArray biomes = element.getAsJsonObject().getAsJsonArray("biomes");