diff --git a/modules/spring-mock-mvc/src/test/java/io/restassured/module/mockmvc/RequestLoggingTest.java b/modules/spring-mock-mvc/src/test/java/io/restassured/module/mockmvc/RequestLoggingTest.java index 7bd4d4183..3921a207f 100644 --- a/modules/spring-mock-mvc/src/test/java/io/restassured/module/mockmvc/RequestLoggingTest.java +++ b/modules/spring-mock-mvc/src/test/java/io/restassured/module/mockmvc/RequestLoggingTest.java @@ -33,6 +33,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.emptyString; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.fail; // @formatter:off @@ -150,6 +151,31 @@ public class RequestLoggingTest { "a string%n"))); } + @Test public void + can_supply_byte_array_as_body_for_post() { + RestAssuredMockMvc.given(). + standaloneSetup(new PostController()). + log().all(false). + body(new byte[] {'B', 'O', 'D', 'Y'}). + when(). + post("/stringBody"). + then(). + body(equalTo("BODY")); + + assertThat(writer.toString(), startsWith(String.format("Request method:\tPOST%n" + + "Request URI:\thttp://localhost:8080/stringBody%n" + + "Proxy:\t\t\t%n" + + "Request params:\t%n" + + "Query params:\t%n" + + "Form params:\t%n" + + "Path params:\t%n" + + "Headers:\t\t%n" + + "Cookies:\t\t%n" + + "Multiparts:\t\t%n" + + "Body:%n" + + "[B@"))); + } + @Test public void base_path_is_prepended_to_path_when_logging() { RestAssuredMockMvc.basePath = "/my-path"; diff --git a/rest-assured/src/main/java/io/restassured/internal/print/RequestPrinter.java b/rest-assured/src/main/java/io/restassured/internal/print/RequestPrinter.java index eb5f3ee30..abe22607f 100644 --- a/rest-assured/src/main/java/io/restassured/internal/print/RequestPrinter.java +++ b/rest-assured/src/main/java/io/restassured/internal/print/RequestPrinter.java @@ -103,7 +103,8 @@ private static void addProxy(FilterableRequestSpecification requestSpec, StringB private static void addBody(FilterableRequestSpecification requestSpec, StringBuilder builder, boolean shouldPrettyPrint) { builder.append("Body:"); if (requestSpec.getBody() != null) { - final String body; + // Note: requestSpec.getBody() below is generic and may not always return a String! + final Object body; if (shouldPrettyPrint) { body = new Prettifier().getPrettifiedBodyIfPossible(requestSpec); } else {