aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/de/hysky/skyblocker/skyblock/item/ArmorTrimIdSerializationTest.java
blob: 8d2bfd6025c7dfdb7ab9861da1fce9e52e44d5fe (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
package de.hysky.skyblocker.skyblock.item;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.mojang.serialization.JsonOps;

import de.hysky.skyblocker.skyblock.item.CustomArmorTrims.ArmorTrimId;
import net.minecraft.util.Identifier;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class ArmorTrimIdSerializationTest {
    private final Gson gson = new Gson();

    @Test
    void serialize() {
        ArmorTrimId armorTrimId = new ArmorTrimId(Identifier.ofVanilla("material_id"), Identifier.ofVanilla("pattern_id"));
        JsonElement json = ArmorTrimId.CODEC.encodeStart(JsonOps.INSTANCE, armorTrimId).getOrThrow();
        String expectedJson = "{\"material\":\"minecraft:material_id\",\"pattern\":\"minecraft:pattern_id\"}";

        Assertions.assertEquals(expectedJson, json.toString());
    }

    @Test
    void deserialize() {
        String json = "{\"material\":\"minecraft:material_id\",\"pattern\":\"minecraft:pattern_id\"}";
        ArmorTrimId armorTrimId = ArmorTrimId.CODEC.parse(JsonOps.INSTANCE, gson.fromJson(json, JsonElement.class)).getOrThrow();
        ArmorTrimId expectedArmorTrimId = new ArmorTrimId(Identifier.ofVanilla("material_id"), Identifier.ofVanilla("pattern_id"));

        Assertions.assertEquals(expectedArmorTrimId, armorTrimId);
    }
}