mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Use uppercase for classpath-related static final field names
Closes gh-35525
This commit is contained in:
@@ -60,7 +60,7 @@ public abstract class BootstrapUtils {
|
||||
private static final String WEB_APP_CONFIGURATION_ANNOTATION_CLASS_NAME =
|
||||
"org.springframework.test.context.web.WebAppConfiguration";
|
||||
|
||||
private static final Class<? extends Annotation> webAppConfigurationClass = loadWebAppConfigurationClass();
|
||||
private static final Class<? extends Annotation> WEB_APP_CONFIGURATION_CLASS = loadWebAppConfigurationClass();
|
||||
|
||||
private static final Log logger = LogFactory.getLog(BootstrapUtils.class);
|
||||
|
||||
@@ -196,7 +196,7 @@ public abstract class BootstrapUtils {
|
||||
}
|
||||
|
||||
private static Class<?> resolveDefaultTestContextBootstrapper(Class<?> testClass) throws Exception {
|
||||
boolean webApp = TestContextAnnotationUtils.hasAnnotation(testClass, webAppConfigurationClass);
|
||||
boolean webApp = TestContextAnnotationUtils.hasAnnotation(testClass, WEB_APP_CONFIGURATION_CLASS);
|
||||
String bootstrapperClassName = (webApp ? DEFAULT_WEB_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME :
|
||||
DEFAULT_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME);
|
||||
return ClassUtils.forName(bootstrapperClassName, BootstrapUtils.class.getClassLoader());
|
||||
|
||||
+3
-3
@@ -57,7 +57,7 @@ class MergedContextConfigurationRuntimeHints {
|
||||
|
||||
private static final String GET_RESOURCE_BASE_PATH_METHOD_NAME = "getResourceBasePath";
|
||||
|
||||
private static final Class<?> webMergedContextConfigurationClass = loadWebMergedContextConfigurationClass();
|
||||
private static final Class<?> WEB_MERGED_CONTEXT_CONFIGURATION_CLASS = loadWebMergedContextConfigurationClass();
|
||||
|
||||
private static final Method getResourceBasePathMethod = loadGetResourceBasePathMethod();
|
||||
|
||||
@@ -90,7 +90,7 @@ class MergedContextConfigurationRuntimeHints {
|
||||
}
|
||||
|
||||
// @WebAppConfiguration(value = ...)
|
||||
if (webMergedContextConfigurationClass.isInstance(mergedConfig)) {
|
||||
if (WEB_MERGED_CONTEXT_CONFIGURATION_CLASS.isInstance(mergedConfig)) {
|
||||
String resourceBasePath;
|
||||
try {
|
||||
resourceBasePath = (String) getResourceBasePathMethod.invoke(mergedConfig);
|
||||
@@ -162,7 +162,7 @@ class MergedContextConfigurationRuntimeHints {
|
||||
|
||||
private static Method loadGetResourceBasePathMethod() {
|
||||
try {
|
||||
return webMergedContextConfigurationClass.getMethod(GET_RESOURCE_BASE_PATH_METHOD_NAME);
|
||||
return WEB_MERGED_CONTEXT_CONFIGURATION_CLASS.getMethod(GET_RESOURCE_BASE_PATH_METHOD_NAME);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(
|
||||
|
||||
+5
-5
@@ -63,17 +63,17 @@ public class MockitoResetTestExecutionListener extends AbstractTestExecutionList
|
||||
* @see #mockitoInitialized
|
||||
* @see #isEnabled()
|
||||
*/
|
||||
private static final boolean mockitoPresent = ClassUtils.isPresent("org.mockito.Mockito",
|
||||
private static final boolean MOCKITO_PRESENT = ClassUtils.isPresent("org.mockito.Mockito",
|
||||
MockitoResetTestExecutionListener.class.getClassLoader());
|
||||
|
||||
/**
|
||||
* Boolean flag which tracks whether Mockito has been successfully initialized
|
||||
* in the current environment.
|
||||
* <p>Even if {@link #mockitoPresent} evaluates to {@code true}, this flag
|
||||
* <p>Even if {@link #MOCKITO_PRESENT} evaluates to {@code true}, this flag
|
||||
* may eventually evaluate to {@code false} — for example, in a GraalVM
|
||||
* native image if the necessary reachability metadata has not been registered
|
||||
* for the {@link org.mockito.plugins.MockMaker} in use.
|
||||
* @see #mockitoPresent
|
||||
* @see #MOCKITO_PRESENT
|
||||
* @see #isEnabled()
|
||||
*/
|
||||
private static volatile @Nullable Boolean mockitoInitialized;
|
||||
@@ -158,11 +158,11 @@ public class MockitoResetTestExecutionListener extends AbstractTestExecutionList
|
||||
|
||||
/**
|
||||
* Determine if this listener is enabled in the current environment.
|
||||
* @see #mockitoPresent
|
||||
* @see #MOCKITO_PRESENT
|
||||
* @see #mockitoInitialized
|
||||
*/
|
||||
private static boolean isEnabled() {
|
||||
if (!mockitoPresent) {
|
||||
if (!MOCKITO_PRESENT) {
|
||||
return false;
|
||||
}
|
||||
Boolean enabled = mockitoInitialized;
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ class MockitoSpyBeanOverrideHandler extends AbstractMockitoBeanOverrideHandler {
|
||||
if (StringUtils.hasLength(name)) {
|
||||
settings.name(name);
|
||||
}
|
||||
if (SpringMockResolver.springAopPresent) {
|
||||
if (SpringMockResolver.SPRING_AOP_PRESENT) {
|
||||
settings.verificationStartedListeners(verificationStartedListener);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -37,13 +37,13 @@ import org.springframework.util.ClassUtils;
|
||||
*/
|
||||
public class SpringMockResolver implements MockResolver {
|
||||
|
||||
static final boolean springAopPresent = ClassUtils.isPresent(
|
||||
static final boolean SPRING_AOP_PRESENT = ClassUtils.isPresent(
|
||||
"org.springframework.aop.framework.Advised", SpringMockResolver.class.getClassLoader());
|
||||
|
||||
|
||||
@Override
|
||||
public Object resolve(Object instance) {
|
||||
if (springAopPresent) {
|
||||
if (SPRING_AOP_PRESENT) {
|
||||
return getUltimateTargetObject(instance);
|
||||
}
|
||||
return instance;
|
||||
|
||||
+2
-2
@@ -39,7 +39,7 @@ public class DelegatingSmartContextLoader extends AbstractDelegatingSmartContext
|
||||
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",
|
||||
private static final boolean GROOVY_PRESENT = ClassUtils.isPresent("groovy.lang.Closure",
|
||||
DelegatingSmartContextLoader.class.getClassLoader()) &&
|
||||
ClassUtils.isPresent(GROOVY_XML_CONTEXT_LOADER_CLASS_NAME,
|
||||
DelegatingSmartContextLoader.class.getClassLoader());
|
||||
@@ -50,7 +50,7 @@ public class DelegatingSmartContextLoader extends AbstractDelegatingSmartContext
|
||||
|
||||
|
||||
public DelegatingSmartContextLoader() {
|
||||
if (groovyPresent) {
|
||||
if (GROOVY_PRESENT) {
|
||||
try {
|
||||
Class<?> loaderClass = ClassUtils.forName(GROOVY_XML_CONTEXT_LOADER_CLASS_NAME,
|
||||
DelegatingSmartContextLoader.class.getClassLoader());
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ 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",
|
||||
private static final boolean GROOVY_PRESENT = ClassUtils.isPresent("groovy.lang.Closure",
|
||||
WebDelegatingSmartContextLoader.class.getClassLoader()) &&
|
||||
ClassUtils.isPresent(GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME,
|
||||
WebDelegatingSmartContextLoader.class.getClassLoader());
|
||||
@@ -48,7 +48,7 @@ public class WebDelegatingSmartContextLoader extends AbstractDelegatingSmartCont
|
||||
|
||||
|
||||
public WebDelegatingSmartContextLoader() {
|
||||
if (groovyPresent) {
|
||||
if (GROOVY_PRESENT) {
|
||||
try {
|
||||
Class<?> loaderClass = ClassUtils.forName(GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME,
|
||||
WebDelegatingSmartContextLoader.class.getClassLoader());
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ import org.springframework.util.ClassUtils;
|
||||
*/
|
||||
class MockServerContainerContextCustomizerFactory implements ContextCustomizerFactory {
|
||||
|
||||
private static final boolean webSocketPresent = ClassUtils.isPresent("jakarta.websocket.server.ServerContainer",
|
||||
private static final boolean WEB_SOCKET_PRESENT = ClassUtils.isPresent("jakarta.websocket.server.ServerContainer",
|
||||
MockServerContainerContextCustomizerFactory.class.getClassLoader());
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class MockServerContainerContextCustomizerFactory implements ContextCustomizerFa
|
||||
public @Nullable ContextCustomizer createContextCustomizer(Class<?> testClass,
|
||||
List<ContextConfigurationAttributes> configAttributes) {
|
||||
|
||||
if (webSocketPresent && isAnnotatedWithWebAppConfiguration(testClass)) {
|
||||
if (WEB_SOCKET_PRESENT && isAnnotatedWithWebAppConfiguration(testClass)) {
|
||||
return new MockServerContainerContextCustomizer();
|
||||
}
|
||||
// Else, nothing to customize
|
||||
|
||||
@@ -75,7 +75,7 @@ public abstract class ReflectionTestUtils {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ReflectionTestUtils.class);
|
||||
|
||||
private static final boolean springAopPresent = ClassUtils.isPresent(
|
||||
private static final boolean SPRING_AOP_PRESENT = ClassUtils.isPresent(
|
||||
"org.springframework.aop.framework.Advised", ReflectionTestUtils.class.getClassLoader());
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ public abstract class ReflectionTestUtils {
|
||||
Assert.isTrue(targetObject != null || targetClass != null,
|
||||
"Either targetObject or targetClass for the field must be specified");
|
||||
|
||||
if (targetObject != null && springAopPresent) {
|
||||
if (targetObject != null && SPRING_AOP_PRESENT) {
|
||||
targetObject = AopTestUtils.getUltimateTargetObject(targetObject);
|
||||
}
|
||||
if (targetClass == null) {
|
||||
@@ -263,7 +263,7 @@ public abstract class ReflectionTestUtils {
|
||||
Assert.isTrue(targetObject != null || targetClass != null,
|
||||
"Either targetObject or targetClass for the field must be specified");
|
||||
|
||||
if (targetObject != null && springAopPresent) {
|
||||
if (targetObject != null && SPRING_AOP_PRESENT) {
|
||||
targetObject = AopTestUtils.getUltimateTargetObject(targetObject);
|
||||
}
|
||||
if (targetClass == null) {
|
||||
@@ -352,7 +352,7 @@ public abstract class ReflectionTestUtils {
|
||||
safeToString(target), value));
|
||||
}
|
||||
|
||||
if (springAopPresent) {
|
||||
if (SPRING_AOP_PRESENT) {
|
||||
// If the target is a CGLIB proxy which does not intercept the method, invoke the
|
||||
// method on the ultimate target.
|
||||
if (isCglibProxyThatDoesNotInterceptMethod(target, method)) {
|
||||
@@ -406,7 +406,7 @@ public abstract class ReflectionTestUtils {
|
||||
"Could not find getter method '%s' on %s", getterMethodName, safeToString(target)));
|
||||
}
|
||||
|
||||
if (springAopPresent) {
|
||||
if (SPRING_AOP_PRESENT) {
|
||||
// If the target is a CGLIB proxy which does not intercept the method, invoke the
|
||||
// method on the ultimate target.
|
||||
if (isCglibProxyThatDoesNotInterceptMethod(target, method)) {
|
||||
@@ -500,7 +500,7 @@ public abstract class ReflectionTestUtils {
|
||||
methodInvoker.setArguments(args);
|
||||
methodInvoker.prepare();
|
||||
|
||||
if (targetObject != null && springAopPresent) {
|
||||
if (targetObject != null && SPRING_AOP_PRESENT) {
|
||||
// If the target is a CGLIB proxy which does not intercept the method, invoke the
|
||||
// method on the ultimate target.
|
||||
if (isCglibProxyThatDoesNotInterceptMethod(targetObject, methodInvoker.getPreparedMethod())) {
|
||||
|
||||
+12
-12
@@ -56,22 +56,22 @@ import org.springframework.web.util.UriBuilderFactory;
|
||||
*/
|
||||
class DefaultWebTestClientBuilder implements WebTestClient.Builder {
|
||||
|
||||
private static final boolean reactorNettyClientPresent;
|
||||
private static final boolean REACTOR_NETTY_CLIENT_PRESENT;
|
||||
|
||||
private static final boolean jettyClientPresent;
|
||||
private static final boolean JETTY_CLIENT_PRESENT;
|
||||
|
||||
private static final boolean httpComponentsClientPresent;
|
||||
private static final boolean HTTP_COMPONENTS_CLIENT_PRESENT;
|
||||
|
||||
private static final boolean webFluxPresent;
|
||||
private static final boolean WEB_FLUX_PRESENT;
|
||||
|
||||
static {
|
||||
ClassLoader loader = DefaultWebTestClientBuilder.class.getClassLoader();
|
||||
reactorNettyClientPresent = ClassUtils.isPresent("reactor.netty.http.client.HttpClient", loader);
|
||||
jettyClientPresent = ClassUtils.isPresent("org.eclipse.jetty.client.HttpClient", loader);
|
||||
httpComponentsClientPresent =
|
||||
REACTOR_NETTY_CLIENT_PRESENT = ClassUtils.isPresent("reactor.netty.http.client.HttpClient", loader);
|
||||
JETTY_CLIENT_PRESENT = ClassUtils.isPresent("org.eclipse.jetty.client.HttpClient", loader);
|
||||
HTTP_COMPONENTS_CLIENT_PRESENT =
|
||||
ClassUtils.isPresent("org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient", loader) &&
|
||||
ClassUtils.isPresent("org.apache.hc.core5.reactive.ReactiveDataConsumer", loader);
|
||||
webFluxPresent = ClassUtils.isPresent(
|
||||
WEB_FLUX_PRESENT = ClassUtils.isPresent(
|
||||
"org.springframework.web.reactive.function.client.ExchangeFunction", loader);
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder {
|
||||
"Expected WebHttpHandlerBuilder or ClientHttpConnector but not both.");
|
||||
|
||||
// Helpful message especially for MockMvcWebTestClient users
|
||||
Assert.state(webFluxPresent,
|
||||
Assert.state(WEB_FLUX_PRESENT,
|
||||
"To use WebTestClient, please add spring-webflux to the test classpath.");
|
||||
|
||||
this.connector = connector;
|
||||
@@ -312,13 +312,13 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder {
|
||||
}
|
||||
|
||||
private static ClientHttpConnector initConnector() {
|
||||
if (reactorNettyClientPresent) {
|
||||
if (REACTOR_NETTY_CLIENT_PRESENT) {
|
||||
return new ReactorClientHttpConnector();
|
||||
}
|
||||
else if (jettyClientPresent) {
|
||||
else if (JETTY_CLIENT_PRESENT) {
|
||||
return new JettyClientHttpConnector();
|
||||
}
|
||||
else if (httpComponentsClientPresent) {
|
||||
else if (HTTP_COMPONENTS_CLIENT_PRESENT) {
|
||||
return new HttpComponentsClientHttpConnector();
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user