use of cn.taketoday.beans.propertyeditors.StringTrimmerEditor in project today-infrastructure by TAKETODAY.
the class DataBinderTests method conversionWithInappropriateStringEditor.
@Test
void conversionWithInappropriateStringEditor() {
DataBinder dataBinder = new DataBinder(null);
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
dataBinder.setConversionService(conversionService);
dataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
NameBean bean = new NameBean("Fred");
assertThat(dataBinder.convertIfNecessary(bean, String.class)).as("ConversionService should have invoked toString()").isEqualTo("Fred");
conversionService.addConverter(new NameBeanConverter());
assertThat(dataBinder.convertIfNecessary(bean, String.class)).as("Type converter should have been used").isEqualTo("[Fred]");
}
use of cn.taketoday.beans.propertyeditors.StringTrimmerEditor in project today-infrastructure by TAKETODAY.
the class DataBinderTests method setAutoGrowCollectionLimitAfterInitialization.
@Test
// SPR-14888
void setAutoGrowCollectionLimitAfterInitialization() {
DataBinder binder = new DataBinder(new BeanWithIntegerList());
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
assertThatIllegalStateException().isThrownBy(() -> binder.setAutoGrowCollectionLimit(257)).withMessageContaining("DataBinder is already initialized - call setAutoGrowCollectionLimit before other configuration methods");
}
use of cn.taketoday.beans.propertyeditors.StringTrimmerEditor in project today-infrastructure by TAKETODAY.
the class AbstractPropertyAccessorTests method propertyTypeIndexedProperty.
@Test
void propertyTypeIndexedProperty() {
IndexedTestBean target = new IndexedTestBean();
AbstractPropertyAccessor accessor = createAccessor(target);
assertThat(accessor.getPropertyType("map[key0]")).isNull();
accessor = createAccessor(target);
accessor.setPropertyValue("map[key0]", "my String");
assertThat(accessor.getPropertyType("map[key0]")).isEqualTo(String.class);
accessor = createAccessor(target);
accessor.registerCustomEditor(String.class, "map[key0]", new StringTrimmerEditor(false));
assertThat(accessor.getPropertyType("map[key0]")).isEqualTo(String.class);
}
use of cn.taketoday.beans.propertyeditors.StringTrimmerEditor in project today-framework by TAKETODAY.
the class DataBinderTests method testSetAutoGrowCollectionLimitAfterInitialization.
@Test
// SPR-14888
void testSetAutoGrowCollectionLimitAfterInitialization() {
DataBinder binder = new DataBinder(new BeanWithIntegerList());
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
assertThatIllegalStateException().isThrownBy(() -> binder.setAutoGrowCollectionLimit(257)).withMessageContaining("DataBinder is already initialized - call setAutoGrowCollectionLimit before other configuration methods");
}
use of cn.taketoday.beans.propertyeditors.StringTrimmerEditor in project today-framework by TAKETODAY.
the class DataBinderTests method conversionWithInappropriateStringEditor.
@Test
void conversionWithInappropriateStringEditor() {
DataBinder dataBinder = new DataBinder(null);
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
dataBinder.setConversionService(conversionService);
dataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
NameBean bean = new NameBean("Fred");
assertThat(dataBinder.convertIfNecessary(bean, String.class)).as("ConversionService should have invoked toString()").isEqualTo("Fred");
conversionService.addConverter(new NameBeanConverter());
assertThat(dataBinder.convertIfNecessary(bean, String.class)).as("Type converter should have been used").isEqualTo("[Fred]");
}
Aggregations