Skip to content

Commit e4741b8

Browse files
committed
SpringExtension.getApplicationContext declared as public
Issue: SPR-15340
1 parent e999da0 commit e4741b8

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

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

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -61,10 +61,10 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes
6161
ParameterResolver {
6262

6363
/**
64-
* {@link Namespace} in which {@code TestContextManagers} are stored, keyed
65-
* by test class.
64+
* {@link Namespace} in which {@code TestContextManagers} are stored,
65+
* keyed by test class.
6666
*/
67-
private static final Namespace namespace = Namespace.create(SpringExtension.class);
67+
private static final Namespace NAMESPACE = Namespace.create(SpringExtension.class);
6868

6969

7070
/**
@@ -84,7 +84,7 @@ public void afterAll(ContainerExtensionContext context) throws Exception {
8484
getTestContextManager(context).afterTestClass();
8585
}
8686
finally {
87-
context.getStore(namespace).remove(context.getTestClass().get());
87+
context.getStore(NAMESPACE).remove(context.getTestClass().get());
8888
}
8989
}
9090

@@ -139,32 +139,30 @@ public void afterEach(TestExtensionContext context) throws Exception {
139139
}
140140

141141
/**
142-
* Determine if the value for the {@link Parameter} in the supplied
143-
* {@link ParameterContext} should be autowired from the test's
144-
* {@link ApplicationContext}.
142+
* Determine if the value for the {@link Parameter} in the supplied {@link ParameterContext}
143+
* should be autowired from the test's {@link ApplicationContext}.
145144
* <p>Returns {@code true} if the parameter is declared in a {@link Constructor}
146-
* that is annotated with {@link Autowired @Autowired} and otherwise delegates
147-
* to {@link ParameterAutowireUtils#isAutowirable}.
148-
* <p><strong>WARNING</strong>: if the parameter is declared in a {@code Constructor}
145+
* that is annotated with {@link Autowired @Autowired} and otherwise delegates to
146+
* {@link ParameterAutowireUtils#isAutowirable}.
147+
* <p><strong>WARNING</strong>: If the parameter is declared in a {@code Constructor}
149148
* that is annotated with {@code @Autowired}, Spring will assume the responsibility
150-
* for resolving all parameters in the constructor. Consequently, no other
151-
* registered {@link ParameterResolver} will be able to resolve parameters.
152-
*
149+
* for resolving all parameters in the constructor. Consequently, no other registered
150+
* {@link ParameterResolver} will be able to resolve parameters.
153151
* @see #resolve
154152
* @see ParameterAutowireUtils#isAutowirable
155153
*/
156154
@Override
157155
public boolean supports(ParameterContext parameterContext, ExtensionContext extensionContext) {
158156
Parameter parameter = parameterContext.getParameter();
159157
Executable executable = parameter.getDeclaringExecutable();
160-
return (executable instanceof Constructor && AnnotatedElementUtils.hasAnnotation(executable, Autowired.class))
161-
|| ParameterAutowireUtils.isAutowirable(parameter);
158+
return (executable instanceof Constructor &&
159+
AnnotatedElementUtils.hasAnnotation(executable, Autowired.class)) ||
160+
ParameterAutowireUtils.isAutowirable(parameter);
162161
}
163162

164163
/**
165-
* Resolve a value for the {@link Parameter} in the supplied
166-
* {@link ParameterContext} by retrieving the corresponding dependency
167-
* from the test's {@link ApplicationContext}.
164+
* Resolve a value for the {@link Parameter} in the supplied {@link ParameterContext} by
165+
* retrieving the corresponding dependency from the test's {@link ApplicationContext}.
168166
* <p>Delegates to {@link ParameterAutowireUtils#resolveDependency}.
169167
* @see #supports
170168
* @see ParameterAutowireUtils#resolveDependency
@@ -177,28 +175,26 @@ public Object resolve(ParameterContext parameterContext, ExtensionContext extens
177175
return ParameterAutowireUtils.resolveDependency(parameter, testClass, applicationContext);
178176
}
179177

178+
180179
/**
181-
* Get the {@link ApplicationContext} associated with the supplied
182-
* {@code ExtensionContext}.
183-
* @param context the current {@code ExtensionContext}; never {@code null}
180+
* Get the {@link ApplicationContext} associated with the supplied {@code ExtensionContext}.
181+
* @param context the current {@code ExtensionContext} (never {@code null})
184182
* @return the application context
185-
* @throws IllegalStateException if an error occurs while retrieving the
186-
* application context
183+
* @throws IllegalStateException if an error occurs while retrieving the application context
187184
* @see org.springframework.test.context.TestContext#getApplicationContext()
188185
*/
189-
static ApplicationContext getApplicationContext(ExtensionContext context) {
186+
public static ApplicationContext getApplicationContext(ExtensionContext context) {
190187
return getTestContextManager(context).getTestContext().getApplicationContext();
191188
}
192189

193190
/**
194-
* Get the {@link TestContextManager} associated with the supplied
195-
* {@code ExtensionContext}.
196-
* @return the {@code TestContextManager}; never {@code null}
191+
* Get the {@link TestContextManager} associated with the supplied {@code ExtensionContext}.
192+
* @return the {@code TestContextManager} (never {@code null})
197193
*/
198194
private static TestContextManager getTestContextManager(ExtensionContext context) {
199195
Assert.notNull(context, "ExtensionContext must not be null");
200196
Class<?> testClass = context.getTestClass().get();
201-
Store store = context.getStore(namespace);
197+
Store store = context.getStore(NAMESPACE);
202198
return store.getOrComputeIfAbsent(testClass, TestContextManager::new, TestContextManager.class);
203199
}
204200

0 commit comments

Comments
 (0)