use of org.terasology.reflection.TypeInfo in project Terasology by MovingBlocks.
the class VectorTypeSerializerTest method testSerializationConstant.
@Test
void testSerializationConstant() {
TestObject2 a = new TestObject2();
a.v1 = new Vector3f(1.0f, 2.0f, 3.0f);
a.v2 = new Vector4f(1.0f, 2.0f, 3.0f, 5.0f);
a.v3 = new Vector2f(1.0f, 2.0f);
byte[] data = gsonSerializer.serialize(a, new TypeInfo<TestObject2>() {
}).get();
TestObject2 o = gsonSerializer.deserialize(new TypeInfo<TestObject2>() {
}, data).get();
assertEquals(new Vector3f(1.0f, 2.0f, 3.0f), o.v1, .00001f);
assertEquals(new Vector4f(1.0f, 2.0f, 3.0f, 5.0f), o.v2, .00001f);
assertEquals(new Vector2f(1.0f, 2.0f), o.v3, .00001f);
}
use of org.terasology.reflection.TypeInfo in project Terasology by MovingBlocks.
the class BlockAreaTypeHandlerTest method testGsonSerialization.
@Test
public void testGsonSerialization() throws IOException {
TestObject a = new TestObject();
a.b1 = new BlockArea(-1, -1, 0, 0);
a.b2 = new BlockArea(0, 0, 1, 1);
byte[] data = gsonSerializer.serialize(a, new TypeInfo<TestObject>() {
}).get();
TestObject o = gsonSerializer.deserialize(new TypeInfo<TestObject>() {
}, data).get();
assertEquals(new BlockArea(-1, -1, 0, 0), o.b1);
assertEquals(new BlockArea(0, 0, 1, 1), o.b2);
}
use of org.terasology.reflection.TypeInfo in project Terasology by MovingBlocks.
the class ReflectionUtilTest method testGetParameterForUnboundGenericInterface.
@Test
public void testGetParameterForUnboundGenericInterface() {
Type parameter = ReflectionUtil.getTypeParameterForSuper(new TypeInfo<UnboundInterfaceImplementor<?>>() {
}.getType(), CopyStrategy.class, 0);
assertTrue(parameter instanceof WildcardType);
}
use of org.terasology.reflection.TypeInfo in project Terasology by MovingBlocks.
the class ReflectionUtilTest method testResolveGenericArray.
@Test
public void testResolveGenericArray() {
class SomeClass<T> {
private T[] t;
}
TypeInfo<SomeClass<Float>> typeInfo = new TypeInfo<SomeClass<Float>>() {
};
GenericArrayType resolvedFieldType = (GenericArrayType) ReflectionUtil.resolveType(typeInfo.getType(), typeInfo.getRawType().getDeclaredFields()[0].getGenericType());
assertEquals(Float[].class.getComponentType(), resolvedFieldType.getGenericComponentType());
}
use of org.terasology.reflection.TypeInfo in project Terasology by MovingBlocks.
the class ReflectionUtilTest method testResolveParameterizedType.
@Test
public void testResolveParameterizedType() {
class SomeClass<T> {
private CopyStrategy<T> t;
}
TypeInfo<SomeClass<Float>> typeInfo = new TypeInfo<SomeClass<Float>>() {
};
Type resolvedFieldType = ReflectionUtil.resolveType(typeInfo.getType(), typeInfo.getRawType().getDeclaredFields()[0].getGenericType());
assertEquals(new TypeInfo<CopyStrategy<Float>>() {
}.getType(), resolvedFieldType);
}
Aggregations