Skip to content

Commit

Permalink
issue #493 add response test to mock response
Browse files Browse the repository at this point in the history
  • Loading branch information
ryber committed Oct 26, 2023
1 parent ef7ec0f commit f14c353
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public ExpectedResponse thenReturn(Object pojo) {

private ExpectedResponse thenReturn(MockResponse res) {
this.response = o -> res.getBody() == null ? null : String.valueOf(res.getBody());
return withStatus(res.getStatus()).withHeaders(res.getHeaders());
return withStatus(res.getStatus(), res.getStatusText())
.withHeaders(res.getHeaders());
}

public RawResponse toRawResponse(Config config, HttpRequest request) {
Expand Down
3 changes: 2 additions & 1 deletion unirest-mocks/src/test/java/kong/tests/AssertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,13 @@ void assertPostWithNoBody() {
@Test
void returnAMockResponseObject() {
client.expect(HttpMethod.POST, path)
.thenReturn(MockResponse.of(500, "error")
.thenReturn(MockResponse.of(500, "a 500 brah", "error")
.withHeader("cool", "beans"));

HttpResponse<String> response = Unirest.post(path).asString();

assertEquals(500, response.getStatus());
assertEquals("a 500 brah", response.getStatusText());
assertEquals("error", response.getBody());
assertEquals(List.of("beans"), response.getHeaders().get("cool"));
}
Expand Down

0 comments on commit f14c353

Please sign in to comment.