Skip to content

Commit 2e27783

Browse files
author
Dmytro Chyzhykov
committed
Merge pull request cucumber#590 from martinlau/master
Using spring @ContextHierarchy to manage multiple @ContextConfiguration's breaks with 1.1.5
2 parents 976111f + 603a138 commit 2e27783

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

spring/src/main/java/cucumber/runtime/java/spring/SpringFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.springframework.context.ConfigurableApplicationContext;
1515
import org.springframework.context.support.GenericXmlApplicationContext;
1616
import org.springframework.test.context.ContextConfiguration;
17+
import org.springframework.test.context.ContextHierarchy;
1718
import org.springframework.test.context.TestContextManager;
1819

1920
import cucumber.runtime.CucumberException;
@@ -168,6 +169,7 @@ protected <T> T createTest(Class<T> type) throws Exception {
168169
}
169170

170171
private boolean dependsOnSpringContext(Class<?> type) {
171-
return type.isAnnotationPresent(ContextConfiguration.class);
172+
return type.isAnnotationPresent(ContextConfiguration.class)
173+
|| type.isAnnotationPresent(ContextHierarchy.class);
172174
}
173175
}

spring/src/test/java/cucumber/runtime/java/spring/SpringFactoryTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ public void shouldRespectCommonAnnotationsInStepDefs() {
6363
assertTrue(stepdef.isAutowired());
6464
}
6565

66+
@Test
67+
public void shouldRespectContextHierarchyInStepDefs() {
68+
final ObjectFactory factory = new SpringFactory();
69+
factory.addClass(WithContextHierarchyAnnotation.class);
70+
factory.start();
71+
WithContextHierarchyAnnotation stepdef = factory.getInstance(WithContextHierarchyAnnotation.class);
72+
factory.stop();
73+
74+
assertNotNull(stepdef);
75+
assertTrue(stepdef.isAutowired());
76+
}
77+
6678
@Test
6779
public void shouldRespectDirtiesContextAnnotationsInStepDefs() {
6880
final ObjectFactory factory = new SpringFactory();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cucumber.runtime.java.spring;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.beans.factory.annotation.Value;
5+
import org.springframework.test.context.ContextConfiguration;
6+
import org.springframework.test.context.ContextHierarchy;
7+
8+
@ContextHierarchy(@ContextConfiguration("classpath:cucumber.xml"))
9+
public class WithContextHierarchyAnnotation {
10+
11+
private boolean autowired;
12+
13+
@Autowired
14+
public void setAutowiredCollaborator(DummyComponent collaborator) {
15+
autowired = true;
16+
}
17+
18+
public boolean isAutowired() {
19+
return autowired;
20+
}
21+
22+
}

0 commit comments

Comments
 (0)