1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

[CI skip] Added two unit tests for translation file integrity

This commit is contained in:
TheBusyBiscuit 2020-06-25 02:33:26 +02:00
parent a36c42959e
commit bc4b625172
2 changed files with 49 additions and 1 deletions

View File

@ -1,12 +1,19 @@
package io.github.thebusybiscuit.slimefun4.testing.tests.items;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.ServerMock;
@ -14,6 +21,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.setup.PostSetup;
import io.github.thebusybiscuit.slimefun4.implementation.setup.SlimefunItemSetup;
import io.github.thebusybiscuit.slimefun4.testing.TestUtilities;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Objects.Category;
@TestMethodOrder(value = OrderAnnotation.class)
public class TestItemSetup {
@ -49,4 +57,17 @@ public class TestItemSetup {
public void testWikiSetup() {
Assertions.assertDoesNotThrow(() -> PostSetup.setupWiki());
}
@Test
@Order(value = 3)
public void testCategoryTranslations() throws IOException {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/languages/categories_en.yml"), StandardCharsets.UTF_8))) {
FileConfiguration config = YamlConfiguration.loadConfiguration(reader);
for (Category category : SlimefunPlugin.getRegistry().getCategories()) {
String path = category.getKey().getNamespace() + '.' + category.getKey().getKey();
Assertions.assertTrue(config.contains(path));
}
}
}
}

View File

@ -1,14 +1,26 @@
package io.github.thebusybiscuit.slimefun4.testing.tests.researches;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import be.seeseemelk.mockbukkit.MockBukkit;
import io.github.thebusybiscuit.slimefun4.core.researching.Research;
import io.github.thebusybiscuit.slimefun4.implementation.setup.ResearchSetup;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
@TestMethodOrder(value = OrderAnnotation.class)
public class TestResearchSetup {
@BeforeAll
@ -23,14 +35,29 @@ public class TestResearchSetup {
}
@Test
@Order(value = 1)
public void testForExceptions() {
// Not really ideal but still important to test.
// Research amount is variable, so we can't test for that.
// We are really only concerned about any runtime exceptions here.
SlimefunPlugin.getRegistry().setResearchingEnabled(true);
Assertions.assertDoesNotThrow(() -> ResearchSetup.setupResearches());
// Running it a second time should NOT be allowed.
Assertions.assertThrows(UnsupportedOperationException.class, () -> ResearchSetup.setupResearches());
}
@Test
@Order(value = 2)
public void testResearchTranslations() throws IOException {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/languages/researches_en.yml"), StandardCharsets.UTF_8))) {
FileConfiguration config = YamlConfiguration.loadConfiguration(reader);
for (Research research : SlimefunPlugin.getRegistry().getResearches()) {
String path = research.getKey().getNamespace() + '.' + research.getKey().getKey();
Assertions.assertTrue(config.contains(path));
}
}
}
}