@Test public void testCharacterEditorGetAsTextReturnsEmptyStringIfValueIsNull() throws Exception { PropertyEditor charEditor = new CharacterEditor(false); assertEquals("", charEditor.getAsText()); charEditor = new CharacterEditor(true); charEditor.setAsText(null); assertEquals("", charEditor.getAsText()); charEditor.setAsText(""); assertEquals("", charEditor.getAsText()); charEditor.setAsText(" "); assertEquals(" ", charEditor.getAsText()); }
@Test public void testFileEditor() { PropertyEditor fileEditor = new FileEditor(); fileEditor.setAsText("file:myfile.txt"); assertEquals(new File("myfile.txt"), fileEditor.getValue()); assertEquals((new File("myfile.txt")).getPath(), fileEditor.getAsText()); }
@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(); assertTrue(value instanceof URI); URI uri = (URI) value; assertEquals(uri.toString(), uriEditor.getAsText()); assertTrue(!uri.getScheme().startsWith("classpath")); }
@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(); assertTrue(value instanceof URI); URI uri = (URI) value; assertEquals(uri.toString(), uriEditor.getAsText()); assertTrue(!uri.getScheme().startsWith("classpath")); }
@Test public void classpathURLAsIs() throws Exception { PropertyEditor uriEditor = new URIEditor(); uriEditor.setAsText("classpath:test.txt"); Object value = uriEditor.getValue(); assertTrue(value instanceof URI); URI uri = (URI) value; assertEquals(uri.toString(), uriEditor.getAsText()); assertTrue(uri.getScheme().startsWith("classpath")); }
@Test public void testStandardURI() throws Exception { PropertyEditor urlEditor = new URLEditor(); urlEditor.setAsText("mailto:juergen.hoeller@interface21.com"); Object value = urlEditor.getValue(); assertTrue(value instanceof URL); URL url = (URL) value; assertEquals(url.toExternalForm(), urlEditor.getAsText()); }
@Test public void testStandardURL() throws Exception { PropertyEditor urlEditor = new URLEditor(); urlEditor.setAsText("http://www.springframework.org"); Object value = urlEditor.getValue(); assertTrue(value instanceof URL); URL url = (URL) value; assertEquals(url.toExternalForm(), urlEditor.getAsText()); }
@Test public void encodeURI() throws Exception { PropertyEditor uriEditor = new URIEditor(); uriEditor.setAsText("http://example.com/spaces and \u20AC"); Object value = uriEditor.getValue(); assertTrue(value instanceof URI); URI uri = (URI) value; assertEquals(uri.toString(), uriEditor.getAsText()); assertEquals("http://example.com/spaces%20and%20%E2%82%AC", uri.toASCIIString()); }
@Test public void setAndGetAsTextWithNull() throws Exception { PropertyEditor editor = new ResourceEditor(); editor.setAsText(null); assertEquals("", editor.getAsText()); }
@Test public void encodeAlreadyEncodedURI() throws Exception { PropertyEditor uriEditor = new URIEditor(false); uriEditor.setAsText("http://example.com/spaces%20and%20%E2%82%AC"); Object value = uriEditor.getValue(); assertTrue(value instanceof URI); URI uri = (URI) value; assertEquals(uri.toString(), uriEditor.getAsText()); assertEquals("http://example.com/spaces%20and%20%E2%82%AC", uri.toASCIIString()); }
@Test public void testClasspathURL() throws Exception { PropertyEditor urlEditor = new URLEditor(); urlEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class"); Object value = urlEditor.getValue(); assertTrue(value instanceof URL); URL url = (URL) value; assertEquals(url.toExternalForm(), urlEditor.getAsText()); assertTrue(!url.getProtocol().startsWith("classpath")); }
@Test public void testLocaleEditor() { PropertyEditor localeEditor = new LocaleEditor(); localeEditor.setAsText("en_CA"); assertEquals(Locale.CANADA, localeEditor.getValue()); assertEquals("en_CA", localeEditor.getAsText()); localeEditor = new LocaleEditor(); assertEquals("", localeEditor.getAsText()); }
@Test public void setAndGetAsTextWithWhitespaceResource() throws Exception { PropertyEditor editor = new ResourceEditor(); editor.setAsText(" "); assertEquals("", editor.getAsText()); }
@Test public void testSetAsTextWithNull() throws Exception { PropertyEditor urlEditor = new URLEditor(); urlEditor.setAsText(null); assertNull(urlEditor.getValue()); assertEquals("", urlEditor.getAsText()); }
@Test public void setAsTextWithNull() throws Exception { PropertyEditor uriEditor = new URIEditor(); uriEditor.setAsText(null); assertNull(uriEditor.getValue()); assertEquals("", uriEditor.getAsText()); }
@Test public void testClassEditorWithArray() { PropertyEditor classEditor = new ClassEditor(); classEditor.setAsText("org.springframework.tests.sample.beans.TestBean[]"); assertEquals(TestBean[].class, classEditor.getValue()); assertEquals("org.springframework.tests.sample.beans.TestBean[]", classEditor.getAsText()); }
@Test public void getAsTextReturnsEmptyStringIfValueNotSet() throws Exception { PropertyEditor uriEditor = new URIEditor(); assertEquals("", uriEditor.getAsText()); }
@Test public void testGetAsTextReturnsEmptyStringIfValueNotSet() throws Exception { PropertyEditor urlEditor = new URLEditor(); assertEquals("", urlEditor.getAsText()); }