|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2018 the original author or authors. |
| 2 | + * Copyright 2002-2020 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.
|
|
36 | 36 | import static org.junit.Assert.*;
|
37 | 37 |
|
38 | 38 | /**
|
39 |
| - * Unit tests for {@link org.springframework.web.util.UriComponentsBuilder}. |
| 39 | + * Unit tests for {@link UriComponentsBuilder}. |
40 | 40 | *
|
41 | 41 | * @author Arjen Poutsma
|
42 | 42 | * @author Phillip Webb
|
@@ -557,7 +557,7 @@ public void pathSegmentsSomeEmpty() {
|
557 | 557 | }
|
558 | 558 |
|
559 | 559 | @Test // SPR-12398
|
560 |
| - public void pathWithDuplicateSlashes() throws URISyntaxException { |
| 560 | + public void pathWithDuplicateSlashes() { |
561 | 561 | UriComponents uriComponents = UriComponentsBuilder.fromPath("/foo/////////bar").build();
|
562 | 562 | assertEquals("/foo/bar", uriComponents.getPath());
|
563 | 563 | }
|
@@ -727,26 +727,28 @@ public void parsesEmptyUri() {
|
727 | 727 | assertThat(components.toString(), equalTo(""));
|
728 | 728 | }
|
729 | 729 |
|
730 |
| - @Test |
731 |
| - public void testClone() throws URISyntaxException { |
| 730 | + @Test // gh-25243 |
| 731 | + public void testCloneAndMerge() { |
732 | 732 | UriComponentsBuilder builder1 = UriComponentsBuilder.newInstance();
|
733 |
| - builder1.scheme("http").host("e1.com").path("/p1").pathSegment("ps1").queryParam("q1").fragment("f1"); |
| 733 | + builder1.scheme("http").host("e1.com").path("/p1").pathSegment("ps1").queryParam("q1", "x").fragment("f1"); |
734 | 734 |
|
735 |
| - UriComponentsBuilder builder2 = (UriComponentsBuilder) builder1.clone(); |
| 735 | + UriComponentsBuilder builder2 = builder1.cloneBuilder(); |
736 | 736 | builder2.scheme("https").host("e2.com").path("p2").pathSegment("ps2").queryParam("q2").fragment("f2");
|
737 | 737 |
|
| 738 | + builder1.queryParam("q1", "y"); // one more entry for an existing parameter |
| 739 | + |
738 | 740 | UriComponents result1 = builder1.build();
|
739 | 741 | assertEquals("http", result1.getScheme());
|
740 | 742 | assertEquals("e1.com", result1.getHost());
|
741 | 743 | assertEquals("/p1/ps1", result1.getPath());
|
742 |
| - assertEquals("q1", result1.getQuery()); |
| 744 | + assertEquals("q1=x&q1=y", result1.getQuery()); |
743 | 745 | assertEquals("f1", result1.getFragment());
|
744 | 746 |
|
745 |
| - UriComponents result2 = builder2.build(); |
| 747 | + UriComponents result2 = builder2.buildAndExpand("ps2;a"); |
746 | 748 | assertEquals("https", result2.getScheme());
|
747 | 749 | assertEquals("e2.com", result2.getHost());
|
748 | 750 | assertEquals("/p1/ps1/p2/ps2", result2.getPath());
|
749 |
| - assertEquals("q1&q2", result2.getQuery()); |
| 751 | + assertEquals("q1=x&q2", result2.getQuery()); |
750 | 752 | assertEquals("f2", result2.getFragment());
|
751 | 753 | }
|
752 | 754 |
|
|
0 commit comments