Skip to content

Commit c528400

Browse files
committed
Fix UriComponentsBuilder examples in ref docs
Closes gh-26453
1 parent 2d29fcd commit c528400

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,6 +51,27 @@
5151
*/
5252
class UriComponentsBuilderTests {
5353

54+
@Test // see gh-26453
55+
void examplesInReferenceManual() {
56+
final String expected = "/hotel%20list/New%20York?q=foo%2Bbar";
57+
58+
URI uri = UriComponentsBuilder.fromPath("/hotel list/{city}")
59+
.queryParam("q", "{q}")
60+
.encode()
61+
.buildAndExpand("New York", "foo+bar")
62+
.toUri();
63+
assertThat(uri).asString().isEqualTo(expected);
64+
65+
uri = UriComponentsBuilder.fromPath("/hotel list/{city}")
66+
.queryParam("q", "{q}")
67+
.build("New York", "foo+bar");
68+
assertThat(uri).asString().isEqualTo(expected);
69+
70+
uri = UriComponentsBuilder.fromUriString("/hotel list/{city}?q={q}")
71+
.build("New York", "foo+bar");
72+
assertThat(uri).asString().isEqualTo(expected);
73+
}
74+
5475
@Test
5576
void plain() throws URISyntaxException {
5677
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();

src/docs/asciidoc/web/web-uris.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ as the following example shows:
8282
.build("Westin", "123")
8383
----
8484

85-
You shorter it further still with a full URI template, as the following example shows:
85+
You can shorten it further still with a full URI template, as the following example shows:
8686

8787
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
8888
.Java
@@ -94,7 +94,7 @@ You shorter it further still with a full URI template, as the following example
9494
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
9595
.Kotlin
9696
----
97-
val uri = UriComponentsBuilder
97+
val uri = UriComponentsBuilder
9898
.fromUriString("https://example.com/hotels/{hotel}?q={q}")
9999
.build("Westin", "123")
100100
----
@@ -250,7 +250,7 @@ as the following example shows:
250250
----
251251
URI uri = UriComponentsBuilder.fromPath("/hotel list/{city}")
252252
.queryParam("q", "{q}")
253-
.build("New York", "foo+bar")
253+
.build("New York", "foo+bar");
254254
----
255255
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
256256
.Kotlin
@@ -265,13 +265,13 @@ You can shorten it further still with a full URI template, as the following exam
265265
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
266266
.Java
267267
----
268-
URI uri = UriComponentsBuilder.fromPath("/hotel list/{city}?q={q}")
269-
.build("New York", "foo+bar")
268+
URI uri = UriComponentsBuilder.fromUriString("/hotel list/{city}?q={q}")
269+
.build("New York", "foo+bar");
270270
----
271271
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
272272
.Kotlin
273273
----
274-
val uri = UriComponentsBuilder.fromPath("/hotel list/{city}?q={q}")
274+
val uri = UriComponentsBuilder.fromUriString("/hotel list/{city}?q={q}")
275275
.build("New York", "foo+bar")
276276
----
277277

0 commit comments

Comments
 (0)