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.
This commit is contained in:
Andy Wilkinson
2015-09-03 15:15:38 +01:00
parent 51051de4c4
commit d80c0f751a

View File

@@ -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\" : \"<<beta>>\"%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\" : \"<<beta>>\"%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