Skip to content

FakeRequest incorrectly uses request body as response body #47

@carlosmiranda

Description

@carlosmiranda

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")
    );
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions