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