Search in sources :

Example 1 with FieldAccessor

use of io.cdap.cdap.internal.io.FieldAccessor in project cdap by caskdata.

the class FieldAccessorTest method testGetter.

@Test
public void testGetter() {
    TypeToken<Child> type = TypeToken.of(Child.class);
    FieldAccessorFactory factory = new ASMFieldAccessorFactory();
    FieldAccessor accessor = factory.getFieldAccessor(type, "integer");
    Assert.assertSame(accessor, factory.getFieldAccessor(type, "integer"));
    Child c = new Child();
    c.integer = 10;
    c.str = "child value";
    ((Parent<String>) c).value = "string value";
    ((Parent<String>) c).b = true;
    Assert.assertEquals(c.integer, accessor.getInt(c));
    Assert.assertSame(c.str, factory.getFieldAccessor(type, "str").get(c));
    Assert.assertSame(((Parent) c).value, factory.getFieldAccessor(type, "value").get(c));
    Assert.assertEquals(((Parent) c).b, factory.getFieldAccessor(type, "b").get(c));
}
Also used : ASMFieldAccessorFactory(io.cdap.cdap.internal.io.ASMFieldAccessorFactory) ASMFieldAccessorFactory(io.cdap.cdap.internal.io.ASMFieldAccessorFactory) FieldAccessorFactory(io.cdap.cdap.internal.io.FieldAccessorFactory) FieldAccessor(io.cdap.cdap.internal.io.FieldAccessor) Test(org.junit.Test)

Example 2 with FieldAccessor

use of io.cdap.cdap.internal.io.FieldAccessor in project cdap by cdapio.

the class FieldAccessorTest method testGetter.

@Test
public void testGetter() {
    TypeToken<Child> type = TypeToken.of(Child.class);
    FieldAccessorFactory factory = new ASMFieldAccessorFactory();
    FieldAccessor accessor = factory.getFieldAccessor(type, "integer");
    Assert.assertSame(accessor, factory.getFieldAccessor(type, "integer"));
    Child c = new Child();
    c.integer = 10;
    c.str = "child value";
    ((Parent<String>) c).value = "string value";
    ((Parent<String>) c).b = true;
    Assert.assertEquals(c.integer, accessor.getInt(c));
    Assert.assertSame(c.str, factory.getFieldAccessor(type, "str").get(c));
    Assert.assertSame(((Parent) c).value, factory.getFieldAccessor(type, "value").get(c));
    Assert.assertEquals(((Parent) c).b, factory.getFieldAccessor(type, "b").get(c));
}
Also used : ASMFieldAccessorFactory(io.cdap.cdap.internal.io.ASMFieldAccessorFactory) ASMFieldAccessorFactory(io.cdap.cdap.internal.io.ASMFieldAccessorFactory) FieldAccessorFactory(io.cdap.cdap.internal.io.FieldAccessorFactory) FieldAccessor(io.cdap.cdap.internal.io.FieldAccessor) Test(org.junit.Test)

Aggregations

ASMFieldAccessorFactory (io.cdap.cdap.internal.io.ASMFieldAccessorFactory)2 FieldAccessor (io.cdap.cdap.internal.io.FieldAccessor)2 FieldAccessorFactory (io.cdap.cdap.internal.io.FieldAccessorFactory)2 Test (org.junit.Test)2