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));
}
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);
}
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);
}
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);
}
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));
}
Aggregations