use of org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher in project SimpleFlatMapper by arnaudroger.
the class SubPropertyMetaTest method testSubProperty.
@Test
@SuppressWarnings("unchecked")
public void testSubProperty() throws Exception {
ClassMeta<Db1DeepObject> classMeta = ReflectionService.newInstance().getClassMeta(Db1DeepObject.class);
PropertyMeta<Db1DeepObject, String> property = classMeta.newPropertyFinder(new Predicate<PropertyMeta<?, ?>>() {
@Override
public boolean test(PropertyMeta<?, ?> propertyMeta) {
return true;
}
}).findProperty(new DefaultPropertyNameMatcher("dbObject_name", 0, false, false), new Object[0]);
assertTrue(property instanceof SubPropertyMeta);
assertTrue(property.isSubProperty());
assertTrue(property.toString().startsWith("SubPropertyMeta{" + "ownerProperty=ObjectPropertyMeta{"));
SubPropertyMeta<Db1DeepObject, DbObject, String> subPropertyMeta = (SubPropertyMeta<Db1DeepObject, DbObject, String>) property;
assertEquals(String.class, subPropertyMeta.getPropertyType());
assertEquals("dbObject.name", subPropertyMeta.getPath());
Db1DeepObject object = new Db1DeepObject();
object.setDbObject(new DbObject());
subPropertyMeta.getSetter().set(object, "n1");
Getter<Db1DeepObject, String> getter = subPropertyMeta.getGetter();
assertEquals("n1", getter.get(object));
Db1DeepObject objectNull = new Db1DeepObject();
assertEquals(null, getter.get(objectNull));
assertTrue(getter.toString().startsWith("GetterOnGetter{g1="));
ClassMeta<?> meta = subPropertyMeta.getPropertyClassMeta();
assertEquals(String.class, meta.getType());
}
Aggregations