Fix UriComponentsBuilder examples in ref docs

Closes gh-26453
This commit is contained in:
Sam Brannen
2021-01-27 15:15:40 +01:00
parent 2d29fcd0bb
commit c5284009a1
2 changed files with 28 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
/*
* 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();