use of cn.taketoday.beans.propertyeditors.CustomNumberEditor in project today-infrastructure by TAKETODAY.
the class DataBinderTests method bindingWithCustomEditorOnObjectField.
@Test
void bindingWithCustomEditorOnObjectField() {
BeanWithObjectProperty tb = new BeanWithObjectProperty();
DataBinder binder = new DataBinder(tb);
binder.registerCustomEditor(Integer.class, "object", new CustomNumberEditor(Integer.class, true));
PropertyValues pvs = new PropertyValues();
pvs.add("object", "1");
binder.bind(pvs);
assertThat(tb.getObject()).isEqualTo(1);
}
use of cn.taketoday.beans.propertyeditors.CustomNumberEditor in project today-infrastructure by TAKETODAY.
the class BeanWrapperGenericsTests method testGenericLowerBoundedSet.
@Test
void testGenericLowerBoundedSet() {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, true));
Set<String> input = new HashSet<>();
input.add("4");
input.add("5");
bw.setPropertyValue("numberSet", input);
assertThat(gb.getNumberSet().contains(4)).isTrue();
assertThat(gb.getNumberSet().contains(5)).isTrue();
}
use of cn.taketoday.beans.propertyeditors.CustomNumberEditor in project today-framework by TAKETODAY.
the class DataBinderTests method bindingWithCustomEditorOnObjectField.
@Test
void bindingWithCustomEditorOnObjectField() {
BeanWithObjectProperty tb = new BeanWithObjectProperty();
DataBinder binder = new DataBinder(tb);
binder.registerCustomEditor(Integer.class, "object", new CustomNumberEditor(Integer.class, true));
PropertyValues pvs = new PropertyValues();
pvs.add("object", "1");
binder.bind(pvs);
assertThat(tb.getObject()).isEqualTo(1);
}
use of cn.taketoday.beans.propertyeditors.CustomNumberEditor in project today-framework by TAKETODAY.
the class BeanWrapperGenericsTests method testGenericMapWithCollectionValue.
@Test
void testGenericMapWithCollectionValue() {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
Map<String, Collection<?>> input = new HashMap<>();
HashSet<Integer> value1 = new HashSet<>();
value1.add(1);
input.put("1", value1);
ArrayList<Boolean> value2 = new ArrayList<>();
value2.add(Boolean.TRUE);
input.put("2", value2);
bw.setPropertyValue("collectionMap", input);
assertThat(gb.getCollectionMap().get(1) instanceof HashSet).isTrue();
assertThat(gb.getCollectionMap().get(2) instanceof ArrayList).isTrue();
}
use of cn.taketoday.beans.propertyeditors.CustomNumberEditor in project today-framework by TAKETODAY.
the class BeanWrapperGenericsTests method testGenericMapElementWithCollectionValue.
@Test
void testGenericMapElementWithCollectionValue() {
GenericBean<?> gb = new GenericBean<>();
gb.setCollectionMap(new HashMap<>());
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
HashSet<Integer> value1 = new HashSet<>();
value1.add(1);
bw.setPropertyValue("collectionMap[1]", value1);
assertThat(gb.getCollectionMap().get(1) instanceof HashSet).isTrue();
}
Aggregations