| 1 | package nl.timfalken.copperkeys; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | import java.nio.file.Files; |
| 5 | import java.nio.file.Path; |
| 6 | import java.util.Map; |
| 7 | import java.util.stream.Stream; |
| 8 | |
| 9 | import org.junit.jupiter.api.Test; |
| 10 | import org.yaml.snakeyaml.Yaml; |
| 11 | |
| 12 | import static org.junit.jupiter.api.Assertions.assertFalse; |
| 13 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 14 | import static org.junit.jupiter.api.Assertions.assertTrue; |
| 15 | |
| 16 | class ResourcePackTest { |
| 17 | |
| 18 | @Test |
| 19 | @SuppressWarnings("unchecked") |
| 20 | void packMcmetaIsValidAndHasPackFormat() throws IOException { |
| 21 | Map<String, Object> root = new Yaml().load(Files.readString(Path.of("resource-pack/pack.mcmeta"))); |
| 22 | Map<String, Object> pack = (Map<String, Object>) root.get("pack"); |
| 23 | assertNotNull(pack.get("pack_format")); |
| 24 | assertFalse(String.valueOf(pack.get("description")).isBlank()); |
| 25 | assertTrue(((Number) pack.get("pack_format")).intValue() > 0); |
| 26 | } |
| 27 | |
| 28 | @Test |
| 29 | void advancementFilesAreValidMappings() throws IOException { |
| 30 | Path dir = Path.of("src/main/resources/advancements"); |
| 31 | try (Stream<Path> files = Files.list(dir)) { |
| 32 | var json = files.filter(p -> p.getFileName().toString().endsWith(".json")).toList(); |
| 33 | assertFalse(json.isEmpty()); |
| 34 | Yaml yaml = new Yaml(); |
| 35 | for (Path file : json) { |
| 36 | Object loaded = yaml.load(Files.readString(file)); |
| 37 | assertTrue(loaded instanceof Map, file.toString()); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | } |