BlueGit

timfa copper-key

Files

copper-key / src / test / java / nl / timfalken / copperkeys / ResourcePackTest.java

ResourcePackTest.java

ResourcePackTest.java 1.5 KiB Download Raw
1package nl.timfalken.copperkeys;
2
3import java.io.IOException;
4import java.nio.file.Files;
5import java.nio.file.Path;
6import java.util.Map;
7import java.util.stream.Stream;
8
9import org.junit.jupiter.api.Test;
10import org.yaml.snakeyaml.Yaml;
11
12import static org.junit.jupiter.api.Assertions.assertFalse;
13import static org.junit.jupiter.api.Assertions.assertNotNull;
14import static org.junit.jupiter.api.Assertions.assertTrue;
15
16class 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}