Search in sources :

Example 66 with PropertyEditor

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

the class URLEditorTests method testSetAsTextWithNull.

@Test
public void testSetAsTextWithNull() throws Exception {
    PropertyEditor urlEditor = new URLEditor();
    urlEditor.setAsText(null);
    assertThat(urlEditor.getValue()).isNull();
    assertThat(urlEditor.getAsText()).isEqualTo("");
}
Also used : PropertyEditor(java.beans.PropertyEditor) Test(org.junit.jupiter.api.Test)

Example 67 with PropertyEditor

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

the class URLEditorTests method testStandardURI.

@Test
public void testStandardURI() throws Exception {
    PropertyEditor urlEditor = new URLEditor();
    urlEditor.setAsText("mailto:juergen.hoeller@interface21.com");
    Object value = urlEditor.getValue();
    boolean condition = value instanceof URL;
    assertThat(condition).isTrue();
    URL url = (URL) value;
    assertThat(urlEditor.getAsText()).isEqualTo(url.toExternalForm());
}
Also used : PropertyEditor(java.beans.PropertyEditor) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 68 with PropertyEditor

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

the class URLEditorTests method testWithNonExistentResource.

@Test
public void testWithNonExistentResource() throws Exception {
    PropertyEditor urlEditor = new URLEditor();
    assertThatIllegalArgumentException().isThrownBy(() -> urlEditor.setAsText("gonna:/freak/in/the/morning/freak/in/the.evening"));
}
Also used : PropertyEditor(java.beans.PropertyEditor) Test(org.junit.jupiter.api.Test)

Example 69 with PropertyEditor

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

the class URIEditorTests method standardURLWithWhitespace.

@Test
public void standardURLWithWhitespace() throws Exception {
    PropertyEditor uriEditor = new URIEditor();
    uriEditor.setAsText("  https://www.springframework.org  ");
    Object value = uriEditor.getValue();
    boolean condition = value instanceof URI;
    assertThat(condition).isTrue();
    URI uri = (URI) value;
    assertThat(uri.toString()).isEqualTo("https://www.springframework.org");
}
Also used : PropertyEditor(java.beans.PropertyEditor) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 70 with PropertyEditor

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

the class URIEditorTests method classpathURL.

@Test
public void classpathURL() 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