Replace remaining use of StringBuffer with StringBuilder
Although this commit only applies to test classes, it serves to reduce the noise when searching for undesirable usage of StringBuffer in production code.
This commit is contained in:
parent
3e14cdbc69
commit
03668f9c10
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -322,7 +322,7 @@ abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
int b = 12;
|
int b = 12;
|
||||||
int c = 25;
|
int c = 25;
|
||||||
String d = "d";
|
String d = "d";
|
||||||
StringBuffer e = new StringBuffer("stringbuf");
|
StringBuilder e = new StringBuilder("stringbuf");
|
||||||
String expectedResult = a + b+ c + d + e;
|
String expectedResult = a + b+ c + d + e;
|
||||||
assertThat(mva.mungeArgs(a, b, c, d, e)).isEqualTo(expectedResult);
|
assertThat(mva.mungeArgs(a, b, c, d, e)).isEqualTo(expectedResult);
|
||||||
}
|
}
|
||||||
|
@ -728,12 +728,12 @@ abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
@Aspect
|
@Aspect
|
||||||
static class ManyValuedArgs {
|
static class ManyValuedArgs {
|
||||||
|
|
||||||
String mungeArgs(String a, int b, int c, String d, StringBuffer e) {
|
String mungeArgs(String a, int b, int c, String d, StringBuilder e) {
|
||||||
return a + b + c + d + e;
|
return a + b + c + d + e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Around(value="execution(String mungeArgs(..)) && args(a, b, c, d, e)", argNames="b,c,d,e,a")
|
@Around(value="execution(String mungeArgs(..)) && args(a, b, c, d, e)", argNames="b,c,d,e,a")
|
||||||
String reverseAdvice(ProceedingJoinPoint pjp, int b, int c, String d, StringBuffer e, String a) throws Throwable {
|
String reverseAdvice(ProceedingJoinPoint pjp, int b, int c, String d, StringBuilder e, String a) throws Throwable {
|
||||||
assertThat(pjp.proceed()).isEqualTo(a + b+ c+ d+ e);
|
assertThat(pjp.proceed()).isEqualTo(a + b+ c+ d+ e);
|
||||||
return a + b + c + d + e;
|
return a + b + c + d + e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -54,10 +54,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
class DirtiesContextWithContextHierarchyTests {
|
class DirtiesContextWithContextHierarchyTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private StringBuffer foo;
|
private StringBuilder foo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private StringBuffer baz;
|
private StringBuilder baz;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationContext context;
|
private ApplicationContext context;
|
||||||
|
@ -74,7 +74,7 @@ class DirtiesContextWithContextHierarchyTests {
|
||||||
@Order(1)
|
@Order(1)
|
||||||
void verifyOriginalStateAndDirtyContexts() {
|
void verifyOriginalStateAndDirtyContexts() {
|
||||||
assertOriginalState();
|
assertOriginalState();
|
||||||
reverseStringBuffers();
|
reverseStringBuilders();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -90,7 +90,7 @@ class DirtiesContextWithContextHierarchyTests {
|
||||||
@DirtiesContext(hierarchyMode = HierarchyMode.CURRENT_LEVEL)
|
@DirtiesContext(hierarchyMode = HierarchyMode.CURRENT_LEVEL)
|
||||||
void verifyOriginalStateWasReinstatedAndDirtyContextsAndTriggerCurrentLevelCacheClearing() {
|
void verifyOriginalStateWasReinstatedAndDirtyContextsAndTriggerCurrentLevelCacheClearing() {
|
||||||
assertOriginalState();
|
assertOriginalState();
|
||||||
reverseStringBuffers();
|
reverseStringBuilders();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -100,7 +100,7 @@ class DirtiesContextWithContextHierarchyTests {
|
||||||
assertCleanChildContext();
|
assertCleanChildContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reverseStringBuffers() {
|
private void reverseStringBuilders() {
|
||||||
foo.reverse();
|
foo.reverse();
|
||||||
baz.reverse();
|
baz.reverse();
|
||||||
}
|
}
|
||||||
|
@ -131,13 +131,13 @@ class DirtiesContextWithContextHierarchyTests {
|
||||||
static class ParentConfig {
|
static class ParentConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
StringBuffer foo() {
|
StringBuilder foo() {
|
||||||
return new StringBuffer("foo");
|
return new StringBuilder("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
StringBuffer baz() {
|
StringBuilder baz() {
|
||||||
return new StringBuffer("baz-parent");
|
return new StringBuilder("baz-parent");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,8 +145,8 @@ class DirtiesContextWithContextHierarchyTests {
|
||||||
static class ChildConfig {
|
static class ChildConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
StringBuffer baz() {
|
StringBuilder baz() {
|
||||||
return new StringBuffer("baz-child");
|
return new StringBuilder("baz-child");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ class ContextLoaderTests {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void contextLoaderListenerWithCustomizedContextLoader() {
|
void contextLoaderListenerWithCustomizedContextLoader() {
|
||||||
final StringBuffer buffer = new StringBuffer();
|
final StringBuilder builder = new StringBuilder();
|
||||||
final String expectedContents = "customizeContext() was called";
|
final String expectedContents = "customizeContext() was called";
|
||||||
final MockServletContext sc = new MockServletContext("");
|
final MockServletContext sc = new MockServletContext("");
|
||||||
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
|
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
|
||||||
|
@ -107,11 +107,11 @@ class ContextLoaderTests {
|
||||||
assertThat(sc).as("The ServletContext should not be null.").isNotNull();
|
assertThat(sc).as("The ServletContext should not be null.").isNotNull();
|
||||||
assertThat(sc).as("Verifying that we received the expected ServletContext.").isEqualTo(sc);
|
assertThat(sc).as("Verifying that we received the expected ServletContext.").isEqualTo(sc);
|
||||||
assertThat(wac.isActive()).as("The ApplicationContext should not yet have been refreshed.").isFalse();
|
assertThat(wac.isActive()).as("The ApplicationContext should not yet have been refreshed.").isFalse();
|
||||||
buffer.append(expectedContents);
|
builder.append(expectedContents);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
listener.contextInitialized(new ServletContextEvent(sc));
|
listener.contextInitialized(new ServletContextEvent(sc));
|
||||||
assertThat(buffer.toString()).as("customizeContext() should have been called.").isEqualTo(expectedContents);
|
assertThat(builder.toString()).as("customizeContext() should have been called.").isEqualTo(expectedContents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -131,7 +131,7 @@ class HtmlEscapeTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void escapeBody() throws JspException {
|
void escapeBody() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer result = new StringBuffer();
|
final StringBuilder result = new StringBuilder();
|
||||||
EscapeBodyTag tag = new EscapeBodyTag() {
|
EscapeBodyTag tag = new EscapeBodyTag() {
|
||||||
@Override
|
@Override
|
||||||
protected String readBodyContent() {
|
protected String readBodyContent() {
|
||||||
|
@ -151,7 +151,7 @@ class HtmlEscapeTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void escapeBodyWithHtmlEscape() throws JspException {
|
void escapeBodyWithHtmlEscape() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer result = new StringBuffer();
|
final StringBuilder result = new StringBuilder();
|
||||||
EscapeBodyTag tag = new EscapeBodyTag() {
|
EscapeBodyTag tag = new EscapeBodyTag() {
|
||||||
@Override
|
@Override
|
||||||
protected String readBodyContent() {
|
protected String readBodyContent() {
|
||||||
|
@ -172,7 +172,7 @@ class HtmlEscapeTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void escapeBodyWithJavaScriptEscape() throws JspException {
|
void escapeBodyWithJavaScriptEscape() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer result = new StringBuffer();
|
final StringBuilder result = new StringBuilder();
|
||||||
EscapeBodyTag tag = new EscapeBodyTag() {
|
EscapeBodyTag tag = new EscapeBodyTag() {
|
||||||
@Override
|
@Override
|
||||||
protected String readBodyContent() {
|
protected String readBodyContent() {
|
||||||
|
@ -193,7 +193,7 @@ class HtmlEscapeTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void escapeBodyWithHtmlEscapeAndJavaScriptEscape() throws JspException {
|
void escapeBodyWithHtmlEscapeAndJavaScriptEscape() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer result = new StringBuffer();
|
final StringBuilder result = new StringBuilder();
|
||||||
EscapeBodyTag tag = new EscapeBodyTag() {
|
EscapeBodyTag tag = new EscapeBodyTag() {
|
||||||
@Override
|
@Override
|
||||||
protected String readBodyContent() {
|
protected String readBodyContent() {
|
||||||
|
|
|
@ -49,7 +49,7 @@ class MessageTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void messageTagWithMessageSourceResolvable() throws JspException {
|
void messageTagWithMessageSourceResolvable() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer message = new StringBuffer();
|
final StringBuilder message = new StringBuilder();
|
||||||
MessageTag tag = new MessageTag() {
|
MessageTag tag = new MessageTag() {
|
||||||
@Override
|
@Override
|
||||||
protected void writeMessage(String msg) {
|
protected void writeMessage(String msg) {
|
||||||
|
@ -66,7 +66,7 @@ class MessageTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void messageTagWithCode() throws JspException {
|
void messageTagWithCode() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer message = new StringBuffer();
|
final StringBuilder message = new StringBuilder();
|
||||||
MessageTag tag = new MessageTag() {
|
MessageTag tag = new MessageTag() {
|
||||||
@Override
|
@Override
|
||||||
protected void writeMessage(String msg) {
|
protected void writeMessage(String msg) {
|
||||||
|
@ -83,7 +83,7 @@ class MessageTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void messageTagWithCodeAndArgument() throws JspException {
|
void messageTagWithCodeAndArgument() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer message = new StringBuffer();
|
final StringBuilder message = new StringBuilder();
|
||||||
MessageTag tag = new MessageTag() {
|
MessageTag tag = new MessageTag() {
|
||||||
@Override
|
@Override
|
||||||
protected void writeMessage(String msg) {
|
protected void writeMessage(String msg) {
|
||||||
|
@ -101,7 +101,7 @@ class MessageTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void messageTagWithCodeAndArguments() throws JspException {
|
void messageTagWithCodeAndArguments() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer message = new StringBuffer();
|
final StringBuilder message = new StringBuilder();
|
||||||
MessageTag tag = new MessageTag() {
|
MessageTag tag = new MessageTag() {
|
||||||
@Override
|
@Override
|
||||||
protected void writeMessage(String msg) {
|
protected void writeMessage(String msg) {
|
||||||
|
@ -119,7 +119,7 @@ class MessageTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void messageTagWithCodeAndStringArgumentWithCustomSeparator() throws JspException {
|
void messageTagWithCodeAndStringArgumentWithCustomSeparator() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer message = new StringBuffer();
|
final StringBuilder message = new StringBuilder();
|
||||||
MessageTag tag = new MessageTag() {
|
MessageTag tag = new MessageTag() {
|
||||||
@Override
|
@Override
|
||||||
protected void writeMessage(String msg) {
|
protected void writeMessage(String msg) {
|
||||||
|
@ -138,7 +138,7 @@ class MessageTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void messageTagWithCodeAndArrayArgument() throws JspException {
|
void messageTagWithCodeAndArrayArgument() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer message = new StringBuffer();
|
final StringBuilder message = new StringBuilder();
|
||||||
MessageTag tag = new MessageTag() {
|
MessageTag tag = new MessageTag() {
|
||||||
@Override
|
@Override
|
||||||
protected void writeMessage(String msg) {
|
protected void writeMessage(String msg) {
|
||||||
|
@ -156,7 +156,7 @@ class MessageTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void messageTagWithCodeAndObjectArgument() throws JspException {
|
void messageTagWithCodeAndObjectArgument() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer message = new StringBuffer();
|
final StringBuilder message = new StringBuilder();
|
||||||
MessageTag tag = new MessageTag() {
|
MessageTag tag = new MessageTag() {
|
||||||
@Override
|
@Override
|
||||||
protected void writeMessage(String msg) {
|
protected void writeMessage(String msg) {
|
||||||
|
@ -174,7 +174,7 @@ class MessageTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void messageTagWithCodeAndArgumentAndNestedArgument() throws JspException {
|
void messageTagWithCodeAndArgumentAndNestedArgument() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer message = new StringBuffer();
|
final StringBuilder message = new StringBuilder();
|
||||||
MessageTag tag = new MessageTag() {
|
MessageTag tag = new MessageTag() {
|
||||||
@Override
|
@Override
|
||||||
protected void writeMessage(String msg) {
|
protected void writeMessage(String msg) {
|
||||||
|
@ -193,7 +193,7 @@ class MessageTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void messageTagWithCodeAndNestedArgument() throws JspException {
|
void messageTagWithCodeAndNestedArgument() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer message = new StringBuffer();
|
final StringBuilder message = new StringBuilder();
|
||||||
MessageTag tag = new MessageTag() {
|
MessageTag tag = new MessageTag() {
|
||||||
@Override
|
@Override
|
||||||
protected void writeMessage(String msg) {
|
protected void writeMessage(String msg) {
|
||||||
|
@ -211,7 +211,7 @@ class MessageTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void messageTagWithCodeAndNestedArguments() throws JspException {
|
void messageTagWithCodeAndNestedArguments() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer message = new StringBuffer();
|
final StringBuilder message = new StringBuilder();
|
||||||
MessageTag tag = new MessageTag() {
|
MessageTag tag = new MessageTag() {
|
||||||
@Override
|
@Override
|
||||||
protected void writeMessage(String msg) {
|
protected void writeMessage(String msg) {
|
||||||
|
@ -230,7 +230,7 @@ class MessageTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void messageTagWithCodeAndText() throws JspException {
|
void messageTagWithCodeAndText() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer message = new StringBuffer();
|
final StringBuilder message = new StringBuilder();
|
||||||
MessageTag tag = new MessageTag() {
|
MessageTag tag = new MessageTag() {
|
||||||
@Override
|
@Override
|
||||||
protected void writeMessage(String msg) {
|
protected void writeMessage(String msg) {
|
||||||
|
@ -248,7 +248,7 @@ class MessageTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void messageTagWithText() throws JspException {
|
void messageTagWithText() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer message = new StringBuffer();
|
final StringBuilder message = new StringBuilder();
|
||||||
MessageTag tag = new MessageTag() {
|
MessageTag tag = new MessageTag() {
|
||||||
@Override
|
@Override
|
||||||
protected void writeMessage(String msg) {
|
protected void writeMessage(String msg) {
|
||||||
|
@ -268,7 +268,7 @@ class MessageTagTests extends AbstractTagTests {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
pc.getServletContext().setInitParameter(WebUtils.RESPONSE_ENCODED_HTML_ESCAPE_CONTEXT_PARAM, "true");
|
pc.getServletContext().setInitParameter(WebUtils.RESPONSE_ENCODED_HTML_ESCAPE_CONTEXT_PARAM, "true");
|
||||||
pc.getResponse().setCharacterEncoding("UTF-8");
|
pc.getResponse().setCharacterEncoding("UTF-8");
|
||||||
final StringBuffer message = new StringBuffer();
|
final StringBuilder message = new StringBuilder();
|
||||||
MessageTag tag = new MessageTag() {
|
MessageTag tag = new MessageTag() {
|
||||||
@Override
|
@Override
|
||||||
protected void writeMessage(String msg) {
|
protected void writeMessage(String msg) {
|
||||||
|
@ -286,7 +286,7 @@ class MessageTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void messageTagWithTextAndJavaScriptEscape() throws JspException {
|
void messageTagWithTextAndJavaScriptEscape() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer message = new StringBuffer();
|
final StringBuilder message = new StringBuilder();
|
||||||
MessageTag tag = new MessageTag() {
|
MessageTag tag = new MessageTag() {
|
||||||
@Override
|
@Override
|
||||||
protected void writeMessage(String msg) {
|
protected void writeMessage(String msg) {
|
||||||
|
@ -304,7 +304,7 @@ class MessageTagTests extends AbstractTagTests {
|
||||||
@Test
|
@Test
|
||||||
void messageTagWithTextAndHtmlEscapeAndJavaScriptEscape() throws JspException {
|
void messageTagWithTextAndHtmlEscapeAndJavaScriptEscape() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer message = new StringBuffer();
|
final StringBuilder message = new StringBuilder();
|
||||||
MessageTag tag = new MessageTag() {
|
MessageTag tag = new MessageTag() {
|
||||||
@Override
|
@Override
|
||||||
protected void writeMessage(String msg) {
|
protected void writeMessage(String msg) {
|
||||||
|
|
|
@ -43,7 +43,7 @@ class ThemeTagTests extends AbstractTagTests {
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
void themeTag() throws JspException {
|
void themeTag() throws JspException {
|
||||||
PageContext pc = createPageContext();
|
PageContext pc = createPageContext();
|
||||||
final StringBuffer message = new StringBuffer();
|
final StringBuilder message = new StringBuilder();
|
||||||
ThemeTag tag = new ThemeTag() {
|
ThemeTag tag = new ThemeTag() {
|
||||||
@Override
|
@Override
|
||||||
protected void writeMessage(String msg) {
|
protected void writeMessage(String msg) {
|
||||||
|
|
Loading…
Reference in New Issue