1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 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.
16
16
17
17
package org .springframework .web .util ;
18
18
19
- import java .io .UnsupportedEncodingException ;
20
19
import java .nio .charset .Charset ;
21
20
import java .nio .charset .StandardCharsets ;
22
21
@@ -35,65 +34,72 @@ public class UriUtilsTests {
35
34
36
35
37
36
@ Test
38
- public void encodeScheme () throws UnsupportedEncodingException {
37
+ public void encodeScheme () {
39
38
assertEquals ("Invalid encoded result" , "foobar+-." , UriUtils .encodeScheme ("foobar+-." , CHARSET ));
40
39
assertEquals ("Invalid encoded result" , "foo%20bar" , UriUtils .encodeScheme ("foo bar" , CHARSET ));
41
40
}
42
41
43
42
@ Test
44
- public void encodeUserInfo () throws UnsupportedEncodingException {
43
+ public void encodeUserInfo () {
45
44
assertEquals ("Invalid encoded result" , "foobar:" , UriUtils .encodeUserInfo ("foobar:" , CHARSET ));
46
45
assertEquals ("Invalid encoded result" , "foo%20bar" , UriUtils .encodeUserInfo ("foo bar" , CHARSET ));
47
46
}
48
47
49
48
@ Test
50
- public void encodeHost () throws UnsupportedEncodingException {
49
+ public void encodeHost () {
51
50
assertEquals ("Invalid encoded result" , "foobar" , UriUtils .encodeHost ("foobar" , CHARSET ));
52
51
assertEquals ("Invalid encoded result" , "foo%20bar" , UriUtils .encodeHost ("foo bar" , CHARSET ));
53
52
}
54
53
55
54
@ Test
56
- public void encodePort () throws UnsupportedEncodingException {
55
+ public void encodePort () {
57
56
assertEquals ("Invalid encoded result" , "80" , UriUtils .encodePort ("80" , CHARSET ));
58
57
}
59
58
60
59
@ Test
61
- public void encodePath () throws UnsupportedEncodingException {
60
+ public void encodePath () {
62
61
assertEquals ("Invalid encoded result" , "/foo/bar" , UriUtils .encodePath ("/foo/bar" , CHARSET ));
63
62
assertEquals ("Invalid encoded result" , "/foo%20bar" , UriUtils .encodePath ("/foo bar" , CHARSET ));
64
63
assertEquals ("Invalid encoded result" , "/Z%C3%BCrich" , UriUtils .encodePath ("/Z\u00fc rich" , CHARSET ));
65
64
}
66
65
67
66
@ Test
68
- public void encodePathSegment () throws UnsupportedEncodingException {
67
+ public void encodePathSegment () {
69
68
assertEquals ("Invalid encoded result" , "foobar" , UriUtils .encodePathSegment ("foobar" , CHARSET ));
70
69
assertEquals ("Invalid encoded result" , "%2Ffoo%2Fbar" , UriUtils .encodePathSegment ("/foo/bar" , CHARSET ));
71
70
}
72
71
73
72
@ Test
74
- public void encodeQuery () throws UnsupportedEncodingException {
73
+ public void encodeQuery () {
75
74
assertEquals ("Invalid encoded result" , "foobar" , UriUtils .encodeQuery ("foobar" , CHARSET ));
76
75
assertEquals ("Invalid encoded result" , "foo%20bar" , UriUtils .encodeQuery ("foo bar" , CHARSET ));
77
76
assertEquals ("Invalid encoded result" , "foobar/+" , UriUtils .encodeQuery ("foobar/+" , CHARSET ));
78
77
assertEquals ("Invalid encoded result" , "T%C5%8Dky%C5%8D" , UriUtils .encodeQuery ("T\u014d ky\u014d " , CHARSET ));
79
78
}
80
79
81
80
@ Test
82
- public void encodeQueryParam () throws UnsupportedEncodingException {
81
+ public void encodeQueryParam () {
83
82
assertEquals ("Invalid encoded result" , "foobar" , UriUtils .encodeQueryParam ("foobar" , CHARSET ));
84
83
assertEquals ("Invalid encoded result" , "foo%20bar" , UriUtils .encodeQueryParam ("foo bar" , CHARSET ));
85
84
assertEquals ("Invalid encoded result" , "foo%26bar" , UriUtils .encodeQueryParam ("foo&bar" , CHARSET ));
86
85
}
87
86
88
87
@ Test
89
- public void encodeFragment () throws UnsupportedEncodingException {
88
+ public void encodeFragment () {
90
89
assertEquals ("Invalid encoded result" , "foobar" , UriUtils .encodeFragment ("foobar" , CHARSET ));
91
90
assertEquals ("Invalid encoded result" , "foo%20bar" , UriUtils .encodeFragment ("foo bar" , CHARSET ));
92
91
assertEquals ("Invalid encoded result" , "foobar/" , UriUtils .encodeFragment ("foobar/" , CHARSET ));
93
92
}
94
93
95
94
@ Test
96
- public void decode () throws UnsupportedEncodingException {
95
+ public void encode () {
96
+ assertEquals ("Invalid encoded result" , "foo" , UriUtils .encode ("foo" , CHARSET ));
97
+ assertEquals ("Invalid encoded result" , "http%3A%2F%2Fexample.com%2Ffoo%20bar" ,
98
+ UriUtils .encode ("http://example.com/foo bar" , CHARSET ));
99
+ }
100
+
101
+ @ Test
102
+ public void decode () {
97
103
assertEquals ("Invalid encoded URI" , "" , UriUtils .decode ("" , CHARSET ));
98
104
assertEquals ("Invalid encoded URI" , "foobar" , UriUtils .decode ("foobar" , CHARSET ));
99
105
assertEquals ("Invalid encoded URI" , "foo bar" , UriUtils .decode ("foo%20bar" , CHARSET ));
@@ -104,7 +110,7 @@ public void decode() throws UnsupportedEncodingException {
104
110
}
105
111
106
112
@ Test (expected = IllegalArgumentException .class )
107
- public void decodeInvalidSequence () throws UnsupportedEncodingException {
113
+ public void decodeInvalidSequence () {
108
114
UriUtils .decode ("foo%2" , CHARSET );
109
115
}
110
116
0 commit comments