Search in sources :

Example 71 with BeanWrapperImpl

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();
}
Also used : BeanWrapper(cn.taketoday.beans.BeanWrapper) BeanWrapperImpl(cn.taketoday.beans.BeanWrapperImpl) Test(org.junit.jupiter.api.Test)

Example 72 with BeanWrapperImpl

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();
}
Also used : BeanWrapper(cn.taketoday.beans.BeanWrapper) BeanWrapperImpl(cn.taketoday.beans.BeanWrapperImpl) Test(org.junit.jupiter.api.Test)

Aggregations

BeanWrapperImpl (cn.taketoday.beans.BeanWrapperImpl)72 Test (org.junit.jupiter.api.Test)64 BeanWrapper (cn.taketoday.beans.BeanWrapper)60 NumberTestBean (cn.taketoday.beans.NumberTestBean)42 BooleanTestBean (cn.taketoday.beans.BooleanTestBean)40 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)34 IndexedTestBean (cn.taketoday.beans.testfixture.beans.IndexedTestBean)34 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)34 PropertyEditorSupport (java.beans.PropertyEditorSupport)28 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)28 PropertyValues (cn.taketoday.beans.PropertyValues)18 BeansException (cn.taketoday.beans.BeansException)8 BeanProperty (cn.taketoday.beans.BeanProperty)6 TypeMismatchException (cn.taketoday.beans.TypeMismatchException)6 BigDecimal (java.math.BigDecimal)6 NumberFormat (java.text.NumberFormat)6 PropertyValue (cn.taketoday.beans.PropertyValue)4 BeanCreationException (cn.taketoday.beans.factory.BeanCreationException)4 BeanDefinitionStoreException (cn.taketoday.beans.factory.BeanDefinitionStoreException)4 InjectionPoint (cn.taketoday.beans.factory.InjectionPoint)4