use of cn.taketoday.beans.BeanWrapperImpl in project today-infrastructure by TAKETODAY.
the class BeanInfoTests method testComplexObject.
@Test
public void testComplexObject() {
ValueBean bean = new ValueBean();
BeanWrapper bw = new BeanWrapperImpl(bean);
Integer value = 1;
bw.setPropertyValue("value", value);
assertThat(value).as("value not set correctly").isEqualTo(bean.getValue());
value = 2;
bw.setPropertyValue("value", value.toString());
assertThat(value).as("value not converted").isEqualTo(bean.getValue());
bw.setPropertyValue("value", null);
assertThat(bean.getValue()).as("value not null").isNull();
bw.setPropertyValue("value", "");
assertThat(bean.getValue()).as("value not converted to null").isNull();
}
use of cn.taketoday.beans.BeanWrapperImpl in project today-infrastructure by TAKETODAY.
the class CustomEditorTests method testCharacterEditorWithAllowEmpty.
@Test
void testCharacterEditorWithAllowEmpty() {
CharBean cb = new CharBean();
BeanWrapper bw = new BeanWrapperImpl(cb);
bw.registerCustomEditor(Character.class, new CharacterEditor(true));
bw.setPropertyValue("myCharacter", 'c');
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf('c'));
bw.setPropertyValue("myCharacter", "c");
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf('c'));
bw.setPropertyValue("myCharacter", "\u0041");
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf('A'));
bw.setPropertyValue("myCharacter", " ");
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf(' '));
bw.setPropertyValue("myCharacter", "");
assertThat(cb.getMyCharacter()).isNull();
}
Aggregations