@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2007 the original author or authors .
* Copyright 2002 - 2009 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -19,16 +19,19 @@ package org.springframework.beans.propertyeditors;
@@ -19,16 +19,19 @@ package org.springframework.beans.propertyeditors;
import java.beans.PropertyEditor ;
import java.net.URI ;
import junit.framework.TestCase ;
import static org.junit.Assert.* ;
import org.junit.Test ;
import org.springframework.util.ClassUtils ;
/ * *
* @author Juergen Hoeller
* @author Arjen Poutsma
* /
public class URIEditorTests extends TestCase {
public class URIEditorTests {
public void testStandardURI ( ) throws Exception {
@Test
public void standardURI ( ) throws Exception {
PropertyEditor uriEditor = new URIEditor ( ) ;
uriEditor . setAsText ( "mailto:juergen.hoeller@interface21.com" ) ;
Object value = uriEditor . getValue ( ) ;
@ -37,7 +40,8 @@ public class URIEditorTests extends TestCase {
@@ -37,7 +40,8 @@ public class URIEditorTests extends TestCase {
assertEquals ( uri . toString ( ) , uriEditor . getAsText ( ) ) ;
}
public void testStandardURL ( ) throws Exception {
@Test
public void standardURL ( ) throws Exception {
PropertyEditor uriEditor = new URIEditor ( ) ;
uriEditor . setAsText ( "http://www.springframework.org" ) ;
Object value = uriEditor . getValue ( ) ;
@ -46,7 +50,8 @@ public class URIEditorTests extends TestCase {
@@ -46,7 +50,8 @@ public class URIEditorTests extends TestCase {
assertEquals ( uri . toString ( ) , uriEditor . getAsText ( ) ) ;
}
public void testStandardURLWithWhitespace ( ) throws Exception {
@Test
public void standardURLWithWhitespace ( ) throws Exception {
PropertyEditor uriEditor = new URIEditor ( ) ;
uriEditor . setAsText ( " http://www.springframework.org " ) ;
Object value = uriEditor . getValue ( ) ;
@ -55,7 +60,8 @@ public class URIEditorTests extends TestCase {
@@ -55,7 +60,8 @@ public class URIEditorTests extends TestCase {
assertEquals ( uri . toString ( ) , uriEditor . getAsText ( ) ) ;
}
public void testClasspathURL ( ) throws Exception {
@Test
public void classpathURL ( ) throws Exception {
PropertyEditor uriEditor = new URIEditor ( getClass ( ) . getClassLoader ( ) ) ;
uriEditor . setAsText ( "classpath:" + ClassUtils . classPackageAsResourcePath ( getClass ( ) ) +
"/" + ClassUtils . getShortName ( getClass ( ) ) + ".class" ) ;
@ -66,7 +72,8 @@ public class URIEditorTests extends TestCase {
@@ -66,7 +72,8 @@ public class URIEditorTests extends TestCase {
assertTrue ( ! uri . getScheme ( ) . startsWith ( "classpath" ) ) ;
}
public void testClasspathURLWithWhitespace ( ) throws Exception {
@Test
public void classpathURLWithWhitespace ( ) throws Exception {
PropertyEditor uriEditor = new URIEditor ( getClass ( ) . getClassLoader ( ) ) ;
uriEditor . setAsText ( " classpath:" + ClassUtils . classPackageAsResourcePath ( getClass ( ) ) +
"/" + ClassUtils . getShortName ( getClass ( ) ) + ".class " ) ;
@ -77,7 +84,8 @@ public class URIEditorTests extends TestCase {
@@ -77,7 +84,8 @@ public class URIEditorTests extends TestCase {
assertTrue ( ! uri . getScheme ( ) . startsWith ( "classpath" ) ) ;
}
public void testClasspathURLAsIs ( ) throws Exception {
@Test
public void classpathURLAsIs ( ) throws Exception {
PropertyEditor uriEditor = new URIEditor ( ) ;
uriEditor . setAsText ( "classpath:test.txt" ) ;
Object value = uriEditor . getValue ( ) ;
@ -87,7 +95,8 @@ public class URIEditorTests extends TestCase {
@@ -87,7 +95,8 @@ public class URIEditorTests extends TestCase {
assertTrue ( uri . getScheme ( ) . startsWith ( "classpath" ) ) ;
}
public void testWithNonExistentResource ( ) throws Exception {
@Test
public void withNonExistentResource ( ) throws Exception {
PropertyEditor uriEditor = new URIEditor ( ) ;
uriEditor . setAsText ( "gonna:/freak/in/the/morning/freak/in/the.evening" ) ;
Object value = uriEditor . getValue ( ) ;
@ -96,16 +105,29 @@ public class URIEditorTests extends TestCase {
@@ -96,16 +105,29 @@ public class URIEditorTests extends TestCase {
assertEquals ( uri . toString ( ) , uriEditor . getAsText ( ) ) ;
}
public void testSetAsTextWithNull ( ) throws Exception {
@Test
public void setAsTextWithNull ( ) throws Exception {
PropertyEditor uriEditor = new URIEditor ( ) ;
uriEditor . setAsText ( null ) ;
assertNull ( uriEditor . getValue ( ) ) ;
assertEquals ( "" , uriEditor . getAsText ( ) ) ;
}
public void testGetAsTextReturnsEmptyStringIfValueNotSet ( ) throws Exception {
@Test
public void getAsTextReturnsEmptyStringIfValueNotSet ( ) throws Exception {
PropertyEditor uriEditor = new URIEditor ( ) ;
assertEquals ( "" , uriEditor . 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 ( ) ) ;
}
}