Introduce Checkstyle rule for separator symbol location

This commit is contained in:
Sam Brannen
2025-03-19 15:35:35 +01:00
parent 18c3b637e4
commit 208d52d852
97 changed files with 378 additions and 403 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -118,8 +118,8 @@ abstract class AbstractExpressionEvaluatingCondition implements ExecutionConditi
if (logger.isInfoEnabled()) {
logger.info(reason);
}
result = (enabledOnTrue ? ConditionEvaluationResult.enabled(reason)
: ConditionEvaluationResult.disabled(reason));
result = (enabledOnTrue ? ConditionEvaluationResult.enabled(reason) :
ConditionEvaluationResult.disabled(reason));
}
else {
String adjective = (enabledOnTrue ? "disabled" : "enabled");

View File

@@ -252,8 +252,8 @@ abstract class ContextLoaderUtils {
// annotated class.
if (currentAnnotation.equals(previousAnnotation) && hasResources(currentAnnotation)) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("Ignoring duplicate %s declaration on [%s], "
+ "since it is also declared on [%s].", currentAnnotation,
logger.debug(String.format("Ignoring duplicate %s declaration on [%s], " +
"since it is also declared on [%s].", currentAnnotation,
previousDeclaringClass.getName(), descriptor.getRootDeclaringClass().getName()));
}
}

View File

@@ -36,12 +36,14 @@ import org.springframework.util.ClassUtils;
*/
public class DelegatingSmartContextLoader extends AbstractDelegatingSmartContextLoader {
private static final String GROOVY_XML_CONTEXT_LOADER_CLASS_NAME = "org.springframework.test.context.support.GenericGroovyXmlContextLoader";
private static final String GROOVY_XML_CONTEXT_LOADER_CLASS_NAME =
"org.springframework.test.context.support.GenericGroovyXmlContextLoader";
private static final boolean groovyPresent = ClassUtils.isPresent("groovy.lang.Closure",
DelegatingSmartContextLoader.class.getClassLoader())
&& ClassUtils.isPresent(GROOVY_XML_CONTEXT_LOADER_CLASS_NAME,
DelegatingSmartContextLoader.class.getClassLoader());
DelegatingSmartContextLoader.class.getClassLoader()) &&
ClassUtils.isPresent(GROOVY_XML_CONTEXT_LOADER_CLASS_NAME,
DelegatingSmartContextLoader.class.getClassLoader());
private final SmartContextLoader xmlLoader;
private final SmartContextLoader annotationConfigLoader;
@@ -55,8 +57,8 @@ public class DelegatingSmartContextLoader extends AbstractDelegatingSmartContext
this.xmlLoader = (SmartContextLoader) BeanUtils.instantiateClass(loaderClass);
}
catch (Throwable ex) {
throw new IllegalStateException("Failed to enable support for Groovy scripts; "
+ "could not load class: " + GROOVY_XML_CONTEXT_LOADER_CLASS_NAME, ex);
throw new IllegalStateException("Failed to enable support for Groovy scripts; " +
"could not load class: " + GROOVY_XML_CONTEXT_LOADER_CLASS_NAME, ex);
}
}
else {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -92,9 +92,9 @@ class TestPropertySourceAttributes {
*/
void mergeWith(TestPropertySourceAttributes attributes) {
Assert.state(attributes.declaringClass == this.declaringClass,
() -> "Detected @TestPropertySource declarations within an aggregate index "
+ "with different sources: " + this.declaringClass.getName() + " and "
+ attributes.declaringClass.getName());
() -> "Detected @TestPropertySource declarations within an aggregate index " +
"with different sources: " + this.declaringClass.getName() + " and " +
attributes.declaringClass.getName());
logger.trace(LogMessage.format("Retrieved %s for declaring class [%s].",
attributes, this.declaringClass.getName()));
assertSameBooleanAttribute(this.inheritLocations, attributes.inheritLocations,

View File

@@ -39,9 +39,9 @@ public class WebDelegatingSmartContextLoader extends AbstractDelegatingSmartCont
private static final String GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME = "org.springframework.test.context.web.GenericGroovyXmlWebContextLoader";
private static final boolean groovyPresent = ClassUtils.isPresent("groovy.lang.Closure",
WebDelegatingSmartContextLoader.class.getClassLoader())
&& ClassUtils.isPresent(GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME,
WebDelegatingSmartContextLoader.class.getClassLoader());
WebDelegatingSmartContextLoader.class.getClassLoader()) &&
ClassUtils.isPresent(GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME,
WebDelegatingSmartContextLoader.class.getClassLoader());
private final SmartContextLoader xmlLoader;
private final SmartContextLoader annotationConfigLoader;
@@ -55,8 +55,8 @@ public class WebDelegatingSmartContextLoader extends AbstractDelegatingSmartCont
this.xmlLoader = (SmartContextLoader) BeanUtils.instantiateClass(loaderClass);
}
catch (Throwable ex) {
throw new IllegalStateException("Failed to enable support for Groovy scripts; "
+ "could not load class: " + GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME, ex);
throw new IllegalStateException("Failed to enable support for Groovy scripts; " +
"could not load class: " + GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME, ex);
}
}
else {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -41,8 +41,8 @@ public abstract class JsonAssert {
* @see JSONCompareMode#LENIENT
*/
public static JsonComparator comparator(JsonCompareMode compareMode) {
JSONCompareMode jsonAssertCompareMode = (compareMode != JsonCompareMode.LENIENT
? JSONCompareMode.STRICT : JSONCompareMode.LENIENT);
JSONCompareMode jsonAssertCompareMode = (compareMode != JsonCompareMode.LENIENT ?
JSONCompareMode.STRICT : JSONCompareMode.LENIENT);
return comparator(jsonAssertCompareMode);
}
@@ -81,18 +81,14 @@ public abstract class JsonAssert {
@Override
public JsonComparison compare(@Nullable String expectedJson, @Nullable String actualJson) {
if (actualJson == null) {
return (expectedJson != null)
? JsonComparison.mismatch("Expected null JSON")
: JsonComparison.match();
return (expectedJson != null) ? JsonComparison.mismatch("Expected null JSON") : JsonComparison.match();
}
if (expectedJson == null) {
return JsonComparison.mismatch("Expected non-null JSON");
}
try {
JSONCompareResult result = JSONCompare.compareJSON(expectedJson, actualJson, this.jsonAssertComparator);
return (!result.passed())
? JsonComparison.mismatch(result.getMessage())
: JsonComparison.match();
return (!result.passed()) ? JsonComparison.mismatch(result.getMessage()) : JsonComparison.match();
}
catch (JSONException ex) {
throw new IllegalStateException(ex);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -47,35 +47,45 @@ class ProfileValueUtilsTests {
}
private void assertClassIsEnabled(Class<?> testClass) {
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(testClass)).as("Test class [" + testClass + "] should be enabled.").isTrue();
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(testClass))
.as("Test class [" + testClass + "] should be enabled.")
.isTrue();
}
private void assertClassIsDisabled(Class<?> testClass) {
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(testClass)).as("Test class [" + testClass + "] should be disabled.").isFalse();
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(testClass))
.as("Test class [" + testClass + "] should be disabled.")
.isFalse();
}
private void assertMethodIsEnabled(String methodName, Class<?> testClass) throws Exception {
Method testMethod = testClass.getMethod(methodName);
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(testMethod, testClass)).as("Test method [" + testMethod + "] should be enabled.").isTrue();
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(testMethod, testClass))
.as("Test method [" + testMethod + "] should be enabled.")
.isTrue();
}
private void assertMethodIsDisabled(String methodName, Class<?> testClass) throws Exception {
Method testMethod = testClass.getMethod(methodName);
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(testMethod, testClass)).as("Test method [" + testMethod + "] should be disabled.").isFalse();
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(testMethod, testClass))
.as("Test method [" + testMethod + "] should be disabled.")
.isFalse();
}
private void assertMethodIsEnabled(ProfileValueSource profileValueSource, String methodName, Class<?> testClass)
throws Exception {
Method testMethod = testClass.getMethod(methodName);
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(profileValueSource, testMethod, testClass)).as("Test method [" + testMethod + "] should be enabled for ProfileValueSource [" + profileValueSource
+ "].").isTrue();
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(profileValueSource, testMethod, testClass))
.as("Test method [" + testMethod + "] should be enabled for ProfileValueSource [" + profileValueSource + "].")
.isTrue();
}
private void assertMethodIsDisabled(ProfileValueSource profileValueSource, String methodName, Class<?> testClass)
throws Exception {
Method testMethod = testClass.getMethod(methodName);
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(profileValueSource, testMethod, testClass)).as("Test method [" + testMethod + "] should be disabled for ProfileValueSource [" + profileValueSource
+ "].").isFalse();
assertThat(ProfileValueUtils.isTestEnabledInThisEnvironment(profileValueSource, testMethod, testClass))
.as("Test method [" + testMethod + "] should be disabled for ProfileValueSource [" + profileValueSource + "].")
.isFalse();
}
// -------------------------------------------------------------------

