use of org.springframework.beans.testfixture.beans.GenericBean in project spring-framework by spring-projects.
the class BeanFactoryGenericsTests method testGenericSetListFactoryMethod.
@Test
void testGenericSetListFactoryMethod() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setFactoryMethodName("createInstance");
Set<String> input = new HashSet<>();
input.add("4");
input.add("5");
List<String> input2 = new ArrayList<>();
input2.add("http://localhost:8080");
input2.add("http://localhost:9090");
rbd.getConstructorArgumentValues().addGenericArgumentValue(input);
rbd.getConstructorArgumentValues().addGenericArgumentValue(input2);
bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
assertThat(gb.getIntegerSet().contains(4)).isTrue();
assertThat(gb.getIntegerSet().contains(5)).isTrue();
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 BeanFactoryGenericsTests method testGenericListProperty.
@Test
void testGenericListProperty() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
List<String> input = new ArrayList<>();
input.add("http://localhost:8080");
input.add("http://localhost:9090");
rbd.getPropertyValues().add("resourceList", input);
bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
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 testGenericListOfArraysWithElementConversion.
@Test
void testGenericListOfArraysWithElementConversion() {
GenericBean<String> gb = new GenericBean<>();
ArrayList<String[]> list = new ArrayList<>();
list.add(new String[] { "str1", "str2" });
gb.setListOfArrays(list);
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.registerCustomEditor(String.class, new StringTrimmerEditor(false));
bw.setPropertyValue("listOfArrays[0][1]", "str3 ");
assertThat(bw.getPropertyValue("listOfArrays[0][1]")).isEqualTo("str3");
assertThat(gb.getListOfArrays().get(0)[1]).isEqualTo("str3");
}
use of org.springframework.beans.testfixture.beans.GenericBean in project spring-framework by spring-projects.
the class BeanWrapperGenericsTests method testGenericSetWithConversionFailure.
@Test
void testGenericSetWithConversionFailure() {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
Set<TestBean> input = new HashSet<>();
input.add(new TestBean());
assertThatExceptionOfType(TypeMismatchException.class).isThrownBy(() -> bw.setPropertyValue("integerSet", input)).withMessageContaining("java.lang.Integer");
}
use of org.springframework.beans.testfixture.beans.GenericBean in project spring-framework by spring-projects.
the class BeanWrapperGenericsTests method testGenericListElement.
@Test
void testGenericListElement() throws Exception {
GenericBean<?> gb = new GenericBean<>();
gb.setResourceList(new ArrayList<>());
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("resourceList[0]", "http://localhost:8080");
assertThat(gb.getResourceList().get(0)).isEqualTo(new UrlResource("http://localhost:8080"));
}
Aggregations