From f14c35343d056ef55a918c0cc1068785f5111012 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Thu, 26 Oct 2023 07:49:33 -0500 Subject: [PATCH] issue #493 add response test to mock response --- .../main/java/kong/unirest/core/ExpectedResponseRecord.java | 3 ++- unirest-mocks/src/test/java/kong/tests/AssertTest.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/unirest-mocks/src/main/java/kong/unirest/core/ExpectedResponseRecord.java b/unirest-mocks/src/main/java/kong/unirest/core/ExpectedResponseRecord.java index db4706fd..1e269deb 100644 --- a/unirest-mocks/src/main/java/kong/unirest/core/ExpectedResponseRecord.java +++ b/unirest-mocks/src/main/java/kong/unirest/core/ExpectedResponseRecord.java @@ -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) { diff --git a/unirest-mocks/src/test/java/kong/tests/AssertTest.java b/unirest-mocks/src/test/java/kong/tests/AssertTest.java index 562616f8..c58814d6 100644 --- a/unirest-mocks/src/test/java/kong/tests/AssertTest.java +++ b/unirest-mocks/src/test/java/kong/tests/AssertTest.java @@ -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 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")); }