From 0fc724b34831cefa76ebb9a3572daef1e996601d Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Mon, 15 Jun 2026 17:37:52 +0800 Subject: [PATCH] Make inner classes in tests static where feasible Closes gh-36939 Signed-off-by: Yanming Zhou --- .../beans/BeanWrapperGenericsTests.java | 4 +- .../beans/ExtendedBeanInfoTests.java | 4 +- .../factory/support/AutowireUtilsTests.java | 2 +- .../scheduling/config/ScheduledTaskTests.java | 2 +- .../SpringValidatorAdapterTests.java | 4 +- .../core/ExceptionDepthComparatorTests.java | 10 ++--- .../core/GenericTypeResolverTests.java | 28 ++++++------- .../core/ResolvableTypeTests.java | 40 +++++++++---------- .../AnnotatedElementUtilsTests.java | 2 +- .../annotation/MergedAnnotationsTests.java | 5 +-- .../core/convert/TypeDescriptorTests.java | 4 +- .../DefaultConversionServiceTests.java | 2 +- .../spel/SelectionAndProjectionTests.java | 2 +- .../spel/SpelCompilationCoverageTests.java | 4 +- ...bstractReactiveTransactionAspectTests.java | 2 +- .../handler/CorsUrlHandlerMappingTests.java | 2 +- 16 files changed, 58 insertions(+), 59 deletions(-) diff --git a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperGenericsTests.java b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperGenericsTests.java index fa3a871c5cb..bee08eaa81f 100644 --- a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperGenericsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperGenericsTests.java @@ -687,7 +687,7 @@ class BeanWrapperGenericsTests { } - public class Bar implements Foo { + public static class Bar implements Foo { private double version; @@ -710,7 +710,7 @@ class BeanWrapperGenericsTests { } - public class Promotion implements ObjectWithId { + public static class Promotion implements ObjectWithId { private Long id; diff --git a/spring-beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java b/spring-beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java index 4d7f7d47889..4b0c7320472 100644 --- a/spring-beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java @@ -934,7 +934,7 @@ class ExtendedBeanInfoTests { } - abstract class Library { + abstract static class Library { public Book getBook() { return null; @@ -945,7 +945,7 @@ class ExtendedBeanInfoTests { } - class LawLibrary extends Library implements TextBookOperations { + static class LawLibrary extends Library implements TextBookOperations { @Override public LawBook getBook() { diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/AutowireUtilsTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/AutowireUtilsTests.java index 49407985500..a9b384bc3a3 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/AutowireUtilsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/AutowireUtilsTests.java @@ -82,7 +82,7 @@ class AutowireUtilsTests { public interface MyInterfaceType { } - public class MySimpleInterfaceType implements MyInterfaceType { + public static class MySimpleInterfaceType implements MyInterfaceType { } public static class MyTypeWithMethods { diff --git a/spring-context/src/test/java/org/springframework/scheduling/config/ScheduledTaskTests.java b/spring-context/src/test/java/org/springframework/scheduling/config/ScheduledTaskTests.java index 79f42c13055..78e5bb534bb 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/config/ScheduledTaskTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/config/ScheduledTaskTests.java @@ -95,7 +95,7 @@ class ScheduledTaskTests { assertThat(scheduledTask.nextExecution()).isNull(); } - class CountingRunnable implements Runnable { + static class CountingRunnable implements Runnable { int executionCount; diff --git a/spring-context/src/test/java/org/springframework/validation/beanvalidation/SpringValidatorAdapterTests.java b/spring-context/src/test/java/org/springframework/validation/beanvalidation/SpringValidatorAdapterTests.java index 69673345a29..b37434eb356 100644 --- a/spring-context/src/test/java/org/springframework/validation/beanvalidation/SpringValidatorAdapterTests.java +++ b/spring-context/src/test/java/org/springframework/validation/beanvalidation/SpringValidatorAdapterTests.java @@ -525,7 +525,7 @@ class SpringValidatorAdapterTests { } - public class BeanWithListElementConstraint { + public static class BeanWithListElementConstraint { @Valid private List<@NotNull String> property; @@ -540,7 +540,7 @@ class SpringValidatorAdapterTests { } - public class BeanWithMapEntryConstraint { + public static class BeanWithMapEntryConstraint { @Valid private Map<@NotNull String, @NotNull String> property; diff --git a/spring-core/src/test/java/org/springframework/core/ExceptionDepthComparatorTests.java b/spring-core/src/test/java/org/springframework/core/ExceptionDepthComparatorTests.java index b973ed5fe4b..a7e459b1f53 100644 --- a/spring-core/src/test/java/org/springframework/core/ExceptionDepthComparatorTests.java +++ b/spring-core/src/test/java/org/springframework/core/ExceptionDepthComparatorTests.java @@ -89,23 +89,23 @@ class ExceptionDepthComparatorTests { } @SuppressWarnings("serial") - public class HighestDepthException extends Throwable { + public static class HighestDepthException extends Throwable { } @SuppressWarnings("serial") - public class LowestDepthException extends HighestDepthException { + public static class LowestDepthException extends HighestDepthException { } @SuppressWarnings("serial") - public class TargetException extends LowestDepthException { + public static class TargetException extends LowestDepthException { } @SuppressWarnings("serial") - public class SameDepthException extends LowestDepthException { + public static class SameDepthException extends LowestDepthException { } @SuppressWarnings("serial") - public class NoDepthException extends TargetException { + public static class NoDepthException extends TargetException { } } diff --git a/spring-core/src/test/java/org/springframework/core/GenericTypeResolverTests.java b/spring-core/src/test/java/org/springframework/core/GenericTypeResolverTests.java index 705cb59d001..4ebc3a4f54c 100644 --- a/spring-core/src/test/java/org/springframework/core/GenericTypeResolverTests.java +++ b/spring-core/src/test/java/org/springframework/core/GenericTypeResolverTests.java @@ -260,25 +260,25 @@ class GenericTypeResolverTests { public interface MyInterfaceType { } - public class MySimpleInterfaceType implements MyInterfaceType { + public static class MySimpleInterfaceType implements MyInterfaceType { } - public class MyCollectionInterfaceType implements MyInterfaceType> { + public static class MyCollectionInterfaceType implements MyInterfaceType> { } - public abstract class MyAbstractType implements MyInterfaceType { + public abstract static class MyAbstractType implements MyInterfaceType { } - public class MyConcreteType extends MyAbstractType { + public static class MyConcreteType extends MyAbstractType { } - public abstract class MySuperclassType { + public abstract static class MySuperclassType { } - public class MySimpleSuperclassType extends MySuperclassType { + public static class MySimpleSuperclassType extends MySuperclassType { } - public class MyCollectionSuperclassType extends MySuperclassType> { + public static class MyCollectionSuperclassType extends MySuperclassType> { } public static class MyTypeWithMethods { @@ -380,19 +380,19 @@ class GenericTypeResolverTests { static class GenericClass { } - class A {} + static class A {} - class B {} + static class B {} - class C extends A {} + static class C extends A {} - class D extends B {} + static class D extends B {} - class E extends C {} + static class E extends C {} - class TestIfc {} + static class TestIfc {} - class TestImpl> extends TestIfc { + static class TestImpl> extends TestIfc { } abstract static class BiGenericClass, V extends A> {} diff --git a/spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java b/spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java index 8b67d70d783..f57baf7d1b2 100644 --- a/spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java +++ b/spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java @@ -1773,7 +1773,7 @@ class ResolvableTypeTests { public interface MyInterfaceType { } - public class MyGenericInterfaceType implements MyInterfaceType, ResolvableTypeProvider { + public static class MyGenericInterfaceType implements MyInterfaceType, ResolvableTypeProvider { private final Class type; @@ -1790,26 +1790,26 @@ class ResolvableTypeTests { } } - public class MySimpleInterfaceType implements MyInterfaceType { + public static class MySimpleInterfaceType implements MyInterfaceType { } - public abstract class MySimpleInterfaceTypeWithImplementsRaw implements MyInterfaceType, List { + public abstract static class MySimpleInterfaceTypeWithImplementsRaw implements MyInterfaceType, List { } - public abstract class ExtendsMySimpleInterfaceTypeWithImplementsRaw extends MySimpleInterfaceTypeWithImplementsRaw { + public abstract static class ExtendsMySimpleInterfaceTypeWithImplementsRaw extends MySimpleInterfaceTypeWithImplementsRaw { } - public class MyCollectionInterfaceType implements MyInterfaceType> { + public static class MyCollectionInterfaceType implements MyInterfaceType> { } - public abstract class MySuperclassType { + public abstract static class MySuperclassType { } - public class MySimpleSuperclassType extends MySuperclassType { + public static class MySimpleSuperclassType extends MySuperclassType { } - public class MyCollectionSuperclassType extends MySuperclassType> { + public static class MyCollectionSuperclassType extends MySuperclassType> { } @@ -1819,22 +1819,22 @@ class ResolvableTypeTests { private static class SubConsumer implements Consumer { } - public class Wildcard { + public static class Wildcard { } - public class WildcardFixed extends Wildcard { + public static class WildcardFixed extends Wildcard { } - public class WildcardConsumer implements Consumer> { + public static class WildcardConsumer implements Consumer> { } - public class DoubleWildcard { + public static class DoubleWildcard { } - public class DoubleWildcardFixed extends DoubleWildcard { + public static class DoubleWildcardFixed extends DoubleWildcard { } - public class DoubleWildcardConsumer implements Consumer> { + public static class DoubleWildcardConsumer implements Consumer> { } @@ -1853,10 +1853,10 @@ class ResolvableTypeTests { } - class Foo> { + static class Foo> { } - class Bar extends Foo { + static class Bar extends Foo { } @@ -1888,19 +1888,19 @@ class ResolvableTypeTests { public interface IBase> { } - public abstract class AbstractBase> implements IBase { + public abstract static class AbstractBase> implements IBase { } - public class BaseImplementation extends AbstractBase { + public static class BaseImplementation extends AbstractBase { } - public class BaseProvider> implements IProvider> { + public static class BaseProvider> implements IProvider> { public Collection> stuff; } - public abstract class UnresolvedWithGenerics { + public abstract static class UnresolvedWithGenerics { Set set; } diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java index 0066de212e8..1610009e255 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java @@ -1519,7 +1519,7 @@ class AnnotatedElementUtilsTests { @Nullable Object doIt(); } - class TransactionalServiceImpl implements TransactionalService { + static class TransactionalServiceImpl implements TransactionalService { @Override public @Nullable Object doIt() { diff --git a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java index 276fb7167c7..c5c386e71d6 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java @@ -2794,7 +2794,7 @@ class MergedAnnotationsTests { void doIt(); } - class TransactionalServiceImpl implements TransactionalService { + static class TransactionalServiceImpl implements TransactionalService { @Override public void doIt() { @@ -3289,8 +3289,7 @@ class MergedAnnotationsTests { @interface DoublyComposedRootAnnotation { } - class DomainType { - + static class DomainType { @RootAnnotation Object directlyAnnotated; diff --git a/spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java b/spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java index 2554391af6e..18b70b7eece 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java @@ -967,7 +967,7 @@ class TypeDescriptorTests { } - public class IntegerType implements GenericType { + public static class IntegerType implements GenericType { @Override public Integer getProperty() { @@ -989,7 +989,7 @@ class TypeDescriptorTests { } - public class NumberType implements GenericType { + public static class NumberType implements GenericType { @Override public Integer getProperty() { diff --git a/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java b/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java index 03205ad34ec..16bac7febe1 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java @@ -1195,7 +1195,7 @@ class DefaultConversionServiceTests { } - public class ColorConverter implements Converter { + public static class ColorConverter implements Converter { @Override public Color convert(String source) { diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/SelectionAndProjectionTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/SelectionAndProjectionTests.java index 3969774c682..7af933ded9b 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/SelectionAndProjectionTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/SelectionAndProjectionTests.java @@ -372,7 +372,7 @@ class SelectionAndProjectionTests { /** * Simulates a custom {@link Iterable} which is itself not a {@link Collection}. */ - class Counter implements Iterable { + static class Counter implements Iterable { private final List list = new ArrayList<>(); diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java index 0fbd98ab010..611d7170ff6 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java @@ -6744,7 +6744,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { } - public class PayloadX { + public static class PayloadX { public int valueI = 120; public Integer valueIB = 120; @@ -7456,7 +7456,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { } - public class Reg { + public static class Reg { private Integer _value,_value2; private Long _valueL,_valueL2; diff --git a/spring-tx/src/test/java/org/springframework/transaction/interceptor/AbstractReactiveTransactionAspectTests.java b/spring-tx/src/test/java/org/springframework/transaction/interceptor/AbstractReactiveTransactionAspectTests.java index bd02eedb2ae..d1105ce0d11 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/interceptor/AbstractReactiveTransactionAspectTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/interceptor/AbstractReactiveTransactionAspectTests.java @@ -387,7 +387,7 @@ public abstract class AbstractReactiveTransactionAspectTests { } - public class DefaultTestBean implements TestBean { + public static class DefaultTestBean implements TestBean { private String name; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/handler/CorsUrlHandlerMappingTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/handler/CorsUrlHandlerMappingTests.java index 97d3ed42640..d72869802ee 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/handler/CorsUrlHandlerMappingTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/handler/CorsUrlHandlerMappingTests.java @@ -194,7 +194,7 @@ class CorsUrlHandlerMappingTests { } } - public class CustomCorsConfigurationSource implements CorsConfigurationSource { + public static class CustomCorsConfigurationSource implements CorsConfigurationSource { @Override public CorsConfiguration getCorsConfiguration(ServerWebExchange exchange) {