Chnages for BAEL-527 (#2621)
This commit is contained in:
parent
113294324e
commit
231500bbf6
@ -211,6 +211,11 @@
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>1.19</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>4.3.4.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -464,7 +469,7 @@
|
||||
<protonpack.version>1.13</protonpack.version>
|
||||
<streamex.version>0.6.5</streamex.version>
|
||||
<vavr.version>0.9.0</vavr.version>
|
||||
|
||||
|
||||
<!-- testing -->
|
||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
|
@ -1,20 +1,23 @@
|
||||
package com.baeldung.encoderdecoder;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import org.springframework.web.util.UriUtils;
|
||||
|
||||
public class EncoderDecoderUnitTest {
|
||||
|
||||
@ -76,19 +79,20 @@ public class EncoderDecoderUnitTest {
|
||||
|
||||
private String encodePath(String path) {
|
||||
try {
|
||||
path = new URI(null, null, path, null).getPath();
|
||||
} catch (URISyntaxException e) {
|
||||
path = UriUtils.encodePath(path, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
LOGGER.error("Error encoding parameter {}", e.getMessage(), e);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenPath_thenEncodeDecodePath() throws URISyntaxException {
|
||||
URI uri = new URI(null, null, "/Path 1/Path+2", null);
|
||||
|
||||
Assert.assertEquals("/Path 1/Path+2", uri.getPath());
|
||||
Assert.assertEquals("/Path%201/Path+2", uri.getRawPath());
|
||||
public void givenPathSegment_thenEncodeDecode() throws UnsupportedEncodingException {
|
||||
String pathSegment = "/Path 1/Path+2";
|
||||
String encodedPathSegment = encodePath(pathSegment);
|
||||
String decodedPathSegment = UriUtils.decode(encodedPathSegment, "UTF-8");
|
||||
Assert.assertEquals("/Path%201/Path+2", encodedPathSegment);
|
||||
Assert.assertEquals("/Path 1/Path+2", decodedPathSegment);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user