@Test // SPR-8867 public void writeOverrideRequestedContentType() throws IOException { String body = "H\u00e9llo W\u00f6rld"; MediaType requestedContentType = new MediaType("text", "html"); HttpHeaders headers = this.outputMessage.getHeaders(); headers.setContentType(TEXT_PLAIN_UTF_8); this.converter.write(body, requestedContentType, this.outputMessage); assertEquals(body, this.outputMessage.getBodyAsString(StandardCharsets.UTF_8)); assertEquals(TEXT_PLAIN_UTF_8, headers.getContentType()); assertEquals(body.getBytes(StandardCharsets.UTF_8).length, headers.getContentLength()); assertFalse(headers.getAcceptCharset().isEmpty()); }
@Test public void writeUTF8() throws IOException { String body = "H\u00e9llo W\u00f6rld"; this.converter.write(body, TEXT_PLAIN_UTF_8, this.outputMessage); HttpHeaders headers = this.outputMessage.getHeaders(); assertEquals(body, this.outputMessage.getBodyAsString(StandardCharsets.UTF_8)); assertEquals(TEXT_PLAIN_UTF_8, headers.getContentType()); assertEquals(body.getBytes(StandardCharsets.UTF_8).length, headers.getContentLength()); assertFalse(headers.getAcceptCharset().isEmpty()); }
@Test public void writeDefaultCharset() throws IOException { String body = "H\u00e9llo W\u00f6rld"; this.converter.write(body, null, this.outputMessage); HttpHeaders headers = this.outputMessage.getHeaders(); assertEquals(body, this.outputMessage.getBodyAsString(StandardCharsets.ISO_8859_1)); assertEquals(new MediaType("text", "plain", StandardCharsets.ISO_8859_1), headers.getContentType()); assertEquals(body.getBytes(StandardCharsets.ISO_8859_1).length, headers.getContentLength()); assertFalse(headers.getAcceptCharset().isEmpty()); }