aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/de/hysky/skyblocker/config/datafixer/ConfigDataFixerTest.java
blob: 7e73b9e95440353db2fdf138a5d8262429b135c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package de.hysky.skyblocker.config.datafixer;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import net.minecraft.Bootstrap;
import net.minecraft.SharedConstants;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.InputStreamReader;

public class ConfigDataFixerTest {
    private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();

    @BeforeAll
    public static void setupEnvironment() {
        SharedConstants.createGameVersion();
        Bootstrap.initialize();
    }

    @Test
    void testDataFixer1() {
        @SuppressWarnings("DataFlowIssue")
        JsonObject oldConfig = GSON.fromJson(new InputStreamReader(ConfigDataFixerTest.class.getResourceAsStream("/assets/skyblocker/config/skyblocker-v1.json")), JsonObject.class);
        @SuppressWarnings("DataFlowIssue")
        JsonObject expectedNewConfig = GSON.fromJson(new InputStreamReader(ConfigDataFixerTest.class.getResourceAsStream("/assets/skyblocker/config/skyblocker-v2.json")), JsonObject.class);

        Assertions.assertEquals(expectedNewConfig, ConfigDataFixer.apply(oldConfig, 2));
    }

    @Test
    void testDataFixer2QuickNav() {
        @SuppressWarnings("DataFlowIssue")
        JsonObject oldConfig = GSON.fromJson(new InputStreamReader(ConfigDataFixerTest.class.getResourceAsStream("/assets/skyblocker/config/skyblocker-v2.json")), JsonObject.class);
        @SuppressWarnings("DataFlowIssue")
        JsonObject expectedNewConfig = GSON.fromJson(new InputStreamReader(ConfigDataFixerTest.class.getResourceAsStream("/assets/skyblocker/config/skyblocker-v3.json")), JsonObject.class);

        Assertions.assertEquals(expectedNewConfig, ConfigDataFixer.apply(oldConfig, 3));
    }

    @Test
    void testDataFixer3SlotText() {
        @SuppressWarnings("DataFlowIssue")
        JsonObject oldConfig = GSON.fromJson(new InputStreamReader(ConfigDataFixerTest.class.getResourceAsStream("/assets/skyblocker/config/skyblocker-v3.1.json")), JsonObject.class);
        @SuppressWarnings("DataFlowIssue")
        JsonObject expectedNewConfig = GSON.fromJson(new InputStreamReader(ConfigDataFixerTest.class.getResourceAsStream("/assets/skyblocker/config/skyblocker-v4.json")), JsonObject.class);

        Assertions.assertEquals(expectedNewConfig, ConfigDataFixer.apply(oldConfig, 4));
    }
}