Skip to content

Using spring @ContextHierarchy to manage multiple @ContextConfiguration's breaks with 1.1.5 #590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextHierarchy;
import org.springframework.test.context.TestContextManager;

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

private boolean dependsOnSpringContext(Class<?> type) {
return type.isAnnotationPresent(ContextConfiguration.class);
return type.isAnnotationPresent(ContextConfiguration.class)
|| type.isAnnotationPresent(ContextHierarchy.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ public void shouldRespectCommonAnnotationsInStepDefs() {
assertTrue(stepdef.isAutowired());
}

@Test
public void shouldRespectContextHierarchyInStepDefs() {
final ObjectFactory factory = new SpringFactory();
factory.addClass(WithContextHierarchyAnnotation.class);
factory.start();
WithContextHierarchyAnnotation stepdef = factory.getInstance(WithContextHierarchyAnnotation.class);
factory.stop();

assertNotNull(stepdef);
assertTrue(stepdef.isAutowired());
}

@Test
public void shouldRespectDirtiesContextAnnotationsInStepDefs() {
final ObjectFactory factory = new SpringFactory();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cucumber.runtime.java.spring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextHierarchy;

@ContextHierarchy(@ContextConfiguration("classpath:cucumber.xml"))
public class WithContextHierarchyAnnotation {

private boolean autowired;

@Autowired
public void setAutowiredCollaborator(DummyComponent collaborator) {
autowired = true;
}

public boolean isAutowired() {
return autowired;
}

}