Skip to content

Commit

Permalink
isEqualTo -> hasToString
Browse files Browse the repository at this point in the history
  • Loading branch information
raccoonback committed Jan 5, 2025
1 parent 2e4a422 commit 4160943
Showing 1 changed file with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,151 +34,151 @@ class BeforeFilterFunctionsTests {
@Test
void setPath() {
MockHttpServletRequest servletRequest = MockMvcRequestBuilders.get("http://localhost/legacy/path")
.buildRequest(null);
.buildRequest(null);

ServerRequest request = ServerRequest.create(servletRequest, Collections.emptyList());

ServerRequest result = BeforeFilterFunctions.setPath("/new/path").apply(request);

assertThat(result.uri().toString()).isEqualTo("http://localhost/new/path");
assertThat(result.uri().toString()).hasToString("http://localhost/new/path");
}

@Test
void setEncodedPath() {
MockHttpServletRequest servletRequest = MockMvcRequestBuilders.get("http://localhost/legacy/path")
.buildRequest(null);
.buildRequest(null);

ServerRequest request = ServerRequest.create(servletRequest, Collections.emptyList());

ServerRequest result = BeforeFilterFunctions.setPath("/new/é").apply(request);

assertThat(result.uri().toString()).isEqualTo("http://localhost/new/%C3%A9");
assertThat(result.uri().toString()).hasToString("http://localhost/new/%C3%A9");
}

@Test
void setPathWithParameters() {
MockHttpServletRequest servletRequest = MockMvcRequestBuilders.get("http://localhost/legacy/path")
.queryParam("foo", "bar")
.buildRequest(null);
.queryParam("foo", "bar")
.buildRequest(null);

ServerRequest request = ServerRequest.create(servletRequest, Collections.emptyList());

ServerRequest result = BeforeFilterFunctions.setPath("/new/path").apply(request);

assertThat(result.uri().toString()).isEqualTo("http://localhost/new/path?foo=bar");
assertThat(result.uri().toString()).hasToString("http://localhost/new/path?foo=bar");
}

@Test
void setPathWithEncodedParameters() {
MockHttpServletRequest servletRequest = MockMvcRequestBuilders.get("http://localhost/legacy/path")
.queryParam("foo[]", "bar[]")
.buildRequest(null);
.queryParam("foo[]", "bar[]")
.buildRequest(null);

ServerRequest request = ServerRequest.create(servletRequest, Collections.emptyList());

ServerRequest result = BeforeFilterFunctions.setPath("/new/path").apply(request);

assertThat(result.uri().toString()).isEqualTo("http://localhost/new/path?foo%5B%5D=bar%5B%5D");
assertThat(result.uri().toString()).hasToString("http://localhost/new/path?foo%5B%5D=bar%5B%5D");
}

@Test
void removeRequestParameter() {
MockHttpServletRequest servletRequest = MockMvcRequestBuilders.get("http://localhost/path")
.queryParam("foo", "bar")
.queryParam("baz", "qux")
.buildRequest(null);
.queryParam("foo", "bar")
.queryParam("baz", "qux")
.buildRequest(null);

ServerRequest request = ServerRequest.create(servletRequest, Collections.emptyList());

ServerRequest result = BeforeFilterFunctions.removeRequestParameter("foo").apply(request);

assertThat(result.param("foo")).isEmpty();
assertThat(result.param("baz")).isPresent().hasValue("qux");
assertThat(result.uri().toString()).isEqualTo("http://localhost/path?baz=qux");
assertThat(result.uri().toString()).hasToString("http://localhost/path?baz=qux");
}

@Test
void removeEncodedRequestParameter() {
MockHttpServletRequest servletRequest = MockMvcRequestBuilders.get("http://localhost/path")
.queryParam("foo[]", "bar")
.queryParam("baz", "qux")
.buildRequest(null);
.queryParam("foo[]", "bar")
.queryParam("baz", "qux")
.buildRequest(null);

ServerRequest request = ServerRequest.create(servletRequest, Collections.emptyList());

ServerRequest result = BeforeFilterFunctions.removeRequestParameter("foo[]").apply(request);

assertThat(result.param("foo[]")).isEmpty();
assertThat(result.param("baz")).isPresent().hasValue("qux");
assertThat(result.uri().toString()).isEqualTo("http://localhost/path?baz=qux");
assertThat(result.uri().toString()).hasToString("http://localhost/path?baz=qux");
}

@Test
void removeRequestParameterWithEncodedRemainParameters() {
MockHttpServletRequest servletRequest = MockMvcRequestBuilders.get("http://localhost/path")
.queryParam("foo", "bar")
.queryParam("baz[]", "qux[]")
.buildRequest(null);
.queryParam("foo", "bar")
.queryParam("baz[]", "qux[]")
.buildRequest(null);

ServerRequest request = ServerRequest.create(servletRequest, Collections.emptyList());

ServerRequest result = BeforeFilterFunctions.removeRequestParameter("foo").apply(request);

assertThat(result.param("foo")).isEmpty();
assertThat(result.param("baz[]")).isPresent().hasValue("qux[]");
assertThat(result.uri().toString()).isEqualTo("http://localhost/path?baz%5B%5D=qux%5B%5D");
assertThat(result.uri().toString()).hasToString("http://localhost/path?baz%5B%5D=qux%5B%5D");
}

@Test
void removeRequestParameterWithEncodedPath() {
MockHttpServletRequest servletRequest = MockMvcRequestBuilders.get("http://localhost/é")
.queryParam("foo", "bar")
.buildRequest(null);
.queryParam("foo", "bar")
.buildRequest(null);

ServerRequest request = ServerRequest.create(servletRequest, Collections.emptyList());

ServerRequest result = BeforeFilterFunctions.removeRequestParameter("foo").apply(request);

assertThat(result.param("foo")).isEmpty();
assertThat(result.uri().toString()).isEqualTo("http://localhost/%C3%A9");
assertThat(result.uri().toString()).hasToString("http://localhost/%C3%A9");
}

@Test
void stripPrefix() {
MockHttpServletRequest servletRequest = MockMvcRequestBuilders.get("http://localhost/depth1/depth2/depth3")
.buildRequest(null);
.buildRequest(null);

ServerRequest request = ServerRequest.create(servletRequest, Collections.emptyList());

ServerRequest result = BeforeFilterFunctions.stripPrefix(2).apply(request);

assertThat(result.uri().toString()).isEqualTo("http://localhost/depth3");
assertThat(result.uri().toString()).hasToString("http://localhost/depth3");
}

@Test
void stripPrefixWithEncodedPath() {
MockHttpServletRequest servletRequest = MockMvcRequestBuilders.get("http://localhost/depth1/depth2/depth3/é")
.buildRequest(null);
.buildRequest(null);

ServerRequest request = ServerRequest.create(servletRequest, Collections.emptyList());

ServerRequest result = BeforeFilterFunctions.stripPrefix(2).apply(request);

assertThat(result.uri().toString()).isEqualTo("http://localhost/depth3/%C3%A9");
assertThat(result.uri().toString()).hasToString("http://localhost/depth3/%C3%A9");
}

@Test
void stripPrefixWithEncodedParameters() {
MockHttpServletRequest servletRequest = MockMvcRequestBuilders.get("http://localhost/depth1/depth2/depth3")
.queryParam("baz[]", "qux[]")
.buildRequest(null);
.queryParam("baz[]", "qux[]")
.buildRequest(null);

ServerRequest request = ServerRequest.create(servletRequest, Collections.emptyList());

ServerRequest result = BeforeFilterFunctions.stripPrefix(2).apply(request);

assertThat(result.param("baz[]")).isPresent().hasValue("qux[]");
assertThat(result.uri().toString()).isEqualTo("http://localhost/depth3?baz%5B%5D=qux%5B%5D");
assertThat(result.uri().toString()).hasToString("http://localhost/depth3?baz%5B%5D=qux%5B%5D");
}

}

0 comments on commit 4160943

Please sign in to comment.