Search in sources :

Example 1 with SerializationContext

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);
}
Also used : SerializationContext(org.terasology.persistence.typeHandling.SerializationContext) PersistedData(org.terasology.persistence.typeHandling.PersistedData) DeserializationContext(org.terasology.persistence.typeHandling.DeserializationContext) Test(org.junit.Test)

Example 2 with SerializationContext

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);
}
Also used : SerializationContext(org.terasology.persistence.typeHandling.SerializationContext) PersistedData(org.terasology.persistence.typeHandling.PersistedData) DeserializationContext(org.terasology.persistence.typeHandling.DeserializationContext) Test(org.junit.Test)

Example 3 with SerializationContext

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);
}
Also used : SerializationContext(org.terasology.persistence.typeHandling.SerializationContext) Color(org.terasology.rendering.nui.Color) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 SerializationContext (org.terasology.persistence.typeHandling.SerializationContext)3 DeserializationContext (org.terasology.persistence.typeHandling.DeserializationContext)2 PersistedData (org.terasology.persistence.typeHandling.PersistedData)2 Color (org.terasology.rendering.nui.Color)1