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();
}
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);
}
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();
}
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"));
}
}
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[]");
}
Aggregations