提交 c5284009 编写于 作者: S Sam Brannen

Fix UriComponentsBuilder examples in ref docs

Closes gh-26453
上级 2d29fcd0
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -51,6 +51,27 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
*/
class UriComponentsBuilderTests {
@Test // see gh-26453
void examplesInReferenceManual() {
final String expected = "/hotel%20list/New%20York?q=foo%2Bbar";
URI uri = UriComponentsBuilder.fromPath("/hotel list/{city}")
.queryParam("q", "{q}")
.encode()
.buildAndExpand("New York", "foo+bar")
.toUri();
assertThat(uri).asString().isEqualTo(expected);
uri = UriComponentsBuilder.fromPath("/hotel list/{city}")
.queryParam("q", "{q}")
.build("New York", "foo+bar");
assertThat(uri).asString().isEqualTo(expected);
uri = UriComponentsBuilder.fromUriString("/hotel list/{city}?q={q}")
.build("New York", "foo+bar");
assertThat(uri).asString().isEqualTo(expected);
}
@Test
void plain() throws URISyntaxException {
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
......
......@@ -82,7 +82,7 @@ as the following example shows:
.build("Westin", "123")
----
You shorter it further still with a full URI template, as the following example shows:
You can shorten it further still with a full URI template, as the following example shows:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
......@@ -94,7 +94,7 @@ You shorter it further still with a full URI template, as the following example
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
val uri = UriComponentsBuilder
val uri = UriComponentsBuilder
.fromUriString("https://example.com/hotels/{hotel}?q={q}")
.build("Westin", "123")
----
......@@ -250,7 +250,7 @@ as the following example shows:
----
URI uri = UriComponentsBuilder.fromPath("/hotel list/{city}")
.queryParam("q", "{q}")
.build("New York", "foo+bar")
.build("New York", "foo+bar");
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
......@@ -265,13 +265,13 @@ You can shorten it further still with a full URI template, as the following exam
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
----
URI uri = UriComponentsBuilder.fromPath("/hotel list/{city}?q={q}")
.build("New York", "foo+bar")
URI uri = UriComponentsBuilder.fromUriString("/hotel list/{city}?q={q}")
.build("New York", "foo+bar");
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
val uri = UriComponentsBuilder.fromPath("/hotel list/{city}?q={q}")
val uri = UriComponentsBuilder.fromUriString("/hotel list/{city}?q={q}")
.build("New York", "foo+bar")
----
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册