Search in sources :

Example 56 with PropertyEditor

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

the class CustomEditorTests method testClassEditor.

@Test
void testClassEditor() {
    PropertyEditor classEditor = new ClassEditor();
    classEditor.setAsText(TestBean.class.getName());
    assertThat(classEditor.getValue()).isEqualTo(TestBean.class);
    assertThat(classEditor.getAsText()).isEqualTo(TestBean.class.getName());
    classEditor.setAsText(null);
    assertThat(classEditor.getAsText()).isEmpty();
    classEditor.setAsText("");
    assertThat(classEditor.getAsText()).isEmpty();
    classEditor.setAsText("\t  ");
    assertThat(classEditor.getAsText()).isEmpty();
}
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)

Example 57 with PropertyEditor

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

the class URIEditorTests method encodeURI.

@Test
public void encodeURI() throws Exception {
    PropertyEditor uriEditor = new URIEditor();
    uriEditor.setAsText("https://example.com/spaces and \u20AC");
    Object value = uriEditor.getValue();
    boolean condition = value instanceof URI;
    assertThat(condition).isTrue();
    URI uri = (URI) value;
    assertThat(uriEditor.getAsText()).isEqualTo(uri.toString());
    assertThat(uri.toASCIIString()).isEqualTo("https://example.com/spaces%20and%20%E2%82%AC");
}
Also used : PropertyEditor(java.beans.PropertyEditor) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 58 with PropertyEditor

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

the class URIEditorTests method classpathURLAsIs.

@Test
public void classpathURLAsIs() throws Exception {
    PropertyEditor uriEditor = new URIEditor();
    uriEditor.setAsText("classpath:test.txt");
    Object value = uriEditor.getValue();
    boolean condition = value instanceof URI;
    assertThat(condition).isTrue();
    URI uri = (URI) value;
    assertThat(uriEditor.getAsText()).isEqualTo(uri.toString());
    assertThat(uri.getScheme().startsWith("classpath")).isTrue();
}
Also used : PropertyEditor(java.beans.PropertyEditor) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 59 with PropertyEditor

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

the class URIEditorTests method getAsTextReturnsEmptyStringIfValueNotSet.

@Test
public void getAsTextReturnsEmptyStringIfValueNotSet() throws Exception {
    PropertyEditor uriEditor = new URIEditor();
    assertThat(uriEditor.getAsText()).isEqualTo("");
}
Also used : PropertyEditor(java.beans.PropertyEditor) Test(org.junit.jupiter.api.Test)

Example 60 with PropertyEditor

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

the class URIEditorTests method classpathURLWithWhitespace.

@Test
public void classpathURLWithWhitespace() throws Exception {
    PropertyEditor uriEditor = new URIEditor(getClass().getClassLoader());
    uriEditor.setAsText("  classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class  ");
    Object value = uriEditor.getValue();
    boolean condition1 = value instanceof URI;
    assertThat(condition1).isTrue();
    URI uri = (URI) value;
    assertThat(uriEditor.getAsText()).isEqualTo(uri.toString());
    boolean condition = !uri.getScheme().startsWith("classpath");
    assertThat(condition).isTrue();
}
Also used : PropertyEditor(java.beans.PropertyEditor) URI(java.net.URI) 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