UriComponentBuilder allows for multiple independent build() calls on same builder instance
Issue: SPR-11885
This commit is contained in:
@@ -664,7 +664,7 @@ final class HierarchicalUriComponents extends UriComponents {
|
|||||||
private final List<String> pathSegments;
|
private final List<String> pathSegments;
|
||||||
|
|
||||||
public PathSegmentComponent(List<String> pathSegments) {
|
public PathSegmentComponent(List<String> pathSegments) {
|
||||||
this.pathSegments = Collections.unmodifiableList(pathSegments);
|
this.pathSegments = Collections.unmodifiableList(new ArrayList<String>(pathSegments));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -23,6 +23,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|
||||||
@@ -50,6 +51,28 @@ public class UriComponentsBuilderTests {
|
|||||||
assertEquals("Invalid result URI", expected, result.toUri());
|
assertEquals("Invalid result URI", expected, result.toUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void multipleFromSameBuilder() throws URISyntaxException {
|
||||||
|
UriComponentsBuilder builder = UriComponentsBuilder.newInstance().scheme("http").host("example.com").pathSegment("foo");
|
||||||
|
UriComponents result1 = builder.build();
|
||||||
|
builder = builder.pathSegment("foo2").queryParam("bar").fragment("baz");
|
||||||
|
UriComponents result2 = builder.build();
|
||||||
|
|
||||||
|
assertEquals("http", result1.getScheme());
|
||||||
|
assertEquals("example.com", result1.getHost());
|
||||||
|
assertEquals("/foo", result1.getPath());
|
||||||
|
URI expected = new URI("http://example.com/foo");
|
||||||
|
assertEquals("Invalid result URI", expected, result1.toUri());
|
||||||
|
|
||||||
|
assertEquals("http", result2.getScheme());
|
||||||
|
assertEquals("example.com", result2.getHost());
|
||||||
|
assertEquals("/foo/foo2", result2.getPath());
|
||||||
|
assertEquals("bar", result2.getQuery());
|
||||||
|
assertEquals("baz", result2.getFragment());
|
||||||
|
expected = new URI("http://example.com/foo/foo2?bar#baz");
|
||||||
|
assertEquals("Invalid result URI", expected, result2.toUri());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fromPath() throws URISyntaxException {
|
public void fromPath() throws URISyntaxException {
|
||||||
UriComponents result = UriComponentsBuilder.fromPath("foo").queryParam("bar").fragment("baz").build();
|
UriComponents result = UriComponentsBuilder.fromPath("foo").queryParam("bar").fragment("baz").build();
|
||||||
|
|||||||
Reference in New Issue
Block a user