When the RequestBody of a FakeRequest is set, it incorrectly uses it in the body of the ResponseBody instead of using the response body content that was specified.
For example, the following test will fail:
@Test
public void fakeRequestReturnsRequestBody() throws Exception {
MatcherAssert.assertThat(
new FakeRequest()
.withBody("foo") // Response body - should be returned
.body().set("bar").back() // Request body
.fetch().body(),
Matchers.is("foo")
);
}
Error:
java.lang.AssertionError:
Expected: is "foo"
but: was "bar"
Note that the following test - if the RequestBody is not set - works fine:
@Test
public void fakeRequestReturnsRequestBody() throws Exception {
MatcherAssert.assertThat(
new FakeRequest()
.withBody("foo")
.fetch().body(),
Matchers.is("foo")
);
}
When the
RequestBodyof aFakeRequestis set, it incorrectly uses it in the body of the ResponseBody instead of using the response body content that was specified.For example, the following test will fail:
Error:
Note that the following test - if the
RequestBodyis not set - works fine: