Search in sources :

Example 1 with GetterSetterComponent

use of org.terasology.unittest.stubs.GetterSetterComponent in project Terasology by MovingBlocks.

the class ByteCodeReflectFactoryTest method testCreateFieldAccessorWithGetterSetter.

@Test
public void testCreateFieldAccessorWithGetterSetter() throws Exception {
    ReflectFactory reflectFactory = new ByteCodeReflectFactory();
    FieldAccessor<GetterSetterComponent, Vector3f> fieldAccessor = reflectFactory.createFieldAccessor(GetterSetterComponent.class, GetterSetterComponent.class.getDeclaredField("value"), Vector3f.class);
    GetterSetterComponent comp = new GetterSetterComponent();
    Vector3f newVal = new Vector3f(1, 2, 3);
    fieldAccessor.setValue(comp, newVal);
    assertTrue(comp.setterUsed);
    assertEquals(newVal, fieldAccessor.getValue(comp));
    assertTrue(comp.getterUsed);
}
Also used : ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) Vector3f(org.joml.Vector3f) GetterSetterComponent(org.terasology.unittest.stubs.GetterSetterComponent) Test(org.junit.jupiter.api.Test)

Example 2 with GetterSetterComponent

use of org.terasology.unittest.stubs.GetterSetterComponent in project Terasology by MovingBlocks.

the class ComponentSerializerTest method testGetterSetterUtilization.

@Test
public void testGetterSetterUtilization() throws Exception {
    GetterSetterComponent comp = new GetterSetterComponent();
    GetterSetterComponent newComp = (GetterSetterComponent) componentSerializer.deserialize(componentSerializer.serialize(comp));
    assertTrue(comp.getterUsed);
    assertTrue(newComp.setterUsed);
}
Also used : GetterSetterComponent(org.terasology.unittest.stubs.GetterSetterComponent) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 GetterSetterComponent (org.terasology.unittest.stubs.GetterSetterComponent)2 Vector3f (org.joml.Vector3f)1 ByteCodeReflectFactory (org.terasology.engine.reflection.reflect.ByteCodeReflectFactory)1