Method[] methods = pojo1.getClass().getDeclaredMethods();
for (Method method : methods) {
if(!method.getName().startsWith("set_")) continue;
Field field = pojo1.getClass()
.getDeclaredField(method.getName().substring(3));
Setter setter = msf.newSetter(method);
assertSame(field.getType(),setter.getType());
Object val1 = field.get(pojo1);
Object val2 = field.get(pojo2);
assertFalse(val1.equals(val2));
setter.setProperty(pojo2,val1);
Object val3 = field.get(pojo2);
assertEquals(val1,val3);
}
assertEquals(pojo1,pojo2);
// let's reset all values to NULL
// primitive fields will not be affected
for (Method method : methods) {
if(!method.getName().startsWith("set_")) continue;
Field field = pojo1.getClass()
.getDeclaredField(method.getName().substring(3));
Setter setter = msf.newSetter(method);
Object val1 = field.get(pojo1);
assertNotNull(val1);
setter.setProperty(pojo1,null);
Object val2 = field.get(pojo1);
if(!setter.getType().isPrimitive()){
assertNull(val2);
continue;
}
assertNotNull(val2);
// not affected