use of org.springframework.beans.BeanWrapperImpl in project spring-framework by spring-projects.
the class CustomEditorTests method testCharacterEditorWithAllowEmpty.
@Test
public void testCharacterEditorWithAllowEmpty() {
CharBean cb = new CharBean();
BeanWrapper bw = new BeanWrapperImpl(cb);
bw.registerCustomEditor(Character.class, new CharacterEditor(true));
bw.setPropertyValue("myCharacter", new Character('c'));
assertEquals(new Character('c'), cb.getMyCharacter());
bw.setPropertyValue("myCharacter", "c");
assertEquals(new Character('c'), cb.getMyCharacter());
bw.setPropertyValue("myCharacter", "A");
assertEquals(new Character('A'), cb.getMyCharacter());
bw.setPropertyValue("myCharacter", " ");
assertEquals(new Character(' '), cb.getMyCharacter());
bw.setPropertyValue("myCharacter", "");
assertNull(cb.getMyCharacter());
}
use of org.springframework.beans.BeanWrapperImpl in project spring-framework by spring-projects.
the class CustomEditorTests method testArrayToArrayConversion.
@Test
public void testArrayToArrayConversion() throws PropertyVetoException {
IndexedTestBean tb = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.registerCustomEditor(TestBean.class, new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(new TestBean(text, 99));
}
});
bw.setPropertyValue("array", new String[] { "a", "b" });
assertEquals(2, tb.getArray().length);
assertEquals("a", tb.getArray()[0].getName());
assertEquals("b", tb.getArray()[1].getName());
}
use of org.springframework.beans.BeanWrapperImpl in project spring-framework by spring-projects.
the class CustomEditorTests method testArrayToStringConversion.
@Test
public void testArrayToStringConversion() throws PropertyVetoException {
TestBean tb = new TestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.registerCustomEditor(String.class, new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue("-" + text + "-");
}
});
bw.setPropertyValue("name", new String[] { "a", "b" });
assertEquals("-a,b-", tb.getName());
}
use of org.springframework.beans.BeanWrapperImpl in project spring-boot by spring-projects.
the class BindingPreparationTests method testAutoGrowNewNestedMapOfListOfString.
@Test
public void testAutoGrowNewNestedMapOfListOfString() throws Exception {
TargetWithNestedMapOfListOfString target = new TargetWithNestedMapOfListOfString();
BeanWrapperImpl wrapper = new BeanWrapperImpl(target);
wrapper.setAutoGrowNestedPaths(true);
RelaxedDataBinder binder = new RelaxedDataBinder(target);
binder.normalizePath(wrapper, "nested[foo][0]");
assertThat(wrapper.getPropertyValue("nested")).isNotNull();
assertThat(wrapper.getPropertyValue("nested[foo]")).isNotNull();
}
use of org.springframework.beans.BeanWrapperImpl in project spring-boot by spring-projects.
the class BindingPreparationTests method testAutoGrowNewNestedMapOfBeansWithPeriod.
@Test
public void testAutoGrowNewNestedMapOfBeansWithPeriod() throws Exception {
TargetWithNestedMapOfBean target = new TargetWithNestedMapOfBean();
BeanWrapperImpl wrapper = new BeanWrapperImpl(target);
wrapper.setAutoGrowNestedPaths(true);
RelaxedDataBinder binder = new RelaxedDataBinder(target);
String result = binder.normalizePath(wrapper, "nested.foo.foo");
assertThat(wrapper.getPropertyValue("nested")).isNotNull();
assertThat("nested[foo].foo").isEqualTo(result);
}
Aggregations