File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed
main/java/cucumber/runtime/java/spring
test/java/cucumber/runtime/java/spring Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 14
14
import org .springframework .context .ConfigurableApplicationContext ;
15
15
import org .springframework .context .support .GenericXmlApplicationContext ;
16
16
import org .springframework .test .context .ContextConfiguration ;
17
+ import org .springframework .test .context .ContextHierarchy ;
17
18
import org .springframework .test .context .TestContextManager ;
18
19
19
20
import cucumber .runtime .CucumberException ;
@@ -168,6 +169,7 @@ protected <T> T createTest(Class<T> type) throws Exception {
168
169
}
169
170
170
171
private boolean dependsOnSpringContext (Class <?> type ) {
171
- return type .isAnnotationPresent (ContextConfiguration .class );
172
+ return type .isAnnotationPresent (ContextConfiguration .class )
173
+ || type .isAnnotationPresent (ContextHierarchy .class );
172
174
}
173
175
}
Original file line number Diff line number Diff line change @@ -63,6 +63,18 @@ public void shouldRespectCommonAnnotationsInStepDefs() {
63
63
assertTrue (stepdef .isAutowired ());
64
64
}
65
65
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
+
66
78
@ Test
67
79
public void shouldRespectDirtiesContextAnnotationsInStepDefs () {
68
80
final ObjectFactory factory = new SpringFactory ();
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments