Search in sources :

Example 1 with GenericBean

use of cn.taketoday.beans.testfixture.beans.GenericBean in project today-infrastructure by TAKETODAY.

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 UrlBasedResource("http://localhost:8080"));
}
Also used : UrlBasedResource(cn.taketoday.core.io.UrlBasedResource) GenericBean(cn.taketoday.beans.testfixture.beans.GenericBean) Test(org.junit.jupiter.api.Test)

Example 2 with GenericBean

use of cn.taketoday.beans.testfixture.beans.GenericBean in project today-infrastructure by TAKETODAY.

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(cn.taketoday.beans.testfixture.beans.GenericBean) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 3 with GenericBean

use of cn.taketoday.beans.testfixture.beans.GenericBean in project today-infrastructure by TAKETODAY.

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 UrlBasedResource("http://localhost:8080"));
    assertThat(gb.getResourceList().get(1)).isEqualTo(new UrlBasedResource("http://localhost:9090"));
}
Also used : UrlBasedResource(cn.taketoday.core.io.UrlBasedResource) ArrayList(java.util.ArrayList) GenericBean(cn.taketoday.beans.testfixture.beans.GenericBean) Test(org.junit.jupiter.api.Test)

Example 4 with GenericBean

use of cn.taketoday.beans.testfixture.beans.GenericBean in project today-infrastructure by TAKETODAY.

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(cn.taketoday.beans.propertyeditors.CustomNumberEditor) GenericBean(cn.taketoday.beans.testfixture.beans.GenericBean) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 5 with GenericBean

use of cn.taketoday.beans.testfixture.beans.GenericBean in project today-framework by TAKETODAY.

the class BeanWrapperEnumTests method testStandardEnumSetWithMultipleValues.

@Test
public void testStandardEnumSetWithMultipleValues() {
    GenericBean<?> gb = new GenericBean<>();
    BeanWrapper bw = new BeanWrapperImpl(gb);
    bw.setConversionService(new DefaultConversionService());
    assertThat(gb.getStandardEnumSet()).isNull();
    bw.setPropertyValue("standardEnumSet", new String[] { "VALUE_1", "VALUE_2" });
    assertThat(gb.getStandardEnumSet().size()).isEqualTo(2);
    assertThat(gb.getStandardEnumSet().contains(CustomEnum.VALUE_1)).isTrue();
    assertThat(gb.getStandardEnumSet().contains(CustomEnum.VALUE_2)).isTrue();
}
Also used : DefaultConversionService(cn.taketoday.core.conversion.support.DefaultConversionService) GenericBean(cn.taketoday.beans.testfixture.beans.GenericBean) Test(org.junit.jupiter.api.Test)

Aggregations

GenericBean (cn.taketoday.beans.testfixture.beans.GenericBean)20 Test (org.junit.jupiter.api.Test)20 HashSet (java.util.HashSet)8 CustomNumberEditor (cn.taketoday.beans.propertyeditors.CustomNumberEditor)6 ArrayList (java.util.ArrayList)6 DefaultConversionService (cn.taketoday.core.conversion.support.DefaultConversionService)4 UrlBasedResource (cn.taketoday.core.io.UrlBasedResource)4 StringTrimmerEditor (cn.taketoday.beans.propertyeditors.StringTrimmerEditor)2 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Properties (java.util.Properties)2