|
1 | 1 | package cucumber.runtime.java.spring;
|
2 | 2 |
|
3 |
| -import cucumber.runtime.CucumberException; |
| 3 | +import static org.springframework.test.context.FixBootstrapUtils.createBootstrapContext; |
| 4 | +import static org.springframework.test.context.FixBootstrapUtils.resolveTestContextBootstrapper; |
| 5 | + |
4 | 6 | import cucumber.api.java.ObjectFactory;
|
| 7 | +import cucumber.runtime.CucumberException; |
5 | 8 | import org.springframework.beans.BeansException;
|
6 | 9 | import org.springframework.beans.factory.config.BeanDefinition;
|
7 | 10 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
@@ -75,20 +78,20 @@ private void checkAnnotationsEqual(Class<?> stepClassWithSpringContext, Class<?>
|
75 | 78 | Annotation[] annotations2 = stepClass.getAnnotations();
|
76 | 79 | if (annotations1.length != annotations2.length) {
|
77 | 80 | throw new CucumberException("Annotations differs on glue classes found: " +
|
78 |
| - stepClassWithSpringContext.getName() + ", " + |
79 |
| - stepClass.getName()); |
| 81 | + stepClassWithSpringContext.getName() + ", " + |
| 82 | + stepClass.getName()); |
80 | 83 | }
|
81 | 84 | for (Annotation annotation : annotations1) {
|
82 | 85 | if (!isAnnotationInArray(annotation, annotations2)) {
|
83 | 86 | throw new CucumberException("Annotations differs on glue classes found: " +
|
84 |
| - stepClassWithSpringContext.getName() + ", " + |
85 |
| - stepClass.getName()); |
| 87 | + stepClassWithSpringContext.getName() + ", " + |
| 88 | + stepClass.getName()); |
86 | 89 | }
|
87 | 90 | }
|
88 | 91 | }
|
89 | 92 |
|
90 | 93 | private boolean isAnnotationInArray(Annotation annotation, Annotation[] annotations) {
|
91 |
| - for (Annotation annotationFromArray: annotations) { |
| 94 | + for (Annotation annotationFromArray : annotations) { |
92 | 95 | if (annotation.equals(annotationFromArray)) {
|
93 | 96 | return true;
|
94 | 97 | }
|
@@ -152,9 +155,9 @@ private boolean isNewContextCreated() {
|
152 | 155 | private void registerStepClassBeanDefinition(ConfigurableListableBeanFactory beanFactory, Class<?> stepClass) {
|
153 | 156 | BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
|
154 | 157 | BeanDefinition beanDefinition = BeanDefinitionBuilder
|
155 |
| - .genericBeanDefinition(stepClass) |
156 |
| - .setScope(GlueCodeScope.NAME) |
157 |
| - .getBeanDefinition(); |
| 158 | + .genericBeanDefinition(stepClass) |
| 159 | + .setScope(GlueCodeScope.NAME) |
| 160 | + .getBeanDefinition(); |
158 | 161 | registry.registerBeanDefinition(stepClass.getName(), beanDefinition);
|
159 | 162 | }
|
160 | 163 |
|
@@ -200,25 +203,28 @@ private boolean annotatedWithSupportedSpringRootTestAnnotations(Class<?> type) {
|
200 | 203 | }
|
201 | 204 | }
|
202 | 205 |
|
| 206 | + |
203 | 207 | class CucumberTestContextManager extends TestContextManager {
|
204 | 208 |
|
205 |
| - public CucumberTestContextManager(Class<?> testClass) { |
206 |
| - super(testClass); |
| 209 | + CucumberTestContextManager(Class<?> testClass) { |
| 210 | + // Does the same as TestContextManager(Class<?>) but creates a |
| 211 | + // DefaultCacheAwareContextLoaderDelegate that does not use a static contextCache. |
| 212 | + super(resolveTestContextBootstrapper(createBootstrapContext(testClass))); |
207 | 213 | registerGlueCodeScope(getContext());
|
208 | 214 | }
|
209 | 215 |
|
210 |
| - public ConfigurableListableBeanFactory getBeanFactory() { |
| 216 | + ConfigurableListableBeanFactory getBeanFactory() { |
211 | 217 | return getContext().getBeanFactory();
|
212 | 218 | }
|
213 | 219 |
|
214 | 220 | private ConfigurableApplicationContext getContext() {
|
215 |
| - return (ConfigurableApplicationContext)getTestContext().getApplicationContext(); |
| 221 | + return (ConfigurableApplicationContext) getTestContext().getApplicationContext(); |
216 | 222 | }
|
217 | 223 |
|
218 | 224 | private void registerGlueCodeScope(ConfigurableApplicationContext context) {
|
219 | 225 | do {
|
220 | 226 | context.getBeanFactory().registerScope(GlueCodeScope.NAME, new GlueCodeScope());
|
221 |
| - context = (ConfigurableApplicationContext)context.getParent(); |
| 227 | + context = (ConfigurableApplicationContext) context.getParent(); |
222 | 228 | } while (context != null);
|
223 | 229 | }
|
224 | 230 | }
|
0 commit comments