Search in sources :

Example 51 with PropertyEditor

use of java.beans.PropertyEditor in project spring-framework by spring-projects.

the class CustomEditorTests method testLocaleEditor.

@Test
void testLocaleEditor() {
    PropertyEditor localeEditor = new LocaleEditor();
    localeEditor.setAsText("en_CA");
    assertThat(localeEditor.getValue()).isEqualTo(Locale.CANADA);
    assertThat(localeEditor.getAsText()).isEqualTo("en_CA");
    localeEditor = new LocaleEditor();
    assertThat(localeEditor.getAsText()).isEmpty();
}
Also used : PropertyEditor(java.beans.PropertyEditor) Test(org.junit.jupiter.api.Test)

Example 52 with PropertyEditor

use of java.beans.PropertyEditor in project spring-framework by spring-projects.

the class CustomEditorTests method testUninitializedArrayPropertyWithCustomEditor.

@Test
void testUninitializedArrayPropertyWithCustomEditor() {
    IndexedTestBean bean = new IndexedTestBean(false);
    BeanWrapper bw = new BeanWrapperImpl(bean);
    PropertyEditor pe = new CustomNumberEditor(Integer.class, true);
    bw.registerCustomEditor(null, "list.age", pe);
    TestBean tb = new TestBean();
    bw.setPropertyValue("list", new ArrayList<>());
    bw.setPropertyValue("list[0]", tb);
    assertThat(bean.getList().get(0)).isEqualTo(tb);
    assertThat(bw.findCustomEditor(int.class, "list.age")).isEqualTo(pe);
    assertThat(bw.findCustomEditor(null, "list.age")).isEqualTo(pe);
    assertThat(bw.findCustomEditor(int.class, "list[0].age")).isEqualTo(pe);
    assertThat(bw.findCustomEditor(null, "list[0].age")).isEqualTo(pe);
}
Also used : IndexedTestBean(org.springframework.beans.testfixture.beans.IndexedTestBean) BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) BooleanTestBean(org.springframework.beans.testfixture.beans.BooleanTestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) NumberTestBean(org.springframework.beans.testfixture.beans.NumberTestBean) IndexedTestBean(org.springframework.beans.testfixture.beans.IndexedTestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) PropertyEditor(java.beans.PropertyEditor) Test(org.junit.jupiter.api.Test)

Example 53 with PropertyEditor

use of java.beans.PropertyEditor in project spring-framework by spring-projects.

the class ResourceArrayPropertyEditorTests method vanillaResource.

@Test
void vanillaResource() {
    PropertyEditor editor = new ResourceArrayPropertyEditor();
    editor.setAsText("classpath:org/springframework/core/io/support/ResourceArrayPropertyEditor.class");
    Resource[] resources = (Resource[]) editor.getValue();
    assertThat(resources).isNotNull();
    assertThat(resources[0].exists()).isTrue();
}
Also used : Resource(org.springframework.core.io.Resource) PropertyEditor(java.beans.PropertyEditor) Test(org.junit.jupiter.api.Test)

Example 54 with PropertyEditor

use of java.beans.PropertyEditor in project spring-framework by spring-projects.

the class CustomEditorTests method testFileEditorWithAbsolutePath.

@Test
void testFileEditorWithAbsolutePath() {
    PropertyEditor fileEditor = new FileEditor();
    // testing on Windows
    if (new File("C:/myfile.txt").isAbsolute()) {
        fileEditor.setAsText("C:/myfile.txt");
        assertThat(fileEditor.getValue()).isEqualTo(new File("C:/myfile.txt"));
    }
    // testing on Unix
    if (new File("/myfile.txt").isAbsolute()) {
        fileEditor.setAsText("/myfile.txt");
        assertThat(fileEditor.getValue()).isEqualTo(new File("/myfile.txt"));
    }
}
Also used : PropertyEditor(java.beans.PropertyEditor) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 55 with PropertyEditor

use of java.beans.PropertyEditor in project spring-framework by spring-projects.

the class CustomEditorTests method testClassEditorWithArray.

@Test
void testClassEditorWithArray() {
    PropertyEditor classEditor = new ClassEditor();
    classEditor.setAsText("org.springframework.beans.testfixture.beans.TestBean[]");
    assertThat(classEditor.getValue()).isEqualTo(TestBean[].class);
    assertThat(classEditor.getAsText()).isEqualTo("org.springframework.beans.testfixture.beans.TestBean[]");
}
Also used : BooleanTestBean(org.springframework.beans.testfixture.beans.BooleanTestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) NumberTestBean(org.springframework.beans.testfixture.beans.NumberTestBean) IndexedTestBean(org.springframework.beans.testfixture.beans.IndexedTestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) PropertyEditor(java.beans.PropertyEditor) Test(org.junit.jupiter.api.Test)

Aggregations

PropertyEditor (java.beans.PropertyEditor)167 Test (org.junit.jupiter.api.Test)59 HashMap (java.util.HashMap)14 Test (org.junit.Test)13 Map (java.util.Map)11 File (java.io.File)10 URI (java.net.URI)9 TestBean (org.springframework.beans.testfixture.beans.TestBean)9 IOException (java.io.IOException)7 Path (java.nio.file.Path)7 Resource (org.springframework.core.io.Resource)7 Method (java.lang.reflect.Method)6 URL (java.net.URL)6 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)6 IndexedTestBean (org.springframework.beans.testfixture.beans.IndexedTestBean)6 PropertyDescriptor (java.beans.PropertyDescriptor)5 Field (java.lang.reflect.Field)4 ArrayList (java.util.ArrayList)4 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)4 StringArrayPropertyEditor (org.springframework.beans.propertyeditors.StringArrayPropertyEditor)4