Search in sources :

Example 1 with GenericBean

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

Example 2 with GenericBean

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"));
}
Also used : UrlResource(org.springframework.core.io.UrlResource) ArrayList(java.util.ArrayList) GenericBean(org.springframework.beans.testfixture.beans.GenericBean) Test(org.junit.jupiter.api.Test)

Example 3 with GenericBean

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

Example 4 with GenericBean

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);
}
Also used : GenericBean(org.springframework.beans.testfixture.beans.GenericBean) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 5 with GenericBean

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

Aggregations

Test (org.junit.jupiter.api.Test)19 GenericBean (org.springframework.beans.testfixture.beans.GenericBean)19 UrlResource (org.springframework.core.io.UrlResource)9 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 HashMap (java.util.HashMap)3 CustomNumberEditor (org.springframework.beans.propertyeditors.CustomNumberEditor)3 DefaultConversionService (org.springframework.core.convert.support.DefaultConversionService)2 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 Properties (java.util.Properties)1 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)1 StringTrimmerEditor (org.springframework.beans.propertyeditors.StringTrimmerEditor)1 TestBean (org.springframework.beans.testfixture.beans.TestBean)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 BindStatus (org.springframework.web.servlet.support.BindStatus)1