View File

@@ -106,8 +106,8 @@ class FailingBeforeAndAfterMethodsSpringExtensionTests {
}
private int getExpectedFailedCount(Class<?> testClass) {
if (testClass == AlwaysFailingBeforeTestClassTestCase.class
|| testClass == AlwaysFailingAfterTestClassTestCase.class) {
if (testClass == AlwaysFailingBeforeTestClassTestCase.class ||
testClass == AlwaysFailingAfterTestClassTestCase.class) {
return 0;
}
return 1;

View File

@@ -98,8 +98,7 @@ public class BeforeAndAfterTransactionAnnotationTests extends AbstractTransactio
@Before
public void before() {
assertShouldBeInTransaction();
long expected = (this.inTransaction ? 1
: 0);
long expected = (this.inTransaction ? 1 : 0);
assertThat(countRowsInPersonTable(jdbcTemplate)).as("Verifying the number of rows in the person table before a test method.").isEqualTo(expected);
}

View File

@@ -42,8 +42,9 @@ public class ClassPathResourceSpringJUnit4ClassRunnerAppCtxTests extends SpringJ
* @see SpringJUnit4ClassRunnerAppCtxTests#DEFAULT_CONTEXT_RESOURCE_PATH
* @see ResourceUtils#CLASSPATH_URL_PREFIX
*/
public static final String CLASSPATH_CONTEXT_RESOURCE_PATH = ResourceUtils.CLASSPATH_URL_PREFIX
+ SpringJUnit4ClassRunnerAppCtxTests.DEFAULT_CONTEXT_RESOURCE_PATH;
public static final String CLASSPATH_CONTEXT_RESOURCE_PATH = ResourceUtils.CLASSPATH_URL_PREFIX +
SpringJUnit4ClassRunnerAppCtxTests.DEFAULT_CONTEXT_RESOURCE_PATH;
/* all tests are in the parent class. */
}

View File

@@ -37,10 +37,11 @@ import org.springframework.util.ResourceUtils;
MultipleResourcesSpringJUnit4ClassRunnerAppCtxTests.ABSOLUTE_RESOURCE_PATH })
public class MultipleResourcesSpringJUnit4ClassRunnerAppCtxTests extends SpringJUnit4ClassRunnerAppCtxTests {
public static final String CLASSPATH_RESOURCE_PATH = ResourceUtils.CLASSPATH_URL_PREFIX
+ "/org/springframework/test/context/junit4/MultipleResourcesSpringJUnit4ClassRunnerAppCtxTests-context1.xml";
public static final String CLASSPATH_RESOURCE_PATH = ResourceUtils.CLASSPATH_URL_PREFIX +
"/org/springframework/test/context/junit4/MultipleResourcesSpringJUnit4ClassRunnerAppCtxTests-context1.xml";
public static final String LOCAL_RESOURCE_PATH = "MultipleResourcesSpringJUnit4ClassRunnerAppCtxTests-context2.xml";
public static final String ABSOLUTE_RESOURCE_PATH = "/org/springframework/test/context/junit4/MultipleResourcesSpringJUnit4ClassRunnerAppCtxTests-context3.xml";
/* all tests are in the parent class. */
}

