use of org.terasology.persistence.typeHandling.PersistedDataSerializer in project Terasology by MovingBlocks.
the class ColorTypeHandlerTest method testSerialize.
@Test
public void testSerialize() {
PersistedDataSerializer persistedDataSerializer = Mockito.mock(PersistedDataSerializer.class);
handler.serialize(new Color(0x010380FF), persistedDataSerializer);
Mockito.verify(persistedDataSerializer).serialize(1, 3, 128, 255);
}
use of org.terasology.persistence.typeHandling.PersistedDataSerializer in project Terasology by MovingBlocks.
the class EnumTypeHandlerSerializerTest method testNullValue.
@Test
void testNullValue() throws Exception {
PersistedData nullData = mock(PersistedData.class);
when(nullData.isNull()).thenReturn(true);
PersistedDataSerializer persistedDataSerializer = mock(PersistedDataSerializer.class);
when(persistedDataSerializer.serializeNull()).thenReturn(nullData);
EnumTypeHandler<TestEnum> handler = new EnumTypeHandler<>(TestEnum.class);
PersistedData serializedNull = handler.serialize(null, persistedDataSerializer);
assertEquals(nullData, serializedNull);
assertFalse(handler.deserialize(nullData).isPresent());
}
use of org.terasology.persistence.typeHandling.PersistedDataSerializer in project Terasology by MovingBlocks.
the class EnumTypeHandlerSerializerTest method testNonNullValue.
@Test
void testNonNullValue() throws Exception {
PersistedData data = mock(PersistedData.class);
when(data.getAsString()).thenReturn(TestEnum.NON_NULL.toString());
when(data.isString()).thenReturn(true);
PersistedDataSerializer persistedDataSerializer = mock(PersistedDataSerializer.class);
when(persistedDataSerializer.serialize(TestEnum.NON_NULL.toString())).thenReturn(data);
EnumTypeHandler<TestEnum> handler = new EnumTypeHandler<>(TestEnum.class);
PersistedData serializedNonNull = handler.serialize(TestEnum.NON_NULL, persistedDataSerializer);
assertEquals(data, serializedNonNull);
TestEnum deserializedValue = handler.deserialize(data).get();
assertEquals(TestEnum.NON_NULL, deserializedValue);
}
use of org.terasology.persistence.typeHandling.PersistedDataSerializer in project Terasology by MovingBlocks.
the class ArrayTypeHandlerTest method testSerialize.
@Test
void testSerialize() {
IntTypeHandler elementTypeHandler = mock(IntTypeHandler.class);
ArrayTypeHandler<Integer> typeHandler = new ArrayTypeHandler<>(elementTypeHandler, TypeInfo.of(Integer.class));
Integer[] array = new Integer[ARRAY_SIZE];
final int[] c = { 0 };
Collections.nCopies(array.length, -1).forEach(i -> array[c[0]++] = i);
PersistedDataSerializer context = mock(PersistedDataSerializer.class);
typeHandler.serialize(array, context);
verify(elementTypeHandler, times(array.length)).serialize(any(), any());
verify(context).serialize(argThat((ArgumentMatcher<Iterable<PersistedData>>) argument -> argument instanceof Collection && ((Collection) argument).size() == array.length));
}
use of org.terasology.persistence.typeHandling.PersistedDataSerializer in project Terasology by MovingBlocks.
the class RuntimeDelegatingTypeHandlerTest method testSerializeBase.
@Test
void testSerializeBase() {
PersistedDataSerializer serializer = mock(PersistedDataSerializer.class);
Base base = new Base();
runtimeDelegatingTypeHandler.serialize(base, serializer);
verify(baseTypeHandler).serialize(any(), any());
verify(subTypeHandler, never()).serialize(any(), any());
verify(serializer, never()).serialize(argThat((ArgumentMatcher<Map<String, PersistedData>>) argument -> argument.containsKey(RuntimeDelegatingTypeHandler.TYPE_FIELD)));
}
Aggregations