package nl.timfalken.chestpreview; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; import java.util.Set; import org.junit.jupiter.api.Test; import org.yaml.snakeyaml.Yaml; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; class PluginConfigTest { @Test @SuppressWarnings("unchecked") void pluginYmlDeclaresAdminCommand() throws IOException { Map yaml = loadYaml("plugin.yml"); assertEquals("ChestPreview", yaml.get("name")); assertEquals("nl.timfalken.chestpreview.ChestPreviewPlugin", yaml.get("main")); assertEquals("26.2", String.valueOf(yaml.get("api-version"))); assertEquals(gradleVersion(), String.valueOf(yaml.get("version"))); Map commands = (Map) yaml.get("commands"); assertEquals(Set.of("chestpreview"), commands.keySet()); assertEquals("chestpreview.admin", ((Map) commands.get("chestpreview")).get("permission")); assertEquals("op", ((Map) ((Map) yaml.get("permissions")).get("chestpreview.admin")).get("default")); } @Test @SuppressWarnings("unchecked") void configYmlEnablesCommonContainersAndDisplayDefaults() throws IOException { Map yaml = loadYaml("config.yml"); Map containers = (Map) yaml.get("containers"); assertTrue((Boolean) containers.get("chest")); assertTrue((Boolean) containers.get("barrel")); Map display = (Map) yaml.get("display"); assertEquals(0.40, ((Number) display.get("scale")).doubleValue(), 0.001); Map cycling = (Map) yaml.get("cycling"); assertTrue((Boolean) cycling.get("enabled")); assertEquals(20, ((Number) cycling.get("interval-ticks")).intValue()); } private static Map loadYaml(String name) throws IOException { try (InputStream in = PluginConfigTest.class.getClassLoader().getResourceAsStream(name)) { assertNotNull(in, name); return new Yaml().load(in); } } private static String gradleVersion() throws IOException { Path gradle = Path.of("build.gradle.kts"); if (!Files.isRegularFile(gradle)) gradle = Path.of("..", "build.gradle.kts"); for (String line : Files.readAllLines(gradle, StandardCharsets.UTF_8)) { line = line.trim(); if (line.startsWith("version = \"")) { return line.substring("version = \"".length(), line.length() - 1); } } throw new IOException("version not found"); } }