SPR-7667
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3779 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
747c192d5c
commit
19224cac2b
|
|
@ -96,7 +96,7 @@ public class UriTemplate implements Serializable {
|
||||||
*/
|
*/
|
||||||
public URI expand(Map<String, ?> uriVariables) {
|
public URI expand(Map<String, ?> uriVariables) {
|
||||||
Assert.notNull(uriVariables, "'uriVariables' must not be null");
|
Assert.notNull(uriVariables, "'uriVariables' must not be null");
|
||||||
Object[] values = new String[this.variableNames.size()];
|
Object[] values = new Object[this.variableNames.size()];
|
||||||
for (int i = 0; i < this.variableNames.size(); i++) {
|
for (int i = 0; i < this.variableNames.size(); i++) {
|
||||||
String name = this.variableNames.get(i);
|
String name = this.variableNames.get(i);
|
||||||
if (!uriVariables.containsKey(name)) {
|
if (!uriVariables.containsKey(name)) {
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,16 @@ public class UriTemplateTests {
|
||||||
assertEquals("Invalid expanded template", new URI("http://example.com/hotels/1/bookings/42"), result);
|
assertEquals("Invalid expanded template", new URI("http://example.com/hotels/1/bookings/42"), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void expandMapNonString() throws Exception {
|
||||||
|
Map<String, Integer> uriVariables = new HashMap<String, Integer>(2);
|
||||||
|
uriVariables.put("booking", 42);
|
||||||
|
uriVariables.put("hotel", 1);
|
||||||
|
UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
|
||||||
|
URI result = template.expand(uriVariables);
|
||||||
|
assertEquals("Invalid expanded template", new URI("http://example.com/hotels/1/bookings/42"), result);
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void expandMapInvalidAmountVariables() throws Exception {
|
public void expandMapInvalidAmountVariables() throws Exception {
|
||||||
UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
|
UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue