use of org.terasology.persistence.typeHandling.SerializationContext in project Terasology by MovingBlocks.
the class EnumTypeHandlerSerializerTest method testNonNullValue.
@Test
public void testNonNullValue() throws Exception {
PersistedData data = mock(PersistedData.class);
when(data.getAsString()).thenReturn(TestEnum.NON_NULL.toString());
when(data.isString()).thenReturn(true);
SerializationContext serializationContext = mock(SerializationContext.class);
when(serializationContext.create(TestEnum.NON_NULL.toString())).thenReturn(data);
EnumTypeHandler<TestEnum> handler = new EnumTypeHandler<>(TestEnum.class);
PersistedData serializedNonNull = handler.serialize(TestEnum.NON_NULL, serializationContext);
assertEquals(data, serializedNonNull);
DeserializationContext deserializationContext = mock(DeserializationContext.class);
TestEnum deserializedValue = handler.deserialize(data, deserializationContext);
assertEquals(TestEnum.NON_NULL, deserializedValue);
}
use of org.terasology.persistence.typeHandling.SerializationContext in project Terasology by MovingBlocks.
the class EnumTypeHandlerSerializerTest method testNullValue.
@Test
public void testNullValue() throws Exception {
PersistedData nullData = mock(PersistedData.class);
when(nullData.isNull()).thenReturn(true);
SerializationContext serializationContext = mock(SerializationContext.class);
when(serializationContext.createNull()).thenReturn(nullData);
EnumTypeHandler<TestEnum> handler = new EnumTypeHandler<>(TestEnum.class);
PersistedData serializedNull = handler.serialize(null, serializationContext);
assertEquals(nullData, serializedNull);
DeserializationContext deserializationContext = mock(DeserializationContext.class);
TestEnum deserializedValue = handler.deserialize(nullData, deserializationContext);
assertEquals(null, deserializedValue);
}
use of org.terasology.persistence.typeHandling.SerializationContext in project Terasology by MovingBlocks.
the class ColorTypeHandlerTest method testSerialize.
@Test
public void testSerialize() {
SerializationContext serializationContext = Mockito.mock(SerializationContext.class);
handler.serialize(new Color(0x010380FF), serializationContext);
Mockito.verify(serializationContext).create(1, 3, 128, 255);
}
Aggregations