Search in sources :

Example 1 with ByteCodeReflectFactory

use of org.terasology.engine.reflection.reflect.ByteCodeReflectFactory in project Terasology by MovingBlocks.

the class ByteCodeReflectFactoryTest method testCreateFieldAccessorDirectToField.

@Test
public void testCreateFieldAccessorDirectToField() throws Exception {
    ReflectFactory reflectFactory = new ByteCodeReflectFactory();
    FieldAccessor<StringComponent, String> fieldAccessor = reflectFactory.createFieldAccessor(StringComponent.class, StringComponent.class.getDeclaredField("value"), String.class);
    StringComponent comp = new StringComponent();
    fieldAccessor.setValue(comp, "String");
    assertEquals("String", fieldAccessor.getValue(comp));
}
Also used : ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) StringComponent(org.terasology.unittest.stubs.StringComponent) Test(org.junit.jupiter.api.Test)

Example 2 with ByteCodeReflectFactory

use of org.terasology.engine.reflection.reflect.ByteCodeReflectFactory in project Terasology by MovingBlocks.

the class ByteCodeReflectFactoryTest method testCreateConstructorObjectWithPublicConstructor.

@Test
public void testCreateConstructorObjectWithPublicConstructor() throws NoSuchMethodException {
    ReflectFactory reflectFactory = new ByteCodeReflectFactory();
    ObjectConstructor<LocationComponent> constructor = reflectFactory.createConstructor(LocationComponent.class);
    LocationComponent locationComponent = constructor.construct();
    assertNotNull(locationComponent);
}
Also used : ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) LocationComponent(org.terasology.engine.logic.location.LocationComponent) Test(org.junit.jupiter.api.Test)

Example 3 with ByteCodeReflectFactory

use of org.terasology.engine.reflection.reflect.ByteCodeReflectFactory in project Terasology by MovingBlocks.

the class ByteCodeReflectFactoryTest method testCreateConstructorObjectWithProtectedConstructor.

@Test
public void testCreateConstructorObjectWithProtectedConstructor() throws Exception {
    ReflectFactory reflectFactory = new ByteCodeReflectFactory();
    ObjectConstructor<AttackRequest> constructor = reflectFactory.createConstructor(AttackRequest.class);
    AttackRequest result = constructor.construct();
    assertNotNull(result);
}
Also used : ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) AttackRequest(org.terasology.engine.logic.characters.events.AttackRequest) Test(org.junit.jupiter.api.Test)

Example 4 with ByteCodeReflectFactory

use of org.terasology.engine.reflection.reflect.ByteCodeReflectFactory 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 5 with ByteCodeReflectFactory

use of org.terasology.engine.reflection.reflect.ByteCodeReflectFactory in project Terasology by MovingBlocks.

the class ByteCodeReflectFactoryTest method testAccessIntegerField.

@Test
public void testAccessIntegerField() throws Exception {
    ReflectFactory reflectFactory = new ByteCodeReflectFactory();
    FieldAccessor fieldAccessor = reflectFactory.createFieldAccessor(IntegerComponent.class, IntegerComponent.class.getDeclaredField("value"));
    IntegerComponent comp = new IntegerComponent();
    fieldAccessor.setValue(comp, 1);
    assertEquals(1, fieldAccessor.getValue(comp));
}
Also used : ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) IntegerComponent(org.terasology.unittest.stubs.IntegerComponent) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)5 ByteCodeReflectFactory (org.terasology.engine.reflection.reflect.ByteCodeReflectFactory)5 Vector3f (org.joml.Vector3f)1 AttackRequest (org.terasology.engine.logic.characters.events.AttackRequest)1 LocationComponent (org.terasology.engine.logic.location.LocationComponent)1 GetterSetterComponent (org.terasology.unittest.stubs.GetterSetterComponent)1 IntegerComponent (org.terasology.unittest.stubs.IntegerComponent)1 StringComponent (org.terasology.unittest.stubs.StringComponent)1