View File

@@ -84,8 +84,8 @@ public @interface ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig {
@Override
public String[] resolve(Class<?> testClass) {
return testClass.getSimpleName().equals("ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigTests") ? new String[] { "resolver" }
: new String[] {};
return testClass.getSimpleName().equals("ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfigTests") ?
new String[] { "resolver" } : new String[] {};
}
}

View File

@@ -372,8 +372,8 @@ class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsTests {
@Override
public String[] resolve(Class<?> testClass) {
return testClass.isAnnotation() ? new String[] { "@" + testClass.getSimpleName() }
: new String[] { testClass.getSimpleName() };
return testClass.isAnnotation() ? new String[] { "@" + testClass.getSimpleName() } :
new String[] { testClass.getSimpleName() };
}
}

View File

@@ -84,8 +84,7 @@ public abstract class AbstractBasicWacTests implements ServletContextAware {
assertThat(webRequest).as("ServletWebRequest should have been autowired from the WAC.").isNotNull();
Object rootWac = mockServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
assertThat(rootWac).as("Root WAC must be stored in the ServletContext as: "
+ WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE).isNotNull();
assertThat(rootWac).as("Root WAC must be stored in the ServletContext as: " + WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE).isNotNull();
assertThat(rootWac).as("test WAC and Root WAC in ServletContext must be the same object.").isSameAs(wac);
assertThat(wac.getServletContext()).as("ServletContext instances must be the same object.").isSameAs(mockServletContext);
assertThat(request.getServletContext()).as("ServletContext in the WAC and in the mock request").isSameAs(mockServletContext);

View File

@@ -99,8 +99,7 @@ public class JUnit4SpringContextWebTests extends AbstractJUnit4SpringContextTest
assertThat(webRequest).as("ServletWebRequest should have been autowired from the WAC.").isNotNull();
Object rootWac = mockServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
assertThat(rootWac).as("Root WAC must be stored in the ServletContext as: "
+ WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE).isNotNull();
assertThat(rootWac).as("Root WAC must be stored in the ServletContext as: " + WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE).isNotNull();
assertThat(rootWac).as("test WAC and Root WAC in ServletContext must be the same object.").isSameAs(wac);
assertThat(wac.getServletContext()).as("ServletContext instances must be the same object.").isSameAs(mockServletContext);
assertThat(request.getServletContext()).as("ServletContext in the WAC and in the mock request").isSameAs(mockServletContext);

View File

@@ -63,8 +63,7 @@ class MetaAnnotationConfigWacTests {
assertThat(mockServletContext).as("ServletContext should have been autowired from the WAC.").isNotNull();
Object rootWac = mockServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
assertThat(rootWac).as("Root WAC must be stored in the ServletContext as: "
+ WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE).isNotNull();
assertThat(rootWac).as("Root WAC must be stored in the ServletContext as: " + WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE).isNotNull();
assertThat(rootWac).as("test WAC and Root WAC in ServletContext must be the same object.").isSameAs(wac);
assertThat(wac.getServletContext()).as("ServletContext instances must be the same object.").isSameAs(mockServletContext);

View File

@@ -81,8 +81,8 @@ public class Person {
@Override
public String toString() {
return "Person [name=" + this.name + ", someDouble=" + this.someDouble
+ ", someBoolean=" + this.someBoolean + "]";
return "Person [name=" + this.name + ", someDouble=" + this.someDouble +
", someBoolean=" + this.someBoolean + "]";
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2025 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.
@@ -48,13 +48,14 @@ import static org.hamcrest.Matchers.startsWith;
*/
class XmlContentTests {
private static final String persons_XML =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+ "<persons>"
+ "<person><name>Jane</name></person>"
+ "<person><name>Jason</name></person>"
+ "<person><name>John</name></person>"
+ "</persons>";
private static final String persons_XML = """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persons>
<person><name>Jane</name></person>
<person><name>Jason</name></person>
<person><name>John</name></person>
</persons>
""";
private final WebTestClient client = WebTestClient.bindToController(new PersonController()).build();

View File

@@ -706,8 +706,7 @@ public class HtmlUnitRequestBuilderTests {
webRequest.setAdditionalHeader("Cookie", "JSESSIONID=" + sessionId + "NEW");
actualRequest = requestBuilder.buildRequest(servletContext);
assertThat(actualRequest.getSession()).isNotEqualTo(session);
assertSingleSessionCookie("JSESSIONID=" + actualRequest.getSession().getId()
+ "; Path=/test; Domain=example.com");
assertSingleSessionCookie("JSESSIONID=" + actualRequest.getSession().getId() + "; Path=/test; Domain=example.com");
}
@Test
@@ -763,8 +762,8 @@ public class HtmlUnitRequestBuilderTests {
sessionToRemove.invalidate();
assertThat(sessions.containsKey(sessionToRemove.getId())).isFalse();
assertSingleSessionCookie("JSESSIONID=" + sessionToRemove.getId()
+ "; Expires=Thu, 01-Jan-1970 00:00:01 GMT; Path=/test; Domain=example.com");
assertSingleSessionCookie("JSESSIONID=" + sessionToRemove.getId() +
"; Expires=Thu, 01-Jan-1970 00:00:01 GMT; Path=/test; Domain=example.com");
webRequest.removeAdditionalHeader("Cookie");
requestBuilder = new HtmlUnitRequestBuilder(sessions, webClient, webRequest);