use of org.springframework.beans.testfixture.beans.GenericBean in project spring-framework by spring-projects.
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 org.springframework.beans.testfixture.beans.GenericBean in project spring-framework by spring-projects.
the class BeanWrapperGenericsTests method testGenericList.
@Test
void testGenericList() throws Exception {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
List<String> input = new ArrayList<>();
input.add("http://localhost:8080");
input.add("http://localhost:9090");
bw.setPropertyValue("resourceList", input);
assertThat(gb.getResourceList().get(0)).isEqualTo(new UrlResource("http://localhost:8080"));
assertThat(gb.getResourceList().get(1)).isEqualTo(new UrlResource("http://localhost:9090"));
}
use of org.springframework.beans.testfixture.beans.GenericBean in project spring-framework by spring-projects.
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();
}
use of org.springframework.beans.testfixture.beans.GenericBean in project spring-framework by spring-projects.
the class BeanWrapperGenericsTests method testGenericMapFromProperties.
@Test
void testGenericMapFromProperties() {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
Properties input = new Properties();
input.setProperty("4", "5");
input.setProperty("6", "7");
bw.setPropertyValue("shortMap", input);
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
}
use of org.springframework.beans.testfixture.beans.GenericBean in project spring-framework by spring-projects.
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();
}
Aggregations