Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mpkorstanje committed Dec 11, 2022
1 parent fad415e commit 74efc89
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ public final void start() {
notifyTestContextManagerAboutBeforeExecution();
}

private void startCucumberTestContext() {
CucumberTestContext.getInstance().start();
}


private void notifyContextManagerAboutBeforeTestClass() {
try {
delegate.beforeTestClass();
Expand All @@ -73,13 +68,8 @@ private void notifyContextManagerAboutBeforeTestClass() {
}
}

private void notifyTestContextManagerAboutBeforeTestMethod() {
try {
Method dummyMethod = getDummyMethod();
delegate.beforeTestMethod(delegateTestInstance, dummyMethod);
} catch (Exception e) {
throw new CucumberBackendException(e.getMessage(), e);
}
private void startCucumberTestContext() {
CucumberTestContext.getInstance().start();
}

private void createAndPrepareTestInstance() {
Expand All @@ -103,14 +93,24 @@ private void createAndPrepareTestInstance() {
// into other step definition classes.
try {
Class<?> delegateTestClass = delegate.getTestContext().getTestClass();
Object delegateTestInstance = applicationContext.getBeanFactory().autowire(delegateTestClass, AUTOWIRE_NO, false);
Object delegateTestInstance = applicationContext.getBeanFactory().autowire(delegateTestClass, AUTOWIRE_NO,
false);
delegate.prepareTestInstance(delegateTestInstance);
this.delegateTestInstance = delegateTestInstance;
} catch (Exception e) {
throw new CucumberBackendException(e.getMessage(), e);
}
}

private void notifyTestContextManagerAboutBeforeTestMethod() {
try {
Method dummyMethod = getDummyMethod();
delegate.beforeTestMethod(delegateTestInstance, dummyMethod);
} catch (Exception e) {
throw new CucumberBackendException(e.getMessage(), e);
}
}

private void registerGlueCodeScope(ConfigurableApplicationContext context) {
while (context != null) {
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
Expand Down Expand Up @@ -153,6 +153,9 @@ private void registerStepClassBeanDefinition(BeanDefinitionRegistry registry, Cl
}

public final void stop() {
// Cucumber only supports 1 set of before/after semantics while JUnit
// and Spring have 2 sets. So here we use a stack to ensure we don't
// invoke only the matching after methods for each before methods.
CucumberBackendException lastException = null;
for (Runnable stopInvocation : stopInvocations) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public class TestTestContextAdaptorTest {
TestExecutionListener listener;

@AfterEach
void verifyNoMoroInteractions(){
void verifyNoMoroInteractions() {
Mockito.verifyNoMoreInteractions(listener);
}

@Test
void invokesAllLiveCycleHooks() throws Exception {
TestContextManager manager = new TestContextManager(SpringContextConfiguration.class);
TestContextAdaptor adaptor = new TestContextAdaptor(manager, singletonList(SpringContextConfiguration.class));
TestContextManager manager = new TestContextManager(SomeContextConfiguration.class);
TestContextAdaptor adaptor = new TestContextAdaptor(manager, singletonList(SomeContextConfiguration.class));
manager.registerTestExecutionListeners(listener);
InOrder inOrder = inOrder(listener);

Expand All @@ -42,7 +42,6 @@ void invokesAllLiveCycleHooks() throws Exception {
inOrder.verify(listener).beforeTestMethod(any());
inOrder.verify(listener).beforeTestExecution(any());


adaptor.stop();
inOrder.verify(listener).afterTestExecution(any());
inOrder.verify(listener).afterTestMethod(any());
Expand All @@ -51,8 +50,8 @@ void invokesAllLiveCycleHooks() throws Exception {

@Test
void invokesAfterClassIfBeforeClassFailed() throws Exception {
TestContextManager manager = new TestContextManager(SpringContextConfiguration.class);
TestContextAdaptor adaptor = new TestContextAdaptor(manager, singletonList(SpringContextConfiguration.class));
TestContextManager manager = new TestContextManager(SomeContextConfiguration.class);
TestContextAdaptor adaptor = new TestContextAdaptor(manager, singletonList(SomeContextConfiguration.class));
manager.registerTestExecutionListeners(listener);
InOrder inOrder = inOrder(listener);

Expand All @@ -65,11 +64,10 @@ void invokesAfterClassIfBeforeClassFailed() throws Exception {
inOrder.verify(listener).afterTestClass(any());
}


@Test
void invokesAfterClassIfPrepareTestInstanceFailed() throws Exception {
TestContextManager manager = new TestContextManager(SpringContextConfiguration.class);
TestContextAdaptor adaptor = new TestContextAdaptor(manager, singletonList(SpringContextConfiguration.class));
TestContextManager manager = new TestContextManager(SomeContextConfiguration.class);
TestContextAdaptor adaptor = new TestContextAdaptor(manager, singletonList(SomeContextConfiguration.class));
manager.registerTestExecutionListeners(listener);
InOrder inOrder = inOrder(listener);

Expand All @@ -82,11 +80,10 @@ void invokesAfterClassIfPrepareTestInstanceFailed() throws Exception {
inOrder.verify(listener).afterTestClass(any());
}


@Test
void invokesAfterMethodIfBeforeMethodThrows() throws Exception {
TestContextManager manager = new TestContextManager(SpringContextConfiguration.class);
TestContextAdaptor adaptor = new TestContextAdaptor(manager, singletonList(SpringContextConfiguration.class));
TestContextManager manager = new TestContextManager(SomeContextConfiguration.class);
TestContextAdaptor adaptor = new TestContextAdaptor(manager, singletonList(SomeContextConfiguration.class));
manager.registerTestExecutionListeners(listener);
InOrder inOrder = inOrder(listener);

Expand All @@ -104,8 +101,8 @@ void invokesAfterMethodIfBeforeMethodThrows() throws Exception {

@Test
void invokesAfterTestExecutionIfBeforeTestExecutionThrows() throws Exception {
TestContextManager manager = new TestContextManager(SpringContextConfiguration.class);
TestContextAdaptor adaptor = new TestContextAdaptor(manager, singletonList(SpringContextConfiguration.class));
TestContextManager manager = new TestContextManager(SomeContextConfiguration.class);
TestContextAdaptor adaptor = new TestContextAdaptor(manager, singletonList(SomeContextConfiguration.class));
manager.registerTestExecutionListeners(listener);
InOrder inOrder = inOrder(listener);

Expand All @@ -124,7 +121,7 @@ void invokesAfterTestExecutionIfBeforeTestExecutionThrows() throws Exception {

@CucumberContextConfiguration
@ContextConfiguration("classpath:cucumber.xml")
public static class SpringContextConfiguration {
public static class SomeContextConfiguration {

}

Expand Down

0 comments on commit 74efc89

Please sign in to comment.