|
1 | 1 | package com.baeldung.uribuilder; |
2 | 2 |
|
3 | | -import static org.junit.Assert.assertEquals; |
4 | | - |
5 | | -import java.util.Collections; |
6 | | - |
7 | 3 | import org.junit.Test; |
8 | 4 | import org.springframework.web.util.UriComponents; |
9 | 5 | import org.springframework.web.util.UriComponentsBuilder; |
10 | 6 |
|
11 | | -public class SpringUriBuilderIntegrationTest { |
| 7 | +import java.util.Collections; |
| 8 | + |
| 9 | +import static org.junit.Assert.assertEquals; |
| 10 | + |
| 11 | +public class SpringUriBuilderUnitTest { |
12 | 12 |
|
13 | 13 | @Test |
14 | 14 | public void constructUri() { |
15 | | - UriComponents uriComponents = UriComponentsBuilder.newInstance().scheme("http").host("www.baeldung.com").path("/junit-5").build(); |
| 15 | + UriComponents uriComponents = UriComponentsBuilder.newInstance() |
| 16 | + .scheme("http").host("www.baeldung.com").path("/junit-5") |
| 17 | + .build(); |
16 | 18 |
|
17 | 19 | assertEquals("http://www.baeldung.com/junit-5", uriComponents.toUriString()); |
18 | 20 | } |
19 | 21 |
|
20 | 22 | @Test |
21 | 23 | public void constructUriEncoded() { |
22 | | - UriComponents uriComponents = UriComponentsBuilder.newInstance().scheme("http").host("www.baeldung.com").path("/junit 5").build().encode(); |
| 24 | + UriComponents uriComponents = UriComponentsBuilder.newInstance() |
| 25 | + .scheme("http").host("www.baeldung.com").path("/junit 5") |
| 26 | + .build().encode(); |
23 | 27 |
|
24 | 28 | assertEquals("http://www.baeldung.com/junit%205", uriComponents.toUriString()); |
25 | 29 | } |
26 | 30 |
|
27 | 31 | @Test |
28 | 32 | public void constructUriFromTemplate() { |
29 | | - UriComponents uriComponents = UriComponentsBuilder.newInstance().scheme("http").host("www.baeldung.com").path("/{article-name}").buildAndExpand("junit-5"); |
| 33 | + UriComponents uriComponents = UriComponentsBuilder.newInstance() |
| 34 | + .scheme("http").host("www.baeldung.com").path("/{article-name}") |
| 35 | + .buildAndExpand("junit-5"); |
30 | 36 |
|
31 | 37 | assertEquals("http://www.baeldung.com/junit-5", uriComponents.toUriString()); |
32 | 38 | } |
33 | 39 |
|
34 | 40 | @Test |
35 | 41 | public void constructUriWithQueryParameter() { |
36 | | - UriComponents uriComponents = UriComponentsBuilder.newInstance().scheme("http").host("www.google.com").path("/").query("q={keyword}").buildAndExpand("baeldung"); |
| 42 | + UriComponents uriComponents = UriComponentsBuilder.newInstance() |
| 43 | + .scheme("http").host("www.google.com").path("/").query("q={keyword}") |
| 44 | + .buildAndExpand("baeldung"); |
37 | 45 |
|
38 | 46 | assertEquals("http://www.google.com/?q=baeldung", uriComponents.toUriString()); |
39 | 47 | } |
|
0 commit comments