gson: add test for String2ObjectMap serialization
ci/woodpecker/push/woodpecker Pipeline failed
Details
ci/woodpecker/push/woodpecker Pipeline failed
Details
This commit is contained in:
parent
b02eb3142f
commit
213aaec874
|
@ -1,13 +1,16 @@
|
|||
package io.gitlab.jfronny.commons.test;
|
||||
|
||||
import io.gitlab.jfronny.commons.ComparableVersion;
|
||||
import io.gitlab.jfronny.commons.data.String2ObjectMap;
|
||||
import io.gitlab.jfronny.commons.serialize.Serializer;
|
||||
import io.gitlab.jfronny.commons.serialize.gson.api.v1.Ignore;
|
||||
import io.gitlab.jfronny.commons.serialize.gson.api.v1.GsonHolders;
|
||||
import io.gitlab.jfronny.gson.reflect.TypeToken;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
@ -30,6 +33,39 @@ public class GsonTest {
|
|||
assertDoesNotThrow(() -> assertEquals(new ComparableVersion("1.0.0"), Serializer.getInstance().deserialize("\"1.0.0\"", ComparableVersion.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void gsonString2ObjectMap() throws IOException {
|
||||
String2ObjectMap<SimpleRecord> map = new String2ObjectMap<>();
|
||||
map.put("Some String", new SimpleRecord("Aaee", 12));
|
||||
map.put("Some", new SimpleRecord("Aeio", 4));
|
||||
map.put("Some Test", new SimpleRecord("U", 64));
|
||||
final String serialized = "{\"Some\":{\"someValue\":\"Aeio\",\"yes\":4},\"Some String\":{\"someValue\":\"Aaee\",\"yes\":12},\"Some Test\":{\"someValue\":\"U\",\"yes\":64}}";
|
||||
assertEquals(serialized, Serializer.getInstance().serialize(map));
|
||||
assertEquals(map, Serializer.getInstance().deserialize(serialized, new TypeToken<String2ObjectMap<SimpleRecord>>() {}.getType()));
|
||||
}
|
||||
|
||||
public static final class SimpleRecord {
|
||||
public final String someValue;
|
||||
public final int yes;
|
||||
|
||||
public SimpleRecord(String someValue, int yes) {
|
||||
this.someValue = someValue;
|
||||
this.yes = yes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof SimpleRecord that)) return false;
|
||||
return yes == that.yes && Objects.equals(someValue, that.someValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(someValue, yes);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ExampleType {
|
||||
String id = "Yes";
|
||||
@Ignore
|
||||
|
|
Loading…
Reference in New Issue