Search in sources :

Example 1 with CustomNumberEditor

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

Example 2 with CustomNumberEditor

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();
}
Also used : CustomNumberEditor(cn.taketoday.beans.propertyeditors.CustomNumberEditor) GenericBean(cn.taketoday.beans.testfixture.beans.GenericBean) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with CustomNumberEditor

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

Example 4 with CustomNumberEditor

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();
}
Also used : CustomNumberEditor(cn.taketoday.beans.propertyeditors.CustomNumberEditor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GenericBean(cn.taketoday.beans.testfixture.beans.GenericBean) Collection(java.util.Collection) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 5 with CustomNumberEditor

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();
}
Also used : CustomNumberEditor(cn.taketoday.beans.propertyeditors.CustomNumberEditor) GenericBean(cn.taketoday.beans.testfixture.beans.GenericBean) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

CustomNumberEditor (cn.taketoday.beans.propertyeditors.CustomNumberEditor)9 Test (org.junit.jupiter.api.Test)9 GenericBean (cn.taketoday.beans.testfixture.beans.GenericBean)6 HashSet (java.util.HashSet)6 PropertyValues (cn.taketoday.beans.PropertyValues)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 BeanWithObjectProperty (cn.taketoday.validation.BeanWithObjectProperty)1 DataBinder (cn.taketoday.validation.DataBinder)1