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.
@@ -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);