Search in sources :

Example 16 with IndexedTestBean

use of org.springframework.beans.testfixture.beans.IndexedTestBean in project spring-framework by spring-projects.

the class AbstractPropertyAccessorTests method setCollectionPropertyWithIntArrayValue.

@Test
// list cannot be properly parameterized as it breaks other tests
@SuppressWarnings("unchecked")
void setCollectionPropertyWithIntArrayValue() {
    IndexedTestBean target = new IndexedTestBean();
    AbstractPropertyAccessor accessor = createAccessor(target);
    Collection<Integer> coll = new HashSet<>();
    coll.add(0);
    accessor.setPropertyValue("collection", new int[] { 0 });
    List<Integer> set = new ArrayList<>();
    set.add(1);
    accessor.setPropertyValue("set", new int[] { 1 });
    List<Integer> sortedSet = new ArrayList<>();
    sortedSet.add(2);
    accessor.setPropertyValue("sortedSet", new int[] { 2 });
    Set<Integer> list = new HashSet<>();
    list.add(3);
    accessor.setPropertyValue("list", new int[] { 3 });
    assertThat(target.getCollection()).hasSize(1);
    assertThat(target.getCollection().containsAll(coll)).isTrue();
    assertThat(target.getSet().size()).isEqualTo(1);
    assertThat(target.getSet().containsAll(set)).isTrue();
    assertThat(target.getSortedSet().size()).isEqualTo(1);
    assertThat(target.getSortedSet().containsAll(sortedSet)).isTrue();
    assertThat(target.getList().size()).isEqualTo(1);
    assertThat(target.getList().containsAll(list)).isTrue();
}
Also used : IndexedTestBean(org.springframework.beans.testfixture.beans.IndexedTestBean) BigInteger(java.math.BigInteger) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 17 with IndexedTestBean

use of org.springframework.beans.testfixture.beans.IndexedTestBean in project spring-framework by spring-projects.

the class AbstractPropertyAccessorTests method setMapProperty.

@Test
void setMapProperty() {
    IndexedTestBean target = new IndexedTestBean();
    AbstractPropertyAccessor accessor = createAccessor(target);
    Map<String, String> map = new HashMap<>();
    map.put("key", "value");
    accessor.setPropertyValue("map", map);
    SortedMap<?, ?> sortedMap = new TreeMap<>();
    map.put("sortedKey", "sortedValue");
    accessor.setPropertyValue("sortedMap", sortedMap);
    assertThat((Map<?, ?>) target.getMap()).isSameAs(map);
    assertThat((Map<?, ?>) target.getSortedMap()).isSameAs(sortedMap);
}
Also used : IndexedTestBean(org.springframework.beans.testfixture.beans.IndexedTestBean) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) Test(org.junit.jupiter.api.Test)

Example 18 with IndexedTestBean

use of org.springframework.beans.testfixture.beans.IndexedTestBean in project spring-framework by spring-projects.

the class AbstractPropertyAccessorTests method setCollectionPropertyWithStringValueAndCustomEditor.

@Test
void setCollectionPropertyWithStringValueAndCustomEditor() {
    IndexedTestBean target = new IndexedTestBean();
    AbstractPropertyAccessor accessor = createAccessor(target);
    accessor.registerCustomEditor(String.class, "set", new StringTrimmerEditor(false));
    accessor.registerCustomEditor(String.class, "list", new StringTrimmerEditor(false));
    accessor.setPropertyValue("set", "set1 ");
    accessor.setPropertyValue("sortedSet", "sortedSet1");
    accessor.setPropertyValue("list", "list1 ");
    assertThat(target.getSet().size()).isEqualTo(1);
    assertThat(target.getSet().contains("set1")).isTrue();
    assertThat(target.getSortedSet().size()).isEqualTo(1);
    assertThat(target.getSortedSet().contains("sortedSet1")).isTrue();
    assertThat(target.getList().size()).isEqualTo(1);
    assertThat(target.getList().contains("list1")).isTrue();
    accessor.setPropertyValue("list", Collections.singletonList("list1 "));
    assertThat(target.getList().contains("list1")).isTrue();
}
Also used : IndexedTestBean(org.springframework.beans.testfixture.beans.IndexedTestBean) StringTrimmerEditor(org.springframework.beans.propertyeditors.StringTrimmerEditor) Test(org.junit.jupiter.api.Test)

Example 19 with IndexedTestBean

use of org.springframework.beans.testfixture.beans.IndexedTestBean in project spring-framework by spring-projects.

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);
}
Also used : IndexedTestBean(org.springframework.beans.testfixture.beans.IndexedTestBean) StringTrimmerEditor(org.springframework.beans.propertyeditors.StringTrimmerEditor) Test(org.junit.jupiter.api.Test)

Example 20 with IndexedTestBean

use of org.springframework.beans.testfixture.beans.IndexedTestBean in project spring-framework by spring-projects.

the class AbstractPropertyAccessorTests method setCollectionProperty.

@Test
void setCollectionProperty() {
    IndexedTestBean target = new IndexedTestBean();
    AbstractPropertyAccessor accessor = createAccessor(target);
    Collection<String> coll = new HashSet<>();
    coll.add("coll1");
    accessor.setPropertyValue("collection", coll);
    Set<String> set = new HashSet<>();
    set.add("set1");
    accessor.setPropertyValue("set", set);
    SortedSet<String> sortedSet = new TreeSet<>();
    sortedSet.add("sortedSet1");
    accessor.setPropertyValue("sortedSet", sortedSet);
    List<String> list = new ArrayList<>();
    list.add("list1");
    accessor.setPropertyValue("list", list);
    assertThat(target.getCollection()).isSameAs(coll);
    assertThat(target.getSet()).isSameAs(set);
    assertThat(target.getSortedSet()).isSameAs(sortedSet);
    assertThat((List<?>) target.getList()).isSameAs(list);
}
Also used : IndexedTestBean(org.springframework.beans.testfixture.beans.IndexedTestBean) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

IndexedTestBean (org.springframework.beans.testfixture.beans.IndexedTestBean)62 Test (org.junit.jupiter.api.Test)61 TestBean (org.springframework.beans.testfixture.beans.TestBean)39 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)31 PropertyEditorSupport (java.beans.PropertyEditorSupport)22 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)17 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)16 BooleanTestBean (org.springframework.beans.testfixture.beans.BooleanTestBean)15 NumberTestBean (org.springframework.beans.testfixture.beans.NumberTestBean)15 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)12 DerivedTestBean (org.springframework.beans.testfixture.beans.DerivedTestBean)11 NestedTestBean (org.springframework.beans.testfixture.beans.NestedTestBean)11 BeanWrapper (org.springframework.beans.BeanWrapper)10 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)10 ArrayList (java.util.ArrayList)7 BeanDefinitionBuilder.genericBeanDefinition (org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition)7 ChildBeanDefinition (org.springframework.beans.factory.support.ChildBeanDefinition)7 HashSet (java.util.HashSet)6 HashMap (java.util.HashMap)4 Properties (java.util.Properties)4