From d80c0f751a4437eda49c3ae8b193bfeb9fc1451c Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 3 Sep 2015 15:15:38 +0100 Subject: [PATCH] Cope with different content length due to Windows line endings Windows uses \r\n for line endings whereas Unix-like platforms us \n. This causes the content length of a pretty-printed response to be longer on Windows. --- ...kMvcRestDocumentationIntegrationTests.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/spring-restdocs-mockmvc/src/test/java/org/springframework/restdocs/mockmvc/MockMvcRestDocumentationIntegrationTests.java b/spring-restdocs-mockmvc/src/test/java/org/springframework/restdocs/mockmvc/MockMvcRestDocumentationIntegrationTests.java index a40ad761..6e015cfd 100644 --- a/spring-restdocs-mockmvc/src/test/java/org/springframework/restdocs/mockmvc/MockMvcRestDocumentationIntegrationTests.java +++ b/spring-restdocs-mockmvc/src/test/java/org/springframework/restdocs/mockmvc/MockMvcRestDocumentationIntegrationTests.java @@ -265,16 +265,21 @@ public class MockMvcRestDocumentationIntegrationTests { .header("Accept", MediaType.APPLICATION_JSON_VALUE) .header("Content-Length", "13") .content("{\"a\":\"alpha\"}")))); + String prettyPrinted = String.format("{%n \"a\" : \"<>\"%n}"); assertThat( new File( "build/generated-snippets/preprocessed-request/http-request.adoc"), - is(snippet().withContents( - httpRequest(RequestMethod.GET, "/").header("Host", "localhost") - .header("b", "bravo") - .header("Content-Type", "application/json") - .header("Accept", MediaType.APPLICATION_JSON_VALUE) - .header("Content-Length", "22") - .content(String.format("{%n \"a\" : \"<>\"%n}"))))); + is(snippet() + .withContents( + httpRequest(RequestMethod.GET, "/") + .header("Host", "localhost") + .header("b", "bravo") + .header("Content-Type", "application/json") + .header("Accept", + MediaType.APPLICATION_JSON_VALUE) + .header("Content-Length", + Integer.toString(prettyPrinted.getBytes().length)) + .content(prettyPrinted)))); } @Test