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();
}
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);
}
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();
}
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);
}
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);
}
Aggregations