Skip to content

Commit debe78b

Browse files
imkulwantsbrannen
authored andcommitted
Minor improvements in spring-test
- Remove final modifier from private method - Use StandardCharsets - Remove unnecessary toString calls - Remove unnecessary static modifiers - Refactor to use enhanced switch - Replace concatenated strings with text blocks - Rely on auto-boxing where appropriate - Remove unnecessary code - Fix imports in Kotlin test classes Closes gh-29413
1 parent 307247b commit debe78b

File tree

33 files changed

+175
-207
lines changed

33 files changed

+175
-207
lines changed

spring-test/src/main/java/org/springframework/test/context/junit/jupiter/AbstractExpressionEvaluatingCondition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected <A extends Annotation> ConditionEvaluationResult evaluateAnnotation(Cl
9393
AnnotatedElement element = context.getElement().get();
9494
Optional<A> annotation = findMergedAnnotation(element, annotationType);
9595

96-
if (!annotation.isPresent()) {
96+
if (annotation.isEmpty()) {
9797
String reason = String.format("%s is enabled since @%s is not present", element,
9898
annotationType.getSimpleName());
9999
if (logger.isDebugEnabled()) {

spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ else if (logger.isDebugEnabled()) {
188188
* register a JVM shutdown hook for it
189189
* @return a new application context
190190
*/
191-
private final GenericApplicationContext loadContext(
191+
private GenericApplicationContext loadContext(
192192
MergedContextConfiguration mergedConfig, boolean forAotProcessing) throws Exception {
193193

194194
if (logger.isTraceEnabled()) {

spring-test/src/main/java/org/springframework/test/context/testng/AbstractTestNGSpringContextTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ protected void springTestContextAfterTestClass() throws Exception {
201201
private Throwable getTestResultException(ITestResult testResult) {
202202
Throwable testResultException = testResult.getThrowable();
203203
if (testResultException instanceof InvocationTargetException) {
204-
testResultException = ((InvocationTargetException) testResultException).getCause();
204+
testResultException = testResultException.getCause();
205205
}
206206
return testResultException;
207207
}

spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void assertSource(String content, Matcher<? super Source> matcher) throws
8282
public void assertXmlEqual(String expected, String actual) throws Exception {
8383
XmlUnitDiff diff = new XmlUnitDiff(expected, actual);
8484
if (diff.hasDifferences()) {
85-
AssertionErrors.fail("Body content " + diff.toString());
85+
AssertionErrors.fail("Body content " + diff);
8686
}
8787
}
8888

spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/BootstrapWithTestInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
@BootstrapWith(CustomTestContextBootstrapper.class)
3535
interface BootstrapWithTestInterface {
3636

37-
static class CustomTestContextBootstrapper extends DefaultTestContextBootstrapper {
37+
class CustomTestContextBootstrapper extends DefaultTestContextBootstrapper {
3838

3939
@Override
4040
protected List<ContextCustomizerFactory> getContextCustomizerFactories() {

spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/ContextConfigurationTestInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
@ContextConfiguration(classes = Config.class)
2929
interface ContextConfigurationTestInterface {
3030

31-
static class Config {
31+
class Config {
3232

3333
@Bean
3434
Employee employee() {

spring-test/src/test/java/org/springframework/test/context/configuration/interfaces/WebAppConfigurationTestInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
interface WebAppConfigurationTestInterface {
3131

3232
@Configuration
33-
static class Config {
33+
class Config {
3434
/* no user beans required for these tests */
3535
}
3636

spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfileResolverWithCustomDefaultsMetaConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
@Configuration
5454
@Profile("dev")
55-
static class DevConfig {
55+
class DevConfig {
5656

5757
@Bean
5858
public String foo() {
@@ -62,7 +62,7 @@ public String foo() {
6262

6363
@Configuration
6464
@Profile("prod")
65-
static class ProductionConfig {
65+
class ProductionConfig {
6666

6767
@Bean
6868
public String foo() {
@@ -72,15 +72,15 @@ public String foo() {
7272

7373
@Configuration
7474
@Profile("resolver")
75-
static class ResolverConfig {
75+
class ResolverConfig {
7676

7777
@Bean
7878
public String foo() {
7979
return "Resolver Foo";
8080
}
8181
}
8282

83-
static class CustomResolver implements ActiveProfilesResolver {
83+
class CustomResolver implements ActiveProfilesResolver {
8484

8585
@Override
8686
public String[] resolve(Class<?> testClass) {

spring-test/src/test/java/org/springframework/test/context/junit4/annotation/meta/ConfigClassesAndProfilesWithCustomDefaultsMetaConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
@Configuration
5252
@Profile("dev")
53-
static class DevConfig {
53+
class DevConfig {
5454

5555
@Bean
5656
public String foo() {
@@ -60,7 +60,7 @@ public String foo() {
6060

6161
@Configuration
6262
@Profile("prod")
63-
static class ProductionConfig {
63+
class ProductionConfig {
6464

6565
@Bean
6666
public String foo() {

spring-test/src/test/java/org/springframework/test/context/junit4/rules/ProgrammaticTxMgmtSpringRuleTests.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,11 @@ void beforeTransaction() {
9797
void afterTransaction() {
9898
String method = this.testName.getMethodName();
9999
switch (method) {
100-
case "commitTxAndStartNewTx":
101-
case "commitTxButDoNotStartNewTx": {
102-
assertUsers("Dogbert");
103-
break;
104-
}
105-
case "rollbackTxAndStartNewTx":
106-
case "rollbackTxButDoNotStartNewTx":
107-
case "startTxWithExistingTransaction": {
108-
assertUsers("Dilbert");
109-
break;
110-
}
111-
case "rollbackTxAndStartNewTxWithDefaultCommitSemantics": {
112-
assertUsers("Dilbert", "Dogbert");
113-
break;
114-
}
115-
default: {
116-
fail("missing 'after transaction' assertion for test method: " + method);
117-
}
100+
case "commitTxAndStartNewTx", "commitTxButDoNotStartNewTx" -> assertUsers("Dogbert");
101+
case "rollbackTxAndStartNewTx", "rollbackTxButDoNotStartNewTx", "startTxWithExistingTransaction" ->
102+
assertUsers("Dilbert");
103+
case "rollbackTxAndStartNewTxWithDefaultCommitSemantics" -> assertUsers("Dilbert", "Dogbert");
104+
default -> fail("missing 'after transaction' assertion for test method: " + method);
118105
}
119106
}
120107

0 commit comments

Comments
 (0)