From 115a46c5e8d536b125fc39d718d1c3061e9dcf3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Tue, 31 Oct 2023 17:58:13 +0100 Subject: [PATCH] Polish --- .../test/context/ActiveProfilesResolver.java | 4 ++-- .../org/springframework/test/context/BootstrapUtils.java | 6 +++--- .../test/context/ContextConfigurationAttributes.java | 2 +- .../test/context/MergedContextConfiguration.java | 4 ---- .../org/springframework/test/context/MethodInvoker.java | 2 +- .../test/context/NestedTestConfiguration.java | 4 ++-- .../org/springframework/test/context/TestConstructor.java | 2 +- .../test/context/TestContextAnnotationUtils.java | 2 +- .../springframework/test/context/aot/DisabledInAotMode.java | 2 +- .../context/aot/MergedContextConfigurationRuntimeHints.java | 4 +--- .../test/context/aot/TestContextGenerationContext.java | 2 +- .../cache/DefaultCacheAwareContextLoaderDelegate.java | 3 +-- .../jupiter/AbstractExpressionEvaluatingCondition.java | 6 +++--- .../test/context/junit4/SpringJUnit4ClassRunner.java | 4 ++-- .../test/context/support/ActiveProfilesUtils.java | 4 ++-- .../test/context/support/DefaultActiveProfilesResolver.java | 4 ++-- .../test/context/support/TestConstructorUtils.java | 2 +- .../test/context/support/TestPropertySourceAttributes.java | 1 - .../test/context/support/TestPropertySourceUtils.java | 2 +- .../test/context/web/AbstractGenericWebContextLoader.java | 4 ++-- 20 files changed, 28 insertions(+), 36 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/ActiveProfilesResolver.java b/spring-test/src/main/java/org/springframework/test/context/ActiveProfilesResolver.java index c101c3d1e3..e29534833f 100644 --- a/spring-test/src/main/java/org/springframework/test/context/ActiveProfilesResolver.java +++ b/spring-test/src/main/java/org/springframework/test/context/ActiveProfilesResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2023 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. @@ -40,7 +40,7 @@ public interface ActiveProfilesResolver { * {@code ApplicationContext} for the given {@linkplain Class test class}. * @param testClass the test class for which the profiles should be resolved; * never {@code null} - * @return the list of bean definition profiles to use when loading the + * @return the bean definition profiles to use when loading the * {@code ApplicationContext}; never {@code null} * @see ActiveProfiles#resolver * @see ActiveProfiles#inheritProfiles diff --git a/spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java b/spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java index f5c7312154..5a35391eaf 100644 --- a/spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -76,7 +76,7 @@ public abstract class BootstrapUtils { static BootstrapContext createBootstrapContext(Class testClass) { CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = createCacheAwareContextLoaderDelegate(); String className = DEFAULT_BOOTSTRAP_CONTEXT_CLASS_NAME; - Class clazz = null; + Class clazz; try { clazz = (Class) ClassUtils.forName(className, BootstrapUtils.class.getClassLoader()); @@ -93,7 +93,7 @@ public abstract class BootstrapUtils { @SuppressWarnings("unchecked") private static CacheAwareContextLoaderDelegate createCacheAwareContextLoaderDelegate() { String className = DEFAULT_CACHE_AWARE_CONTEXT_LOADER_DELEGATE_CLASS_NAME; - Class clazz = null; + Class clazz; try { clazz = (Class) ClassUtils.forName(className, BootstrapUtils.class.getClassLoader()); diff --git a/spring-test/src/main/java/org/springframework/test/context/ContextConfigurationAttributes.java b/spring-test/src/main/java/org/springframework/test/context/ContextConfigurationAttributes.java index 591ee45fc9..73643729ef 100644 --- a/spring-test/src/main/java/org/springframework/test/context/ContextConfigurationAttributes.java +++ b/spring-test/src/main/java/org/springframework/test/context/ContextConfigurationAttributes.java @@ -75,7 +75,7 @@ public class ContextConfigurationAttributes { * either explicitly or implicitly * @since 4.3 */ - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) public ContextConfigurationAttributes(Class declaringClass) { this(declaringClass, EMPTY_LOCATIONS, EMPTY_CLASSES, false, (Class[]) EMPTY_CLASSES, true, ContextLoader.class); } diff --git a/spring-test/src/main/java/org/springframework/test/context/MergedContextConfiguration.java b/spring-test/src/main/java/org/springframework/test/context/MergedContextConfiguration.java index 1764a054cd..26837b83f5 100644 --- a/spring-test/src/main/java/org/springframework/test/context/MergedContextConfiguration.java +++ b/spring-test/src/main/java/org/springframework/test/context/MergedContextConfiguration.java @@ -88,7 +88,6 @@ public class MergedContextConfiguration implements Serializable { private final Class[] classes; - @SuppressWarnings("serial") private final Set>> contextInitializerClasses; private final String[] activeProfiles; @@ -99,14 +98,11 @@ public class MergedContextConfiguration implements Serializable { private final String[] propertySourceProperties; - @SuppressWarnings("serial") private final Set contextCustomizers; - @SuppressWarnings("serial") private final ContextLoader contextLoader; @Nullable - @SuppressWarnings("serial") private final CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate; @Nullable diff --git a/spring-test/src/main/java/org/springframework/test/context/MethodInvoker.java b/spring-test/src/main/java/org/springframework/test/context/MethodInvoker.java index f98ef3f3e6..247351e3b8 100644 --- a/spring-test/src/main/java/org/springframework/test/context/MethodInvoker.java +++ b/spring-test/src/main/java/org/springframework/test/context/MethodInvoker.java @@ -47,7 +47,7 @@ public interface MethodInvoker { * Shared instance of the default {@link MethodInvoker}. *

This invoker never provides arguments to a {@link Method}. */ - static final MethodInvoker DEFAULT_INVOKER = new DefaultMethodInvoker(); + MethodInvoker DEFAULT_INVOKER = new DefaultMethodInvoker(); /** diff --git a/spring-test/src/main/java/org/springframework/test/context/NestedTestConfiguration.java b/spring-test/src/main/java/org/springframework/test/context/NestedTestConfiguration.java index 74e7ec91a1..3686560b7a 100644 --- a/spring-test/src/main/java/org/springframework/test/context/NestedTestConfiguration.java +++ b/spring-test/src/main/java/org/springframework/test/context/NestedTestConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2023 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. @@ -98,7 +98,7 @@ public @interface NestedTestConfiguration { /** * JVM system property used to change the default enclosing configuration - * inheritance mode: {@value #ENCLOSING_CONFIGURATION_PROPERTY_NAME}. + * inheritance mode: {@value}. *

Supported values include enum constants defined in * {@link EnclosingConfiguration}, ignoring case. For example, the default * may be changed to {@link EnclosingConfiguration#OVERRIDE} by supplying diff --git a/spring-test/src/main/java/org/springframework/test/context/TestConstructor.java b/spring-test/src/main/java/org/springframework/test/context/TestConstructor.java index 1f286429e9..74ebda799d 100644 --- a/spring-test/src/main/java/org/springframework/test/context/TestConstructor.java +++ b/spring-test/src/main/java/org/springframework/test/context/TestConstructor.java @@ -79,7 +79,7 @@ public @interface TestConstructor { /** * JVM system property used to change the default test constructor - * autowire mode: {@value #TEST_CONSTRUCTOR_AUTOWIRE_MODE_PROPERTY_NAME}. + * autowire mode: {@value}. *

Acceptable values include enum constants defined in {@link AutowireMode}, * ignoring case. For example, the default may be changed to {@link AutowireMode#ALL} * by supplying the following JVM system property via the command line. diff --git a/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java b/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java index cf28420ce8..be01566361 100644 --- a/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java @@ -248,7 +248,7 @@ public abstract class TestContextAnnotationUtils { return new AnnotationDescriptor<>(clazz, clazz.getAnnotation(annotationType)); } - AnnotationDescriptor descriptor = null; + AnnotationDescriptor descriptor; // Declared on a composed annotation (i.e., as a meta-annotation)? for (Annotation composedAnn : clazz.getDeclaredAnnotations()) { diff --git a/spring-test/src/main/java/org/springframework/test/context/aot/DisabledInAotMode.java b/spring-test/src/main/java/org/springframework/test/context/aot/DisabledInAotMode.java index 1f3a6dd6ca..ea94e60e6d 100644 --- a/spring-test/src/main/java/org/springframework/test/context/aot/DisabledInAotMode.java +++ b/spring-test/src/main/java/org/springframework/test/context/aot/DisabledInAotMode.java @@ -32,7 +32,7 @@ import org.junit.jupiter.api.condition.DisabledIf; *

If a test class is annotated with {@code @DisabledInAotMode}, all other test * classes which specify configuration to load the same {@code ApplicationContext} * must also be annotated with {@code @DisabledInAotMode}. Failure to annotate - * all such test classes will result in a exception, either at build time or + * all such test classes will result in an exception, either at build time or * run time. * *

When used with JUnit Jupiter based tests, {@code @DisabledInAotMode} also diff --git a/spring-test/src/main/java/org/springframework/test/context/aot/MergedContextConfigurationRuntimeHints.java b/spring-test/src/main/java/org/springframework/test/context/aot/MergedContextConfigurationRuntimeHints.java index 70cbd9cfdf..82803a5b44 100644 --- a/spring-test/src/main/java/org/springframework/test/context/aot/MergedContextConfigurationRuntimeHints.java +++ b/spring-test/src/main/java/org/springframework/test/context/aot/MergedContextConfigurationRuntimeHints.java @@ -64,7 +64,6 @@ class MergedContextConfigurationRuntimeHints { private final Log logger = LogFactory.getLog(getClass()); - @SuppressWarnings("deprecation") public void registerHints(RuntimeHints runtimeHints, MergedContextConfiguration mergedConfig, ClassLoader classLoader) { // @ContextConfiguration(loader = ...) ContextLoader contextLoader = mergedConfig.getContextLoader(); @@ -92,7 +91,7 @@ class MergedContextConfigurationRuntimeHints { // @WebAppConfiguration(value = ...) if (webMergedContextConfigurationClass.isInstance(mergedConfig)) { - String resourceBasePath = null; + String resourceBasePath; try { resourceBasePath = (String) getResourceBasePathMethod.invoke(mergedConfig); } @@ -150,7 +149,6 @@ class MergedContextConfigurationRuntimeHints { } } - @SuppressWarnings("unchecked") private static Class loadWebMergedContextConfigurationClass() { try { return ClassUtils.forName(WEB_MERGED_CONTEXT_CONFIGURATION_CLASS_NAME, diff --git a/spring-test/src/main/java/org/springframework/test/context/aot/TestContextGenerationContext.java b/spring-test/src/main/java/org/springframework/test/context/aot/TestContextGenerationContext.java index 9e14822394..957a5b628f 100644 --- a/spring-test/src/main/java/org/springframework/test/context/aot/TestContextGenerationContext.java +++ b/spring-test/src/main/java/org/springframework/test/context/aot/TestContextGenerationContext.java @@ -63,7 +63,7 @@ class TestContextGenerationContext extends DefaultGenerationContext { * Create a new {@link TestContextGenerationContext} instance using the specified * feature name to qualify generated assets for a dedicated round of code generation. *

If this {@code TestContextGenerationContext} has a configured feature - * name, the existing feature name will prepended to the supplied feature name in + * name, the existing feature name will be prepended to the supplied feature name in * order to avoid naming collisions. * @param featureName the feature name to use * @return a specialized {@link TestContextGenerationContext} for the specified diff --git a/spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java b/spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java index 145998fdcd..c9601be992 100644 --- a/spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java +++ b/spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java @@ -137,7 +137,7 @@ public class DefaultCacheAwareContextLoaderDelegate implements CacheAwareContext ApplicationContext context = this.contextCache.get(mergedConfig); try { if (context == null) { - Integer failureCount = this.contextCache.getFailureCount(mergedConfig); + int failureCount = this.contextCache.getFailureCount(mergedConfig); if (failureCount >= this.failureThreshold) { throw new IllegalStateException(""" ApplicationContext failure threshold (%d) exceeded: \ @@ -287,7 +287,6 @@ public class DefaultCacheAwareContextLoaderDelegate implements CacheAwareContext * have an AOT-optimized {@code ApplicationContext} * @since 6.0 */ - @SuppressWarnings("unchecked") private MergedContextConfiguration replaceIfNecessary(MergedContextConfiguration mergedConfig) { if (AotDetector.useGeneratedArtifacts()) { Class testClass = mergedConfig.getTestClass(); diff --git a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/AbstractExpressionEvaluatingCondition.java b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/AbstractExpressionEvaluatingCondition.java index 09db2ae790..9542bd73c8 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/AbstractExpressionEvaluatingCondition.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/AbstractExpressionEvaluatingCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -79,10 +79,10 @@ abstract class AbstractExpressionEvaluatingCondition implements ExecutionConditi * @param loadContextExtractor a function that extracts the {@code loadContext} * flag from the annotation * @param enabledOnTrue indicates whether the returned {@code ConditionEvaluationResult} - * should be {@link ConditionEvaluationResult#enabled enabled} if the expression + * should be {@link ConditionEvaluationResult#enabled(String)} enabled} if the expression * evaluates to {@code true} * @param context the {@code ExtensionContext} - * @return {@link ConditionEvaluationResult#enabled enabled} if the container + * @return {@link ConditionEvaluationResult#enabled(String)} enabled} if the container * or test should be enabled; otherwise {@link ConditionEvaluationResult#disabled disabled} */ protected ConditionEvaluationResult evaluateAnnotation(Class annotationType, diff --git a/spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java b/spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java index 904618a68d..d06106d746 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -370,7 +370,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { // in BlockJUnit4ClassRunner has been deprecated. @SuppressWarnings("deprecation") protected Statement withPotentialTimeout(FrameworkMethod frameworkMethod, Object testInstance, Statement next) { - Statement statement = null; + Statement statement; long springTimeout = getSpringTimeout(frameworkMethod); long junitTimeout = getJUnitTimeout(frameworkMethod); if (springTimeout > 0 && junitTimeout > 0) { diff --git a/spring-test/src/main/java/org/springframework/test/context/support/ActiveProfilesUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/ActiveProfilesUtils.java index 719591efd1..18044d4cc5 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/ActiveProfilesUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/ActiveProfilesUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -64,7 +64,7 @@ abstract class ActiveProfilesUtils { * and enclosing classes. * @param testClass the class for which to resolve the active profiles (must not be * {@code null}) - * @return the set of active profiles for the specified class, including active + * @return the active profiles for the specified class, including active * profiles from superclasses and enclosing classes if appropriate (never {@code null}) * @see ActiveProfiles * @see ActiveProfilesResolver diff --git a/spring-test/src/main/java/org/springframework/test/context/support/DefaultActiveProfilesResolver.java b/spring-test/src/main/java/org/springframework/test/context/support/DefaultActiveProfilesResolver.java index 5f68a4d8b7..5f52030208 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/DefaultActiveProfilesResolver.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/DefaultActiveProfilesResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -50,7 +50,7 @@ public class DefaultActiveProfilesResolver implements ActiveProfilesResolver { * {@link ActiveProfiles#profiles} or {@link ActiveProfiles#value}. * @param testClass the test class for which the profiles should be resolved; * never {@code null} - * @return the list of bean definition profiles to use when loading the + * @return the bean definition profiles to use when loading the * {@code ApplicationContext}; never {@code null} */ @Override diff --git a/spring-test/src/main/java/org/springframework/test/context/support/TestConstructorUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/TestConstructorUtils.java index 017d14318b..0cf4aed962 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/TestConstructorUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/TestConstructorUtils.java @@ -163,7 +163,7 @@ public abstract class TestConstructorUtils { return true; } - AutowireMode autowireMode = null; + AutowireMode autowireMode; // Is the test class annotated with @TestConstructor? TestConstructor testConstructor = TestContextAnnotationUtils.findMergedAnnotation(testClass, TestConstructor.class); diff --git a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceAttributes.java b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceAttributes.java index 22efe9dd80..d37f4fc6b5 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceAttributes.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceAttributes.java @@ -73,7 +73,6 @@ class TestPropertySourceAttributes { private final boolean inheritProperties; - @SuppressWarnings("unchecked") TestPropertySourceAttributes(MergedAnnotation mergedAnnotation) { this.declaringClass = declaringClass(mergedAnnotation); this.rootAnnotation = mergedAnnotation.getRoot(); diff --git a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java index bdb3c11770..7cf10ab174 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java @@ -79,7 +79,7 @@ public abstract class TestPropertySourceUtils { private static final PropertySourceFactory defaultPropertySourceFactory = new DefaultPropertySourceFactory(); - private static Comparator> reversedMetaDistance = + private static final Comparator> reversedMetaDistance = Comparator.> comparingInt(MergedAnnotation::getDistance).reversed(); private static final Log logger = LogFactory.getLog(TestPropertySourceUtils.class); diff --git a/spring-test/src/main/java/org/springframework/test/context/web/AbstractGenericWebContextLoader.java b/spring-test/src/main/java/org/springframework/test/context/web/AbstractGenericWebContextLoader.java index 8874d5f15a..1ed791f9a4 100644 --- a/spring-test/src/main/java/org/springframework/test/context/web/AbstractGenericWebContextLoader.java +++ b/spring-test/src/main/java/org/springframework/test/context/web/AbstractGenericWebContextLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -190,7 +190,7 @@ public abstract class AbstractGenericWebContextLoader extends AbstractContextLoa * @see org.springframework.test.context.SmartContextLoader#loadContext(MergedContextConfiguration) * @see org.springframework.test.context.aot.AotContextLoader#loadContextForAotProcessing(MergedContextConfiguration) */ - private final GenericWebApplicationContext loadContext( + private GenericWebApplicationContext loadContext( MergedContextConfiguration mergedConfig, boolean forAotProcessing) throws Exception { if (!(mergedConfig instanceof WebMergedContextConfiguration webMergedConfig)) {