diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java index 7e22d70d4fb..6bde5487b89 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -193,7 +193,8 @@ public class MockHttpServletResponse implements HttpServletResponse { Assert.state(this.writerAccessAllowed, "Writer access not allowed"); if (this.writer == null) { Writer targetWriter = (this.characterEncoding != null ? - new OutputStreamWriter(this.content, this.characterEncoding) : new OutputStreamWriter(this.content)); + new OutputStreamWriter(this.content, this.characterEncoding) : + new OutputStreamWriter(this.content)); this.writer = new ResponsePrintWriter(targetWriter); } return this.writer; diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java index 7f248e90931..d9f3488d0a8 100644 --- a/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java +++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -168,11 +168,11 @@ public class MockHttpServletResponse implements HttpServletResponse { private void updateContentTypeHeader() { if (this.contentType != null) { - StringBuilder sb = new StringBuilder(this.contentType); - if (!this.contentType.toLowerCase().contains(CHARSET_PREFIX) && this.charset) { - sb.append(";").append(CHARSET_PREFIX).append(this.characterEncoding); + String value = this.contentType; + if (this.charset && !this.contentType.toLowerCase().contains(CHARSET_PREFIX)) { + value = value + ';' + CHARSET_PREFIX + this.characterEncoding; } - doAddHeaderValue(HttpHeaders.CONTENT_TYPE, sb.toString(), true); + doAddHeaderValue(HttpHeaders.CONTENT_TYPE, value, true); } } @@ -193,7 +193,8 @@ public class MockHttpServletResponse implements HttpServletResponse { Assert.state(this.writerAccessAllowed, "Writer access not allowed"); if (this.writer == null) { Writer targetWriter = (this.characterEncoding != null ? - new OutputStreamWriter(this.content, this.characterEncoding) : new OutputStreamWriter(this.content)); + new OutputStreamWriter(this.content, this.characterEncoding) : + new OutputStreamWriter(this.content)); this.writer = new ResponsePrintWriter(targetWriter); } return this.writer;