Merge branch '5.3.x'
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,10 +22,12 @@ import jakarta.servlet.http.Cookie;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.result.PrintingResultHandler;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
@@ -60,6 +62,22 @@ class PrintingResultHandlerIntegrationTests {
|
||||
.contains("Headers = [Set-Cookie:\"enigma=42\", Content-Type:\"text/plain;charset=ISO-8859-1\", Content-Length:\"14\"]");
|
||||
}
|
||||
|
||||
@Test
|
||||
void printMvcResultsToWriterWithJsonResponseBodyInterpretedAsUtf8() throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
standaloneSetup(new SimpleController()).build()
|
||||
// "Hallöchen" is German slang for "hello".
|
||||
.perform(get("/utf8").accept(MediaType.APPLICATION_JSON).content("Hallöchen, Welt!".getBytes()).characterEncoding(UTF_8))
|
||||
.andDo(print(writer))
|
||||
// "Grüß dich!" is German for "greetings to you".
|
||||
.andExpect(content().bytes("Grüß dich!".getBytes()));
|
||||
|
||||
assertThat(writer).asString()
|
||||
.contains("Body = Hallöchen, Welt!")
|
||||
.contains("Body = Grüß dich!");
|
||||
}
|
||||
|
||||
@Test
|
||||
void printMvcResultsToWriterWithFailingGlobalResultMatcher() throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
@@ -91,6 +109,11 @@ class PrintingResultHandlerIntegrationTests {
|
||||
response.addCookie(new Cookie("enigma", "42"));
|
||||
return "Hello Response";
|
||||
}
|
||||
|
||||
@GetMapping("/utf8")
|
||||
String utf8(HttpServletResponse response) {
|
||||
return "Grüß dich!";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user