Ensure characterEncoding in MockHttpServletResponse is non-null

Closes gh-27219
This commit is contained in:
Sam Brannen
2021-07-28 16:08:28 +02:00
parent 915f1027a5
commit 96ee8a3bc7
5 changed files with 53 additions and 58 deletions

View File

@@ -551,6 +551,8 @@ class MockHttpServletResponseTests {
@Test // gh-25501
void resetResetsCharset() {
assertThat(response.getContentType()).isNull();
assertThat(response.getCharacterEncoding()).isEqualTo("ISO-8859-1");
assertThat(response.isCharset()).isFalse();
response.setCharacterEncoding("UTF-8");
assertThat(response.isCharset()).isTrue();
@@ -562,6 +564,8 @@ class MockHttpServletResponseTests {
response.reset();
assertThat(response.getContentType()).isNull();
assertThat(response.getCharacterEncoding()).isEqualTo("ISO-8859-1");
assertThat(response.isCharset()).isFalse();
// Do not invoke setCharacterEncoding() since that sets the charset flag to true.
// response.setCharacterEncoding("UTF-8");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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.
@@ -238,16 +238,6 @@ public class PrintingResultHandlerTests {
assertValue("MockHttpServletResponse", "Body", "text");
}
@Test
public void printResponseWithoutCharacterEncoding() throws Exception {
this.response.setCharacterEncoding(null);
this.response.getWriter().print("text");
this.handler.handle(this.mvcResult);
assertValue("MockHttpServletResponse", "Body", "<no character encoding set>");
}
@Test
public void printHandlerNull() throws Exception {
StubMvcResult mvcResult = new StubMvcResult(this.request, null, null, null, null, null, this.response);