diff --git a/cucumber-core/pom.xml b/cucumber-core/pom.xml
index 1e2e3b53e6..8376a8b54b 100644
--- a/cucumber-core/pom.xml
+++ b/cucumber-core/pom.xml
@@ -20,7 +20,6 @@
2.9.1
2.2
0.2
- 5.6.0
4.4.6
1.0.4
@@ -139,12 +138,6 @@
junit-jupiter
test
-
- org.mockito
- mockito-junit-jupiter
- ${mockito.version}
- test
-
io.vertx
vertx-web
diff --git a/cucumber-core/src/test/java/io/cucumber/core/runner/HookTest.java b/cucumber-core/src/test/java/io/cucumber/core/runner/HookTest.java
index eb0f1e3055..79b9f59a13 100644
--- a/cucumber-core/src/test/java/io/cucumber/core/runner/HookTest.java
+++ b/cucumber-core/src/test/java/io/cucumber/core/runner/HookTest.java
@@ -4,6 +4,8 @@
import io.cucumber.core.backend.Glue;
import io.cucumber.core.backend.HookDefinition;
import io.cucumber.core.backend.ObjectFactory;
+import io.cucumber.core.backend.Snippet;
+import io.cucumber.core.backend.TestCaseState;
import io.cucumber.core.eventbus.EventBus;
import io.cucumber.core.feature.TestFeatureParser;
import io.cucumber.core.gherkin.Feature;
@@ -12,21 +14,18 @@
import io.cucumber.core.runtime.TimeServiceEventBus;
import io.cucumber.core.snippets.TestSnippet;
import org.junit.jupiter.api.Test;
-import org.mockito.ArgumentMatchers;
-import org.mockito.InOrder;
+import java.net.URI;
import java.time.Clock;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.List;
import java.util.UUID;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertLinesMatch;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
class HookTest {
@@ -44,43 +43,23 @@ class HookTest {
*/
@Test
void after_hooks_execute_before_objects_are_disposed() {
- Backend backend = mock(Backend.class);
- when(backend.getSnippet()).thenReturn(new TestSnippet());
+ final List eventListener = new ArrayList<>();
+ final HookDefinition hook = new MockHookDefinition("", "hook-location", eventListener);
+ Backend backend = new StubBackend(hook, eventListener);
ObjectFactory objectFactory = new StubObjectFactory();
- final HookDefinition hook = mock(HookDefinition.class);
- when(hook.getLocation()).thenReturn("hook-location");
- when(hook.getTagExpression()).thenReturn("");
-
- doAnswer(invocation -> {
- Glue glue = invocation.getArgument(0);
- glue.addBeforeHook(hook);
- return null;
- }).when(backend).loadGlue(any(Glue.class), ArgumentMatchers.anyList());
-
Runner runner = new Runner(bus, Collections.singleton(backend), objectFactory, runtimeOptions);
runner.runPickle(pickle);
- InOrder inOrder = inOrder(hook, backend);
- inOrder.verify(backend).buildWorld();
- inOrder.verify(hook).execute(ArgumentMatchers.any());
- inOrder.verify(backend).disposeWorld();
+ assertLinesMatch(eventListener, List.of("buildWorld", "execute", "disposeWorld"));
}
@Test
void hook_throws_exception_with_name_when_tag_expression_is_invalid() {
- Backend backend = mock(Backend.class);
- when(backend.getSnippet()).thenReturn(new TestSnippet());
+ final List eventListener = new ArrayList<>();
+ final HookDefinition hook = new MockHookDefinition("(", "hook-location", eventListener);
+ Backend backend = new StubBackend(hook, eventListener);
ObjectFactory objectFactory = new StubObjectFactory();
- final HookDefinition hook = mock(HookDefinition.class);
- when(hook.getLocation()).thenReturn("hook-location");
- when(hook.getTagExpression()).thenReturn("(");
-
- doAnswer(invocation -> {
- Glue glue = invocation.getArgument(0);
- glue.addBeforeHook(hook);
- return null;
- }).when(backend).loadGlue(any(Glue.class), ArgumentMatchers.anyList());
RuntimeException e = assertThrows(RuntimeException.class,
() -> new Runner(bus, Collections.singleton(backend), objectFactory,
@@ -111,4 +90,71 @@ public void stop() {
}
}
+
+ private final static class StubBackend implements Backend {
+ private final HookDefinition beforeHook;
+ private final List eventListener;
+
+ public StubBackend(HookDefinition beforeHook, List eventListener) {
+ this.beforeHook = beforeHook;
+ this.eventListener = eventListener;
+ }
+
+ @Override
+ public void loadGlue(Glue glue, List gluePaths) {
+ glue.addBeforeHook(beforeHook);
+ }
+
+ @Override
+ public void buildWorld() {
+ eventListener.add("buildWorld");
+ }
+
+ @Override
+ public void disposeWorld() {
+ eventListener.add("disposeWorld");
+ }
+
+ @Override
+ public Snippet getSnippet() {
+ return new TestSnippet();
+ }
+ }
+
+ private static final class MockHookDefinition implements HookDefinition {
+ private final String tagExpression;
+ private final String location;
+ private final List eventListener;
+
+ public MockHookDefinition(String tagExpression, String location, List eventListener) {
+ this.tagExpression = tagExpression;
+ this.location = location;
+ this.eventListener = eventListener;
+ }
+
+ @Override
+ public void execute(TestCaseState state) {
+ eventListener.add("execute");
+ }
+
+ @Override
+ public String getTagExpression() {
+ return tagExpression;
+ }
+
+ @Override
+ public int getOrder() {
+ return 0;
+ }
+
+ @Override
+ public boolean isDefinedAt(StackTraceElement stackTraceElement) {
+ return false;
+ }
+
+ @Override
+ public String getLocation() {
+ return location;
+ }
+ }
}
diff --git a/cucumber-core/src/test/java/io/cucumber/core/runner/PickleStepTestStepTest.java b/cucumber-core/src/test/java/io/cucumber/core/runner/PickleStepTestStepTest.java
index 60e561bde9..2dee028fc8 100644
--- a/cucumber-core/src/test/java/io/cucumber/core/runner/PickleStepTestStepTest.java
+++ b/cucumber-core/src/test/java/io/cucumber/core/runner/PickleStepTestStepTest.java
@@ -1,28 +1,31 @@
package io.cucumber.core.runner;
+import io.cucumber.core.backend.HookDefinition;
import io.cucumber.core.backend.StubPendingException;
import io.cucumber.core.eventbus.EventBus;
import io.cucumber.core.feature.TestFeatureParser;
import io.cucumber.core.gherkin.Feature;
import io.cucumber.core.gherkin.Pickle;
+import io.cucumber.messages.types.Envelope;
+import io.cucumber.plugin.event.EventHandler;
import io.cucumber.plugin.event.Result;
import io.cucumber.plugin.event.Status;
import io.cucumber.plugin.event.TestCaseEvent;
import io.cucumber.plugin.event.TestStepFinished;
import io.cucumber.plugin.event.TestStepStarted;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.mockito.ArgumentCaptor;
-import org.mockito.ArgumentMatcher;
-import org.mockito.InOrder;
-import org.mockito.Mockito;
import org.opentest4j.TestAbortedException;
import java.net.URI;
import java.time.Instant;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Queue;
import java.util.UUID;
+import java.util.stream.Collectors;
import static io.cucumber.core.backend.Status.FAILED;
import static io.cucumber.core.backend.Status.PASSED;
@@ -30,7 +33,6 @@
import static io.cucumber.core.backend.Status.SKIPPED;
import static io.cucumber.plugin.event.HookType.AFTER_STEP;
import static io.cucumber.plugin.event.HookType.BEFORE_STEP;
-import static java.time.Duration.ZERO;
import static java.time.Duration.ofMillis;
import static java.time.Instant.ofEpochMilli;
import static java.util.Collections.singletonList;
@@ -38,17 +40,10 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.jupiter.api.Assertions.assertAll;
-import static org.mockito.ArgumentCaptor.forClass;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.argThat;
-import static org.mockito.ArgumentMatchers.isA;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
class PickleStepTestStepTest {
@@ -59,207 +54,239 @@ class PickleStepTestStepTest {
private final Pickle pickle = feature.getPickles().get(0);
private final TestCase testCase = new TestCase(UUID.randomUUID(), Collections.emptyList(), Collections.emptyList(),
Collections.emptyList(), pickle, false);
- private final EventBus bus = mock(EventBus.class);
- private final UUID testExecutionId = UUID.randomUUID();
- private final TestCaseState state = new TestCaseState(bus, testExecutionId, testCase);
- private final PickleStepDefinitionMatch definitionMatch = mock(PickleStepDefinitionMatch.class);
- private final CoreHookDefinition afterHookDefinition = mock(CoreHookDefinition.class);
- private final HookTestStep afterHook = new HookTestStep(UUID.randomUUID(), AFTER_STEP,
- new HookDefinitionMatch(afterHookDefinition));
- private final CoreHookDefinition beforeHookDefinition = mock(CoreHookDefinition.class);
- private final HookTestStep beforeHook = new HookTestStep(UUID.randomUUID(), BEFORE_STEP,
- new HookDefinitionMatch(beforeHookDefinition));
- private final PickleStepTestStep step = new PickleStepTestStep(
- UUID.randomUUID(),
- URI.create("file:path/to.feature"),
- pickle.getSteps().get(0),
- singletonList(beforeHook),
- singletonList(afterHook),
- definitionMatch);
-
- @BeforeEach
- void init() {
- Mockito.when(bus.getInstant()).thenReturn(Instant.now());
+ private MockEventBus bus = new MockEventBus();
+ private final TestCaseState state = new TestCaseState(bus, UUID.randomUUID(), testCase);
+ private PickleStepDefinitionMatch definitionMatch;
+ private CoreHookDefinition afterHookDefinition;
+ private CoreHookDefinition beforeHookDefinition;
+ private PickleStepTestStep step;
+
+ private void buildStep(
+ RuntimeException beforeHookException, RuntimeException afterHookException, Throwable stepException
+ ) {
+ beforeHookDefinition = CoreHookDefinition.create(new MockHookDefinition(beforeHookException));
+ afterHookDefinition = CoreHookDefinition.create(new MockHookDefinition(afterHookException));
+ definitionMatch = new MockPickleStepDefinitionMatch(stepException);
+ step = new PickleStepTestStep(
+ UUID.randomUUID(),
+ URI.create("file:path/to.feature"),
+ pickle.getSteps().get(0),
+ singletonList(new HookTestStep(UUID.randomUUID(), BEFORE_STEP,
+ new HookDefinitionMatch(beforeHookDefinition))),
+ singletonList(new HookTestStep(UUID.randomUUID(), AFTER_STEP,
+ new HookDefinitionMatch(afterHookDefinition))),
+ definitionMatch);
}
@Test
void run_wraps_run_step_in_test_step_started_and_finished_events() throws Throwable {
+ buildStep(null, null, null);
+
step.run(testCase, bus, state, ExecutionMode.RUN);
- InOrder order = inOrder(bus, definitionMatch);
- order.verify(bus).send(isA(TestStepStarted.class));
- order.verify(definitionMatch).runStep(state);
- order.verify(bus).send(isA(TestStepFinished.class));
+ List