Skip to content

Commit f3c29fe

Browse files
committed
Add test for UriUtils.encode(String, Charset)
Issue: SPR-17451
1 parent abf9ce8 commit f3c29fe

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

spring-web/src/test/java/org/springframework/web/util/UriUtilsTests.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.web.util;
1818

19-
import java.io.UnsupportedEncodingException;
2019
import java.nio.charset.Charset;
2120
import java.nio.charset.StandardCharsets;
2221

@@ -35,65 +34,72 @@ public class UriUtilsTests {
3534

3635

3736
@Test
38-
public void encodeScheme() throws UnsupportedEncodingException {
37+
public void encodeScheme() {
3938
assertEquals("Invalid encoded result", "foobar+-.", UriUtils.encodeScheme("foobar+-.", CHARSET));
4039
assertEquals("Invalid encoded result", "foo%20bar", UriUtils.encodeScheme("foo bar", CHARSET));
4140
}
4241

4342
@Test
44-
public void encodeUserInfo() throws UnsupportedEncodingException {
43+
public void encodeUserInfo() {
4544
assertEquals("Invalid encoded result", "foobar:", UriUtils.encodeUserInfo("foobar:", CHARSET));
4645
assertEquals("Invalid encoded result", "foo%20bar", UriUtils.encodeUserInfo("foo bar", CHARSET));
4746
}
4847

4948
@Test
50-
public void encodeHost() throws UnsupportedEncodingException {
49+
public void encodeHost() {
5150
assertEquals("Invalid encoded result", "foobar", UriUtils.encodeHost("foobar", CHARSET));
5251
assertEquals("Invalid encoded result", "foo%20bar", UriUtils.encodeHost("foo bar", CHARSET));
5352
}
5453

5554
@Test
56-
public void encodePort() throws UnsupportedEncodingException {
55+
public void encodePort() {
5756
assertEquals("Invalid encoded result", "80", UriUtils.encodePort("80", CHARSET));
5857
}
5958

6059
@Test
61-
public void encodePath() throws UnsupportedEncodingException {
60+
public void encodePath() {
6261
assertEquals("Invalid encoded result", "/foo/bar", UriUtils.encodePath("/foo/bar", CHARSET));
6362
assertEquals("Invalid encoded result", "/foo%20bar", UriUtils.encodePath("/foo bar", CHARSET));
6463
assertEquals("Invalid encoded result", "/Z%C3%BCrich", UriUtils.encodePath("/Z\u00fcrich", CHARSET));
6564
}
6665

6766
@Test
68-
public void encodePathSegment() throws UnsupportedEncodingException {
67+
public void encodePathSegment() {
6968
assertEquals("Invalid encoded result", "foobar", UriUtils.encodePathSegment("foobar", CHARSET));
7069
assertEquals("Invalid encoded result", "%2Ffoo%2Fbar", UriUtils.encodePathSegment("/foo/bar", CHARSET));
7170
}
7271

7372
@Test
74-
public void encodeQuery() throws UnsupportedEncodingException {
73+
public void encodeQuery() {
7574
assertEquals("Invalid encoded result", "foobar", UriUtils.encodeQuery("foobar", CHARSET));
7675
assertEquals("Invalid encoded result", "foo%20bar", UriUtils.encodeQuery("foo bar", CHARSET));
7776
assertEquals("Invalid encoded result", "foobar/+", UriUtils.encodeQuery("foobar/+", CHARSET));
7877
assertEquals("Invalid encoded result", "T%C5%8Dky%C5%8D", UriUtils.encodeQuery("T\u014dky\u014d", CHARSET));
7978
}
8079

8180
@Test
82-
public void encodeQueryParam() throws UnsupportedEncodingException {
81+
public void encodeQueryParam() {
8382
assertEquals("Invalid encoded result", "foobar", UriUtils.encodeQueryParam("foobar", CHARSET));
8483
assertEquals("Invalid encoded result", "foo%20bar", UriUtils.encodeQueryParam("foo bar", CHARSET));
8584
assertEquals("Invalid encoded result", "foo%26bar", UriUtils.encodeQueryParam("foo&bar", CHARSET));
8685
}
8786

8887
@Test
89-
public void encodeFragment() throws UnsupportedEncodingException {
88+
public void encodeFragment() {
9089
assertEquals("Invalid encoded result", "foobar", UriUtils.encodeFragment("foobar", CHARSET));
9190
assertEquals("Invalid encoded result", "foo%20bar", UriUtils.encodeFragment("foo bar", CHARSET));
9291
assertEquals("Invalid encoded result", "foobar/", UriUtils.encodeFragment("foobar/", CHARSET));
9392
}
9493

9594
@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() {
97103
assertEquals("Invalid encoded URI", "", UriUtils.decode("", CHARSET));
98104
assertEquals("Invalid encoded URI", "foobar", UriUtils.decode("foobar", CHARSET));
99105
assertEquals("Invalid encoded URI", "foo bar", UriUtils.decode("foo%20bar", CHARSET));
@@ -104,7 +110,7 @@ public void decode() throws UnsupportedEncodingException {
104110
}
105111

106112
@Test(expected = IllegalArgumentException.class)
107-
public void decodeInvalidSequence() throws UnsupportedEncodingException {
113+
public void decodeInvalidSequence() {
108114
UriUtils.decode("foo%2", CHARSET);
109115
}
110116

0 commit comments

Comments
 (0)