1
1
/*
2
- * Copyright 2002-2007 the original author or authors.
2
+ * Copyright 2002-2009 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
19
19
import java .beans .PropertyEditor ;
20
20
import java .net .URI ;
21
21
22
- import junit .framework .TestCase ;
22
+ import static org .junit .Assert .*;
23
+ import org .junit .Test ;
23
24
24
25
import org .springframework .util .ClassUtils ;
25
26
26
27
/**
27
28
* @author Juergen Hoeller
29
+ * @author Arjen Poutsma
28
30
*/
29
- public class URIEditorTests extends TestCase {
31
+ public class URIEditorTests {
30
32
31
- public void testStandardURI () throws Exception {
33
+ @ Test
34
+ public void standardURI () throws Exception {
32
35
PropertyEditor uriEditor = new URIEditor ();
33
36
uriEditor .
setAsText (
"mailto:[email protected] " );
34
37
Object value = uriEditor .getValue ();
@@ -37,7 +40,8 @@ public void testStandardURI() throws Exception {
37
40
assertEquals (uri .toString (), uriEditor .getAsText ());
38
41
}
39
42
40
- public void testStandardURL () throws Exception {
43
+ @ Test
44
+ public void standardURL () throws Exception {
41
45
PropertyEditor uriEditor = new URIEditor ();
42
46
uriEditor .setAsText ("http://www.springframework.org" );
43
47
Object value = uriEditor .getValue ();
@@ -46,7 +50,8 @@ public void testStandardURL() throws Exception {
46
50
assertEquals (uri .toString (), uriEditor .getAsText ());
47
51
}
48
52
49
- public void testStandardURLWithWhitespace () throws Exception {
53
+ @ Test
54
+ public void standardURLWithWhitespace () throws Exception {
50
55
PropertyEditor uriEditor = new URIEditor ();
51
56
uriEditor .setAsText (" http://www.springframework.org " );
52
57
Object value = uriEditor .getValue ();
@@ -55,7 +60,8 @@ public void testStandardURLWithWhitespace() throws Exception {
55
60
assertEquals (uri .toString (), uriEditor .getAsText ());
56
61
}
57
62
58
- public void testClasspathURL () throws Exception {
63
+ @ Test
64
+ public void classpathURL () throws Exception {
59
65
PropertyEditor uriEditor = new URIEditor (getClass ().getClassLoader ());
60
66
uriEditor .setAsText ("classpath:" + ClassUtils .classPackageAsResourcePath (getClass ()) +
61
67
"/" + ClassUtils .getShortName (getClass ()) + ".class" );
@@ -66,7 +72,8 @@ public void testClasspathURL() throws Exception {
66
72
assertTrue (!uri .getScheme ().startsWith ("classpath" ));
67
73
}
68
74
69
- public void testClasspathURLWithWhitespace () throws Exception {
75
+ @ Test
76
+ public void classpathURLWithWhitespace () throws Exception {
70
77
PropertyEditor uriEditor = new URIEditor (getClass ().getClassLoader ());
71
78
uriEditor .setAsText (" classpath:" + ClassUtils .classPackageAsResourcePath (getClass ()) +
72
79
"/" + ClassUtils .getShortName (getClass ()) + ".class " );
@@ -77,7 +84,8 @@ public void testClasspathURLWithWhitespace() throws Exception {
77
84
assertTrue (!uri .getScheme ().startsWith ("classpath" ));
78
85
}
79
86
80
- public void testClasspathURLAsIs () throws Exception {
87
+ @ Test
88
+ public void classpathURLAsIs () throws Exception {
81
89
PropertyEditor uriEditor = new URIEditor ();
82
90
uriEditor .setAsText ("classpath:test.txt" );
83
91
Object value = uriEditor .getValue ();
@@ -87,7 +95,8 @@ public void testClasspathURLAsIs() throws Exception {
87
95
assertTrue (uri .getScheme ().startsWith ("classpath" ));
88
96
}
89
97
90
- public void testWithNonExistentResource () throws Exception {
98
+ @ Test
99
+ public void withNonExistentResource () throws Exception {
91
100
PropertyEditor uriEditor = new URIEditor ();
92
101
uriEditor .setAsText ("gonna:/freak/in/the/morning/freak/in/the.evening" );
93
102
Object value = uriEditor .getValue ();
@@ -96,16 +105,29 @@ public void testWithNonExistentResource() throws Exception {
96
105
assertEquals (uri .toString (), uriEditor .getAsText ());
97
106
}
98
107
99
- public void testSetAsTextWithNull () throws Exception {
108
+ @ Test
109
+ public void setAsTextWithNull () throws Exception {
100
110
PropertyEditor uriEditor = new URIEditor ();
101
111
uriEditor .setAsText (null );
102
112
assertNull (uriEditor .getValue ());
103
113
assertEquals ("" , uriEditor .getAsText ());
104
114
}
105
115
106
- public void testGetAsTextReturnsEmptyStringIfValueNotSet () throws Exception {
116
+ @ Test
117
+ public void getAsTextReturnsEmptyStringIfValueNotSet () throws Exception {
107
118
PropertyEditor uriEditor = new URIEditor ();
108
119
assertEquals ("" , uriEditor .getAsText ());
109
120
}
110
121
122
+ @ Test
123
+ public void encodeURI () throws Exception {
124
+ PropertyEditor uriEditor = new URIEditor ();
125
+ uriEditor .setAsText ("http://example.com/spaces and \u20AC " );
126
+ Object value = uriEditor .getValue ();
127
+ assertTrue (value instanceof URI );
128
+ URI uri = (URI ) value ;
129
+ assertEquals (uri .toString (), uriEditor .getAsText ());
130
+ assertEquals ("http://example.com/spaces%20and%20%E2%82%AC" , uri .toASCIIString ());
131
+ }
132
+
111
133
}
0 commit comments