diff --git a/cucumber-core/pom.xml b/cucumber-core/pom.xml
index a7e9d6917f..a226cdc4df 100644
--- a/cucumber-core/pom.xml
+++ b/cucumber-core/pom.xml
@@ -20,7 +20,6 @@
2.10.0
3.0
0.2
- 5.14.2
4.5.10
1.0.4
@@ -143,12 +142,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/order/PickleOrderTest.java b/cucumber-core/src/test/java/io/cucumber/core/order/PickleOrderTest.java
index 9578eb1e67..37e0102ce7 100644
--- a/cucumber-core/src/test/java/io/cucumber/core/order/PickleOrderTest.java
+++ b/cucumber-core/src/test/java/io/cucumber/core/order/PickleOrderTest.java
@@ -1,11 +1,9 @@
package io.cucumber.core.order;
import io.cucumber.core.gherkin.Pickle;
+import io.cucumber.core.gherkin.Step;
import io.cucumber.plugin.event.Location;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
import java.net.URI;
import java.util.Arrays;
@@ -13,27 +11,14 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
-import static org.mockito.Mockito.when;
-@ExtendWith(MockitoExtension.class)
class PickleOrderTest {
- @Mock
- Pickle firstPickle;
-
- @Mock
- Pickle secondPickle;
-
- @Mock
- Pickle thirdPickle;
-
@Test
void lexical_uri_order() {
- when(firstPickle.getUri()).thenReturn(URI.create("file:com/example/a.feature"));
- when(firstPickle.getLocation()).thenReturn(new Location(2, -1));
- when(secondPickle.getUri()).thenReturn(URI.create("file:com/example/a.feature"));
- when(secondPickle.getLocation()).thenReturn(new Location(3, -1));
- when(thirdPickle.getUri()).thenReturn(URI.create("file:com/example/b.feature"));
+ Pickle firstPickle = new StubPickle(new Location(2, -1), URI.create("file:com/example/a.feature"));
+ Pickle secondPickle = new StubPickle(new Location(3, -1), URI.create("file:com/example/a.feature"));
+ Pickle thirdPickle = new StubPickle(null, URI.create("file:com/example/b.feature"));
PickleOrder order = StandardPickleOrders.lexicalUriOrder();
List pickles = order.orderPickles(Arrays.asList(thirdPickle, secondPickle, firstPickle));
@@ -42,11 +27,9 @@ void lexical_uri_order() {
@Test
void reverse_lexical_uri_order() {
- when(firstPickle.getUri()).thenReturn(URI.create("file:com/example/a.feature"));
- when(firstPickle.getLocation()).thenReturn(new Location(2, -1));
- when(secondPickle.getUri()).thenReturn(URI.create("file:com/example/a.feature"));
- when(secondPickle.getLocation()).thenReturn(new Location(3, -1));
- when(thirdPickle.getUri()).thenReturn(URI.create("file:com/example/b.feature"));
+ Pickle firstPickle = new StubPickle(new Location(2, -1), URI.create("file:com/example/a.feature"));
+ Pickle secondPickle = new StubPickle(new Location(3, -1), URI.create("file:com/example/a.feature"));
+ Pickle thirdPickle = new StubPickle(null, URI.create("file:com/example/b.feature"));
PickleOrder order = StandardPickleOrders.reverseLexicalUriOrder();
List pickles = order.orderPickles(Arrays.asList(secondPickle, thirdPickle, firstPickle));
@@ -55,9 +38,67 @@ void reverse_lexical_uri_order() {
@Test
void random_order() {
+ Pickle firstPickle = new StubPickle(new Location(2, -1), URI.create("file:com/example/a.feature"));
+ Pickle secondPickle = new StubPickle(new Location(3, -1), URI.create("file:com/example/a.feature"));
+ Pickle thirdPickle = new StubPickle(null, URI.create("file:com/example/b.feature"));
+
PickleOrder order = StandardPickleOrders.random(42);
List pickles = order.orderPickles(Arrays.asList(firstPickle, secondPickle, thirdPickle));
assertThat(pickles, contains(secondPickle, firstPickle, thirdPickle));
}
+ private static class StubPickle implements Pickle {
+ private final Location location;
+ private final URI uri;
+
+ public StubPickle(Location location, URI uri) {
+ this.location = location;
+ this.uri = uri;
+ }
+
+ @Override
+ public String getKeyword() {
+ return null;
+ }
+
+ @Override
+ public String getLanguage() {
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public Location getLocation() {
+ return location;
+ }
+
+ @Override
+ public Location getScenarioLocation() {
+ return null;
+ }
+
+ @Override
+ public List getSteps() {
+ return null;
+ }
+
+ @Override
+ public List getTags() {
+ return null;
+ }
+
+ @Override
+ public URI getUri() {
+ return uri;
+ }
+
+ @Override
+ public String getId() {
+ return null;
+ }
+ }
}
diff --git a/cucumber-core/src/test/java/io/cucumber/core/plugin/CanonicalEventOrderTest.java b/cucumber-core/src/test/java/io/cucumber/core/plugin/CanonicalEventOrderTest.java
index da413f7885..5e4b6dd55c 100644
--- a/cucumber-core/src/test/java/io/cucumber/core/plugin/CanonicalEventOrderTest.java
+++ b/cucumber-core/src/test/java/io/cucumber/core/plugin/CanonicalEventOrderTest.java
@@ -6,7 +6,6 @@
import io.cucumber.plugin.event.SnippetsSuggestedEvent;
import io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion;
import io.cucumber.plugin.event.Status;
-import io.cucumber.plugin.event.TestCase;
import io.cucumber.plugin.event.TestCaseStarted;
import io.cucumber.plugin.event.TestRunFinished;
import io.cucumber.plugin.event.TestRunStarted;
@@ -27,8 +26,6 @@
import static org.hamcrest.number.OrderingComparison.greaterThan;
import static org.hamcrest.number.OrderingComparison.lessThan;
import static org.junit.jupiter.api.Assertions.assertAll;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
class CanonicalEventOrderTest {
@@ -81,10 +78,7 @@ class CanonicalEventOrderTest {
new Result(Status.PASSED, Duration.ZERO, null));
private static TestCaseStarted createTestCaseEvent(Instant instant, URI uri, int line) {
- final TestCase testCase = mock(TestCase.class);
- given(testCase.getUri()).willReturn(uri);
- given(testCase.getLocation()).willReturn(new Location(line, -1));
- return new TestCaseStarted(instant, testCase);
+ return new TestCaseStarted(instant, new StubTestCase(uri, new Location(line, -1)));
}
@Test
diff --git a/cucumber-core/src/test/java/io/cucumber/core/plugin/PluginFactoryTest.java b/cucumber-core/src/test/java/io/cucumber/core/plugin/PluginFactoryTest.java
index 74a5cda275..3766f4499c 100644
--- a/cucumber-core/src/test/java/io/cucumber/core/plugin/PluginFactoryTest.java
+++ b/cucumber-core/src/test/java/io/cucumber/core/plugin/PluginFactoryTest.java
@@ -10,10 +10,8 @@
import io.cucumber.plugin.EventListener;
import io.cucumber.plugin.event.EventHandler;
import io.cucumber.plugin.event.EventPublisher;
-import io.cucumber.plugin.event.PickleStepTestStep;
import io.cucumber.plugin.event.Result;
import io.cucumber.plugin.event.Status;
-import io.cucumber.plugin.event.TestCase;
import io.cucumber.plugin.event.TestRunFinished;
import io.cucumber.plugin.event.TestRunStarted;
import io.cucumber.plugin.event.TestStepFinished;
@@ -48,7 +46,6 @@
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.Mockito.mock;
class PluginFactoryTest {
@@ -196,8 +193,8 @@ void plugin_does_not_buffer_its_output() {
EventBus bus = new TimeServiceEventBus(new ClockStub(ZERO), UUID::randomUUID);
plugin.setEventPublisher(bus);
Result result = new Result(Status.PASSED, ZERO, null);
- TestStepFinished event = new TestStepFinished(bus.getInstant(), mock(TestCase.class),
- mock(PickleStepTestStep.class), result);
+ TestStepFinished event = new TestStepFinished(bus.getInstant(), new StubTestCase(),
+ new StubPickleStepTestStep(), result);
bus.send(event);
assertThat(mockSystemOut.toString(), is(not(equalTo(""))));
diff --git a/cucumber-core/src/test/java/io/cucumber/core/plugin/PluginsTest.java b/cucumber-core/src/test/java/io/cucumber/core/plugin/PluginsTest.java
index 307057c5c9..7b1b6d7c16 100644
--- a/cucumber-core/src/test/java/io/cucumber/core/plugin/PluginsTest.java
+++ b/cucumber-core/src/test/java/io/cucumber/core/plugin/PluginsTest.java
@@ -6,79 +6,127 @@
import io.cucumber.plugin.EventListener;
import io.cucumber.plugin.StrictAware;
import io.cucumber.plugin.event.Event;
+import io.cucumber.plugin.event.EventHandler;
import io.cucumber.plugin.event.EventPublisher;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.ArgumentMatchers;
-import org.mockito.Captor;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-@ExtendWith({ MockitoExtension.class })
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+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.assertIterableEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
class PluginsTest {
private final PluginFactory pluginFactory = new PluginFactory();
- @Mock
- private EventPublisher rootEventPublisher;
- @Captor
- private ArgumentCaptor eventPublisher;
@Test
void shouldSetStrictOnPlugin() {
RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
Plugins plugins = new Plugins(pluginFactory, runtimeOptions);
- StrictAware plugin = mock(StrictAware.class);
+ MockStrictAware plugin = new MockStrictAware();
plugins.addPlugin(plugin);
- verify(plugin).setStrict(true);
+ assertTrue(plugin.strict);
}
@Test
void shouldSetMonochromeOnPlugin() {
RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
Plugins plugins = new Plugins(pluginFactory, runtimeOptions);
- ColorAware plugin = mock(ColorAware.class);
+ MockColorAware plugin = new MockColorAware();
plugins.addPlugin(plugin);
- verify(plugin).setMonochrome(false);
+ assertFalse(plugin.monochrome);
}
@Test
void shouldSetConcurrentEventListener() {
RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
Plugins plugins = new Plugins(pluginFactory, runtimeOptions);
- ConcurrentEventListener plugin = mock(ConcurrentEventListener.class);
+ MockConcurrentEventListener plugin = new MockConcurrentEventListener();
+ EventPublisher rootEventPublisher = new MockEventPublisher();
plugins.addPlugin(plugin);
plugins.setEventBusOnEventListenerPlugins(rootEventPublisher);
- verify(plugin, times(1)).setEventPublisher(rootEventPublisher);
+
+ assertIterableEquals(List.of(rootEventPublisher), plugin.eventPublishers);
}
@Test
void shouldSetNonConcurrentEventListener() {
RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
Plugins plugins = new Plugins(pluginFactory, runtimeOptions);
- EventListener plugin = mock(EventListener.class);
+ MockEventListener plugin = new MockEventListener();
+ EventPublisher rootEventPublisher = new MockEventPublisher();
plugins.addPlugin(plugin);
plugins.setSerialEventBusOnEventListenerPlugins(rootEventPublisher);
- verify(plugin, times(1)).setEventPublisher(eventPublisher.capture());
- assertThat(eventPublisher.getValue().getClass(), is(equalTo(CanonicalOrderEventPublisher.class)));
+
+ assertEquals(1, plugin.eventPublishers.size());
+ assertInstanceOf(CanonicalOrderEventPublisher.class, plugin.eventPublishers.get(0));
}
@Test
void shouldRegisterCanonicalOrderEventPublisherWithRootEventPublisher() {
RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
Plugins plugins = new Plugins(pluginFactory, runtimeOptions);
- EventListener plugin = mock(EventListener.class);
+ MockEventListener plugin = new MockEventListener();
+ MockEventPublisher rootEventPublisher = new MockEventPublisher();
plugins.addPlugin(plugin);
plugins.setSerialEventBusOnEventListenerPlugins(rootEventPublisher);
- verify(rootEventPublisher, times(1)).registerHandlerFor(eq(Event.class), ArgumentMatchers.any());
+
+ List> eventHandlers = rootEventPublisher.handlers.get(Event.class);
+ assertNotNull(eventHandlers);
+ assertEquals(1, eventHandlers.size());
+ }
+
+ @SuppressWarnings("deprecation")
+ private static class MockStrictAware implements StrictAware {
+ Boolean strict;
+ @Override
+ public void setStrict(boolean strict) {
+ this.strict = strict;
+ }
}
+ private static class MockColorAware implements ColorAware {
+ Boolean monochrome;
+ @Override
+ public void setMonochrome(boolean monochrome) {
+ this.monochrome = monochrome;
+ }
+ }
+
+ private static class MockConcurrentEventListener implements ConcurrentEventListener {
+ final List eventPublishers = new ArrayList<>();
+ @Override
+ public void setEventPublisher(EventPublisher publisher) {
+ eventPublishers.add(publisher);
+ }
+ }
+
+ private static class MockEventListener implements EventListener {
+ final List eventPublishers = new ArrayList<>();
+ @Override
+ public void setEventPublisher(EventPublisher publisher) {
+ eventPublishers.add(publisher);
+ }
+ }
+
+ private static class MockEventPublisher implements EventPublisher {
+ final Map, List>> handlers = new HashMap<>();
+ @Override
+ public void registerHandlerFor(Class eventType, EventHandler handler) {
+ List> eventHandlers = handlers.computeIfAbsent(eventType, key -> new ArrayList<>());
+ eventHandlers.add(handler);
+ }
+
+ @Override
+ public void removeHandlerFor(Class eventType, EventHandler handler) {
+
+ }
+ }
}
diff --git a/cucumber-core/src/test/java/io/cucumber/core/plugin/ProgressFormatterTest.java b/cucumber-core/src/test/java/io/cucumber/core/plugin/ProgressFormatterTest.java
index 2a3069e354..b506ba8201 100644
--- a/cucumber-core/src/test/java/io/cucumber/core/plugin/ProgressFormatterTest.java
+++ b/cucumber-core/src/test/java/io/cucumber/core/plugin/ProgressFormatterTest.java
@@ -2,19 +2,25 @@
import io.cucumber.core.eventbus.EventBus;
import io.cucumber.core.runtime.TimeServiceEventBus;
-import io.cucumber.plugin.event.HookTestStep;
+import io.cucumber.plugin.event.Argument;
+import io.cucumber.plugin.event.Location;
import io.cucumber.plugin.event.PickleStepTestStep;
import io.cucumber.plugin.event.Result;
+import io.cucumber.plugin.event.Step;
+import io.cucumber.plugin.event.StepArgument;
import io.cucumber.plugin.event.TestCase;
import io.cucumber.plugin.event.TestRunFinished;
+import io.cucumber.plugin.event.TestStep;
import io.cucumber.plugin.event.TestStepFinished;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
+import java.net.URI;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
+import java.util.List;
import java.util.UUID;
import static io.cucumber.core.plugin.Bytes.bytes;
@@ -24,13 +30,14 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.text.IsEqualCompressingWhiteSpace.equalToCompressingWhiteSpace;
-import static org.mockito.Mockito.mock;
class ProgressFormatterTest {
final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final ProgressFormatter formatter = new ProgressFormatter(out);
+ private final StubTestCase mocktestCase = new StubTestCase();
+ private final StubPickleStepTestStep stubPickleStepTestStep = new StubPickleStepTestStep();
@BeforeEach
void setup() {
@@ -47,7 +54,7 @@ void prints_empty_line_for_empty_test_run() {
@Test
void prints_empty_line_and_green_dot_for_passing_test_run() {
Result result = new Result(PASSED, Duration.ZERO, null);
- bus.send(new TestStepFinished(Instant.now(), mock(TestCase.class), mock(PickleStepTestStep.class), result));
+ bus.send(new TestStepFinished(Instant.now(), mocktestCase, stubPickleStepTestStep, result));
bus.send(new TestRunFinished(Instant.now(), result));
assertThat(out, bytes(equalToCompressingWhiteSpace(AnsiEscapes.GREEN + "." + AnsiEscapes.RESET + "\n")));
}
@@ -55,35 +62,142 @@ void prints_empty_line_and_green_dot_for_passing_test_run() {
@Test
void print_green_dot_for_passing_step() {
Result result = new Result(PASSED, Duration.ZERO, null);
- bus.send(new TestStepFinished(Instant.now(), mock(TestCase.class), mock(PickleStepTestStep.class), result));
+ bus.send(new TestStepFinished(Instant.now(), mocktestCase, stubPickleStepTestStep, result));
assertThat(out, bytes(equalTo(AnsiEscapes.GREEN + "." + AnsiEscapes.RESET)));
}
@Test
void print_yellow_U_for_undefined_step() {
Result result = new Result(UNDEFINED, Duration.ZERO, null);
- bus.send(new TestStepFinished(Instant.now(), mock(TestCase.class), mock(PickleStepTestStep.class), result));
+ bus.send(new TestStepFinished(Instant.now(), mocktestCase, stubPickleStepTestStep, result));
assertThat(out, bytes(equalTo(AnsiEscapes.YELLOW + "U" + AnsiEscapes.RESET)));
}
@Test
void print_nothing_for_passed_hook() {
Result result = new Result(PASSED, Duration.ZERO, null);
- bus.send(new TestStepFinished(Instant.now(), mock(TestCase.class), mock(HookTestStep.class), result));
+ bus.send(new TestStepFinished(Instant.now(), mocktestCase, stubPickleStepTestStep, result));
}
@Test
void print_red_F_for_failed_step() {
Result result = new Result(FAILED, Duration.ZERO, null);
- bus.send(new TestStepFinished(Instant.now(), mock(TestCase.class), mock(PickleStepTestStep.class), result));
+ bus.send(new TestStepFinished(Instant.now(), mocktestCase, stubPickleStepTestStep, result));
assertThat(out, bytes(equalTo(AnsiEscapes.RED + "F" + AnsiEscapes.RESET)));
}
@Test
void print_red_F_for_failed_hook() {
Result result = new Result(FAILED, Duration.ZERO, null);
- bus.send(new TestStepFinished(Instant.now(), mock(TestCase.class), mock(HookTestStep.class), result));
+ bus.send(new TestStepFinished(Instant.now(), mocktestCase, stubPickleStepTestStep, result));
assertThat(out, bytes(equalTo(AnsiEscapes.RED + "F" + AnsiEscapes.RESET)));
}
+ @Test
+ void print_red_F_for_failed_hook_monochrome() {
+ // Given
+ Result result = new Result(FAILED, Duration.ZERO, null);
+ formatter.setMonochrome(true);
+
+ // When
+ bus.send(new TestStepFinished(Instant.now(), mocktestCase, stubPickleStepTestStep, result));
+
+ // Then
+ assertThat(out, bytes(equalTo("F")));
+ formatter.setMonochrome(false);
+ }
+
+ private static class StubTestCase implements TestCase {
+ @Override
+ public Integer getLine() {
+ return null;
+ }
+
+ @Override
+ public Location getLocation() {
+ return null;
+ }
+
+ @Override
+ public String getKeyword() {
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public String getScenarioDesignation() {
+ return null;
+ }
+
+ @Override
+ public List getTags() {
+ return null;
+ }
+
+ @Override
+ public List getTestSteps() {
+ return null;
+ }
+
+ @Override
+ public URI getUri() {
+ return null;
+ }
+
+ @Override
+ public UUID getId() {
+ return null;
+ }
+ }
+
+ private static class StubPickleStepTestStep implements PickleStepTestStep {
+ @Override
+ public String getPattern() {
+ return null;
+ }
+
+ @Override
+ public Step getStep() {
+ return null;
+ }
+
+ @Override
+ public List getDefinitionArgument() {
+ return null;
+ }
+
+ @Override
+ public StepArgument getStepArgument() {
+ return null;
+ }
+
+ @Override
+ public int getStepLine() {
+ return 0;
+ }
+
+ @Override
+ public URI getUri() {
+ return null;
+ }
+
+ @Override
+ public String getStepText() {
+ return null;
+ }
+
+ @Override
+ public String getCodeLocation() {
+ return null;
+ }
+
+ @Override
+ public UUID getId() {
+ return null;
+ }
+ }
}
diff --git a/cucumber-core/src/test/java/io/cucumber/core/plugin/StubPickleStepTestStep.java b/cucumber-core/src/test/java/io/cucumber/core/plugin/StubPickleStepTestStep.java
new file mode 100644
index 0000000000..e04e8c1f89
--- /dev/null
+++ b/cucumber-core/src/test/java/io/cucumber/core/plugin/StubPickleStepTestStep.java
@@ -0,0 +1,70 @@
+package io.cucumber.core.plugin;
+
+import io.cucumber.plugin.event.Argument;
+import io.cucumber.plugin.event.PickleStepTestStep;
+import io.cucumber.plugin.event.Step;
+import io.cucumber.plugin.event.StepArgument;
+
+import java.net.URI;
+import java.util.List;
+import java.util.UUID;
+
+public class StubPickleStepTestStep implements PickleStepTestStep {
+ private final String pattern;
+ private final String stepText;
+
+ public StubPickleStepTestStep() {
+ this.pattern = null;
+ this.stepText = null;
+ }
+
+ public StubPickleStepTestStep(String pattern, String stepText) {
+ this.pattern = pattern;
+ this.stepText = stepText;
+ }
+
+ @Override
+ public String getPattern() {
+ return pattern;
+ }
+
+ @Override
+ public Step getStep() {
+ return null;
+ }
+
+ @Override
+ public List getDefinitionArgument() {
+ return null;
+ }
+
+ @Override
+ public StepArgument getStepArgument() {
+ return null;
+ }
+
+ @Override
+ public int getStepLine() {
+ return 0;
+ }
+
+ @Override
+ public URI getUri() {
+ return null;
+ }
+
+ @Override
+ public String getStepText() {
+ return stepText;
+ }
+
+ @Override
+ public String getCodeLocation() {
+ return null;
+ }
+
+ @Override
+ public UUID getId() {
+ return null;
+ }
+}
diff --git a/cucumber-core/src/test/java/io/cucumber/core/plugin/StubTestCase.java b/cucumber-core/src/test/java/io/cucumber/core/plugin/StubTestCase.java
new file mode 100644
index 0000000000..6f67f5d138
--- /dev/null
+++ b/cucumber-core/src/test/java/io/cucumber/core/plugin/StubTestCase.java
@@ -0,0 +1,69 @@
+package io.cucumber.core.plugin;
+
+import io.cucumber.plugin.event.Location;
+import io.cucumber.plugin.event.TestCase;
+import io.cucumber.plugin.event.TestStep;
+
+import java.net.URI;
+import java.util.List;
+import java.util.UUID;
+
+public class StubTestCase implements TestCase {
+ private final URI uri;
+ private final Location location;
+
+ public StubTestCase() {
+ this.uri = null;
+ this.location = null;
+ }
+
+ public StubTestCase(URI uri, Location location) {
+ this.uri = uri;
+ this.location = location;
+ }
+
+ @Override
+ public Integer getLine() {
+ return null;
+ }
+
+ @Override
+ public Location getLocation() {
+ return location;
+ }
+
+ @Override
+ public String getKeyword() {
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public String getScenarioDesignation() {
+ return null;
+ }
+
+ @Override
+ public List getTags() {
+ return null;
+ }
+
+ @Override
+ public List getTestSteps() {
+ return null;
+ }
+
+ @Override
+ public URI getUri() {
+ return uri;
+ }
+
+ @Override
+ public UUID getId() {
+ return null;
+ }
+}
diff --git a/cucumber-core/src/test/java/io/cucumber/core/plugin/UnusedStepsSummaryPrinterTest.java b/cucumber-core/src/test/java/io/cucumber/core/plugin/UnusedStepsSummaryPrinterTest.java
index af319a45fa..adbbd172c5 100644
--- a/cucumber-core/src/test/java/io/cucumber/core/plugin/UnusedStepsSummaryPrinterTest.java
+++ b/cucumber-core/src/test/java/io/cucumber/core/plugin/UnusedStepsSummaryPrinterTest.java
@@ -5,7 +5,6 @@
import io.cucumber.plugin.event.Status;
import io.cucumber.plugin.event.StepDefinedEvent;
import io.cucumber.plugin.event.StepDefinition;
-import io.cucumber.plugin.event.TestCase;
import io.cucumber.plugin.event.TestRunFinished;
import io.cucumber.plugin.event.TestStep;
import io.cucumber.plugin.event.TestStepFinished;
@@ -19,8 +18,6 @@
import static io.cucumber.core.plugin.Bytes.bytes;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.text.IsEqualCompressingWhiteSpace.equalToCompressingWhiteSpace;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
class UnusedStepsSummaryPrinterTest {
@@ -36,12 +33,12 @@ void verifyUnusedStepsPrinted() {
bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/belly.feature:3", "a few cukes")));
bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/tummy.feature:5", "some more cukes")));
bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/gut.feature:7", "even more cukes")));
- bus.send(new TestStepFinished(bus.getInstant(), mock(TestCase.class), mockTestStep("my/belly.feature:3"),
+ bus.send(new TestStepFinished(bus.getInstant(), new StubTestCase(), new StubTestStep("my/belly.feature:3"),
new Result(Status.UNUSED, Duration.ZERO, null)));
bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/belly.feature:3", "a few cukes")));
bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/tummy.feature:5", "some more cukes")));
bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/gut.feature:7", "even more cukes")));
- bus.send(new TestStepFinished(bus.getInstant(), mock(TestCase.class), mockTestStep("my/gut.feature:7"),
+ bus.send(new TestStepFinished(bus.getInstant(), new StubTestCase(), new StubTestStep("my/gut.feature:7"),
new Result(Status.UNUSED, Duration.ZERO, null)));
bus.send(new TestRunFinished(bus.getInstant(), new Result(Status.PASSED, Duration.ZERO, null)));
@@ -54,10 +51,21 @@ private static StepDefinition mockStepDef(String location, String pattern) {
return new StepDefinition(location, pattern);
}
- private static TestStep mockTestStep(String location) {
- TestStep testStep = mock(TestStep.class);
- when(testStep.getCodeLocation()).thenReturn(location);
- return testStep;
- }
+ public static class StubTestStep implements TestStep {
+ private final String codeLocation;
+
+ public StubTestStep(String codeLocation) {
+ this.codeLocation = codeLocation;
+ }
+ @Override
+ public String getCodeLocation() {
+ return codeLocation;
+ }
+
+ @Override
+ public UUID getId() {
+ return null;
+ }
+ }
}
diff --git a/cucumber-core/src/test/java/io/cucumber/core/plugin/UsageFormatterTest.java b/cucumber-core/src/test/java/io/cucumber/core/plugin/UsageFormatterTest.java
index 00cc379a35..ece53df6c5 100644
--- a/cucumber-core/src/test/java/io/cucumber/core/plugin/UsageFormatterTest.java
+++ b/cucumber-core/src/test/java/io/cucumber/core/plugin/UsageFormatterTest.java
@@ -3,13 +3,11 @@
import io.cucumber.plugin.event.PickleStepTestStep;
import io.cucumber.plugin.event.Result;
import io.cucumber.plugin.event.Status;
-import io.cucumber.plugin.event.TestCase;
import io.cucumber.plugin.event.TestStep;
import io.cucumber.plugin.event.TestStepFinished;
import org.json.JSONException;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
@@ -26,8 +24,6 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.number.IsCloseTo.closeTo;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
class UsageFormatterTest {
@@ -38,11 +34,11 @@ class UsageFormatterTest {
void resultWithPassedStep() {
OutputStream out = new ByteArrayOutputStream();
UsageFormatter usageFormatter = new UsageFormatter(out);
- TestStep testStep = mockTestStep();
+ TestStep testStep = new StubPickleStepTestStep("stepDef", "step");
Result result = new Result(Status.PASSED, Duration.ofMillis(12345L), null);
usageFormatter
- .handleTestStepFinished(new TestStepFinished(Instant.EPOCH, mock(TestCase.class), testStep, result));
+ .handleTestStepFinished(new TestStepFinished(Instant.EPOCH, new StubTestCase(), testStep, result));
Map> usageMap = usageFormatter.usageMap;
assertThat(usageMap.size(), is(equalTo(1)));
@@ -53,26 +49,19 @@ void resultWithPassedStep() {
assertThat(durationEntries.get(0).getDurations().get(0).getDuration(), is(closeTo(12.345, EPSILON)));
}
- private PickleStepTestStep mockTestStep() {
- PickleStepTestStep testStep = mock(PickleStepTestStep.class, Mockito.RETURNS_MOCKS);
- when(testStep.getPattern()).thenReturn("stepDef");
- when(testStep.getStepText()).thenReturn("step");
- return testStep;
- }
-
@Test
void resultWithPassedAndFailedStep() {
OutputStream out = new ByteArrayOutputStream();
UsageFormatter usageFormatter = new UsageFormatter(out);
- TestStep testStep = mockTestStep();
+ TestStep testStep = new StubPickleStepTestStep("stepDef", "step");
Result passed = new Result(Status.PASSED, Duration.ofSeconds(12345L), null);
usageFormatter
- .handleTestStepFinished(new TestStepFinished(Instant.EPOCH, mock(TestCase.class), testStep, passed));
+ .handleTestStepFinished(new TestStepFinished(Instant.EPOCH, new StubTestCase(), testStep, passed));
Result failed = new Result(Status.FAILED, Duration.ZERO, null);
usageFormatter
- .handleTestStepFinished(new TestStepFinished(Instant.EPOCH, mock(TestCase.class), testStep, failed));
+ .handleTestStepFinished(new TestStepFinished(Instant.EPOCH, new StubTestCase(), testStep, failed));
Map> usageMap = usageFormatter.usageMap;
assertThat(usageMap.size(), is(equalTo(1)));
@@ -87,11 +76,11 @@ void resultWithPassedAndFailedStep() {
void resultWithZeroDuration() {
OutputStream out = new ByteArrayOutputStream();
UsageFormatter usageFormatter = new UsageFormatter(out);
- TestStep testStep = mockTestStep();
+ TestStep testStep = new StubPickleStepTestStep("stepDef", "step");
Result result = new Result(Status.PASSED, Duration.ZERO, null);
usageFormatter
- .handleTestStepFinished(new TestStepFinished(Instant.EPOCH, mock(TestCase.class), testStep, result));
+ .handleTestStepFinished(new TestStepFinished(Instant.EPOCH, new StubTestCase(), testStep, result));
Map> usageMap = usageFormatter.usageMap;
assertThat(usageMap.size(), is(equalTo(1)));
@@ -107,11 +96,11 @@ void resultWithZeroDuration() {
void resultWithNullDuration() {
OutputStream out = new ByteArrayOutputStream();
UsageFormatter usageFormatter = new UsageFormatter(out);
- PickleStepTestStep testStep = mockTestStep();
+ PickleStepTestStep testStep = new StubPickleStepTestStep("stepDef", "step");
Result result = new Result(Status.PASSED, Duration.ZERO, null);
usageFormatter
- .handleTestStepFinished(new TestStepFinished(Instant.EPOCH, mock(TestCase.class), testStep, result));
+ .handleTestStepFinished(new TestStepFinished(Instant.EPOCH, new StubTestCase(), testStep, result));
Map> usageMap = usageFormatter.usageMap;
assertThat(usageMap.size(), is(equalTo(1)));
diff --git a/cucumber-core/src/test/java/io/cucumber/core/resource/ClasspathScannerTest.java b/cucumber-core/src/test/java/io/cucumber/core/resource/ClasspathScannerTest.java
index c664b86eec..4f0a05e3c2 100644
--- a/cucumber-core/src/test/java/io/cucumber/core/resource/ClasspathScannerTest.java
+++ b/cucumber-core/src/test/java/io/cucumber/core/resource/ClasspathScannerTest.java
@@ -11,7 +11,9 @@
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
+import java.util.Enumeration;
import java.util.List;
+import java.util.Map;
import static java.util.Collections.enumeration;
import static java.util.Collections.singletonList;
@@ -20,8 +22,6 @@
import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
@WithLogRecordListener
class ClasspathScannerTest {
@@ -64,8 +64,6 @@ void scanForClassesInNonExistingPackage() {
@Test
void scanForResourcesInUnsupportedFileSystem(LogRecordListener logRecordListener) throws IOException {
- ClassLoader classLoader = mock(ClassLoader.class);
- ClasspathScanner scanner = new ClasspathScanner(() -> classLoader);
URLStreamHandler handler = new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL u) {
@@ -73,10 +71,25 @@ protected URLConnection openConnection(URL u) {
}
};
URL resourceUrl = new URL(null, "bundle-resource:com/cucumber/bundle", handler);
- when(classLoader.getResources("com/cucumber/bundle")).thenReturn(enumeration(singletonList(resourceUrl)));
+ ClassLoader classLoader = new MockClassLoader(
+ Map.of("com/cucumber/bundle", enumeration(singletonList(resourceUrl))));
+ ClasspathScanner scanner = new ClasspathScanner(() -> classLoader);
assertThat(scanner.scanForClassesInPackage("com.cucumber.bundle"), empty());
assertThat(logRecordListener.getLogRecords().get(0).getMessage(),
containsString("Failed to find resources for 'bundle-resource:com/cucumber/bundle'"));
}
+ public static class MockClassLoader extends ClassLoader {
+ private final Map> resources;
+
+ public MockClassLoader(Map> resources) {
+ this.resources = resources;
+ }
+
+ @Override
+ public Enumeration getResources(String name) {
+ return resources.get(name);
+ }
+ }
+
}
diff --git a/cucumber-core/src/test/java/io/cucumber/core/runner/AmbiguousStepDefinitionMatchTest.java b/cucumber-core/src/test/java/io/cucumber/core/runner/AmbiguousStepDefinitionMatchTest.java
index 1383c8df89..14ff905e33 100644
--- a/cucumber-core/src/test/java/io/cucumber/core/runner/AmbiguousStepDefinitionMatchTest.java
+++ b/cucumber-core/src/test/java/io/cucumber/core/runner/AmbiguousStepDefinitionMatchTest.java
@@ -1,8 +1,10 @@
package io.cucumber.core.runner;
+import io.cucumber.core.eventbus.IncrementingUuidGenerator;
import io.cucumber.core.feature.TestFeatureParser;
import io.cucumber.core.gherkin.Feature;
import io.cucumber.core.gherkin.Step;
+import io.cucumber.core.plugin.StubTestCase;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
@@ -13,7 +15,6 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.Mockito.mock;
class AmbiguousStepDefinitionMatchTest {
@@ -25,10 +26,12 @@ class AmbiguousStepDefinitionMatchTest {
private final AmbiguousStepDefinitionsException e = new AmbiguousStepDefinitionsException(step, emptyList());
private final AmbiguousPickleStepDefinitionsMatch match = new AmbiguousPickleStepDefinitionsMatch(
URI.create("file:path/to.feature"), step, e);
+ private final TestCaseState mockTestCaseState = new TestCaseState(new StubEventBus(),
+ new IncrementingUuidGenerator().generateId(), new StubTestCase());
@Test
void throws_ambiguous_step_definitions_exception_when_run() {
- Executable testMethod = () -> match.runStep(mock(TestCaseState.class));
+ Executable testMethod = () -> match.runStep(mockTestCaseState);
AmbiguousStepDefinitionsException actualThrown = assertThrows(AmbiguousStepDefinitionsException.class,
testMethod);
assertThat(actualThrown.getMessage(), is(equalTo(
@@ -37,7 +40,7 @@ void throws_ambiguous_step_definitions_exception_when_run() {
@Test
void throws_ambiguous_step_definitions_exception_when_dry_run() {
- Executable testMethod = () -> match.dryRunStep(mock(TestCaseState.class));
+ Executable testMethod = () -> match.dryRunStep(mockTestCaseState);
AmbiguousStepDefinitionsException actualThrown = assertThrows(AmbiguousStepDefinitionsException.class,
testMethod);
assertThat(actualThrown.getMessage(), is(equalTo(
diff --git a/cucumber-core/src/test/java/io/cucumber/core/runner/AmbiguousStepDefinitionsExceptionTest.java b/cucumber-core/src/test/java/io/cucumber/core/runner/AmbiguousStepDefinitionsExceptionTest.java
index 80db4b66ef..61885d5e70 100644
--- a/cucumber-core/src/test/java/io/cucumber/core/runner/AmbiguousStepDefinitionsExceptionTest.java
+++ b/cucumber-core/src/test/java/io/cucumber/core/runner/AmbiguousStepDefinitionsExceptionTest.java
@@ -1,10 +1,12 @@
package io.cucumber.core.runner;
+import io.cucumber.core.backend.StubStepDefinition;
import io.cucumber.core.feature.TestFeatureParser;
import io.cucumber.core.gherkin.Feature;
import io.cucumber.core.gherkin.Step;
import org.junit.jupiter.api.Test;
+import java.util.ArrayList;
import java.util.List;
import static java.util.Arrays.asList;
@@ -13,8 +15,6 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.jupiter.api.Assertions.assertAll;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
class AmbiguousStepDefinitionsExceptionTest {
@@ -27,13 +27,13 @@ void can_report_ambiguous_step_definitions() {
Step mockPickleStep = feature.getPickles().get(0).getSteps().get(0);
- PickleStepDefinitionMatch mockPickleStepDefinitionMatchOne = mock(PickleStepDefinitionMatch.class);
- when(mockPickleStepDefinitionMatchOne.getPattern()).thenReturn("PickleStepDefinitionMatchOne_Pattern");
- when(mockPickleStepDefinitionMatchOne.getLocation()).thenReturn("PickleStepDefinitionMatchOne_Location");
+ PickleStepDefinitionMatch mockPickleStepDefinitionMatchOne = new PickleStepDefinitionMatch(new ArrayList<>(),
+ new StubStepDefinition("PickleStepDefinitionMatchOne_Pattern", "PickleStepDefinitionMatchOne_Location"),
+ null, null);
- PickleStepDefinitionMatch mockPickleStepDefinitionMatchTwo = mock(PickleStepDefinitionMatch.class);
- when(mockPickleStepDefinitionMatchTwo.getPattern()).thenReturn("PickleStepDefinitionMatchTwo_Pattern");
- when(mockPickleStepDefinitionMatchTwo.getLocation()).thenReturn("PickleStepDefinitionMatchTwo_Location");
+ PickleStepDefinitionMatch mockPickleStepDefinitionMatchTwo = new PickleStepDefinitionMatch(new ArrayList<>(),
+ new StubStepDefinition("PickleStepDefinitionMatchTwo_Pattern", "PickleStepDefinitionMatchTwo_Location"),
+ null, null);
List matches = asList(mockPickleStepDefinitionMatchOne,
mockPickleStepDefinitionMatchTwo);
diff --git a/cucumber-core/src/test/java/io/cucumber/core/runner/CachingGlueTest.java b/cucumber-core/src/test/java/io/cucumber/core/runner/CachingGlueTest.java
index c67d33d9e3..2c1ad4cce7 100644
--- a/cucumber-core/src/test/java/io/cucumber/core/runner/CachingGlueTest.java
+++ b/cucumber-core/src/test/java/io/cucumber/core/runner/CachingGlueTest.java
@@ -1,11 +1,14 @@
package io.cucumber.core.runner;
+import io.cucumber.core.backend.CucumberBackendException;
+import io.cucumber.core.backend.CucumberInvocationTargetException;
import io.cucumber.core.backend.DataTableTypeDefinition;
import io.cucumber.core.backend.DefaultDataTableCellTransformerDefinition;
import io.cucumber.core.backend.DefaultDataTableEntryTransformerDefinition;
import io.cucumber.core.backend.DefaultParameterTransformerDefinition;
import io.cucumber.core.backend.DocStringTypeDefinition;
import io.cucumber.core.backend.HookDefinition;
+import io.cucumber.core.backend.ParameterInfo;
import io.cucumber.core.backend.ParameterTypeDefinition;
import io.cucumber.core.backend.ScenarioScoped;
import io.cucumber.core.backend.SourceReference;
@@ -32,6 +35,7 @@
import java.net.URI;
import java.time.Clock;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@@ -48,8 +52,6 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
class CachingGlueTest {
@@ -58,14 +60,10 @@ class CachingGlueTest {
@Test
void throws_duplicate_error_on_dupe_stepdefs() {
- StepDefinition a = mock(StepDefinition.class);
- when(a.getPattern()).thenReturn("hello");
- when(a.getLocation()).thenReturn("foo.bf:10");
+ StepDefinition a = new StubStepDefinitionWithPatternAndLocation("hello", "foo.bf:10");
glue.addStepDefinition(a);
- StepDefinition b = mock(StepDefinition.class);
- when(b.getPattern()).thenReturn("hello");
- when(b.getLocation()).thenReturn("bar.bf:90");
+ StepDefinition b = new StubStepDefinitionWithPatternAndLocation("hello", "bar.bf:90");
glue.addStepDefinition(b);
DuplicateStepDefinitionException exception = assertThrows(
@@ -853,4 +851,39 @@ public boolean isDisposed() {
}
}
+
+ private static class StubStepDefinitionWithPatternAndLocation implements StepDefinition {
+ private final String pattern;
+ private final String location;
+
+ public StubStepDefinitionWithPatternAndLocation(String pattern, String location) {
+ this.pattern = pattern;
+ this.location = location;
+ }
+
+ @Override
+ public boolean isDefinedAt(StackTraceElement stackTraceElement) {
+ return false;
+ }
+
+ @Override
+ public String getLocation() {
+ return location;
+ }
+
+ @Override
+ public void execute(Object[] args) throws CucumberBackendException, CucumberInvocationTargetException {
+
+ }
+
+ @Override
+ public List parameterInfos() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public String getPattern() {
+ return pattern;
+ }
+ }
}
diff --git a/cucumber-core/src/test/java/io/cucumber/core/runner/DuplicateStepDefinitionExceptionTest.java b/cucumber-core/src/test/java/io/cucumber/core/runner/DuplicateStepDefinitionExceptionTest.java
index 63012ff6ea..d78b37592f 100644
--- a/cucumber-core/src/test/java/io/cucumber/core/runner/DuplicateStepDefinitionExceptionTest.java
+++ b/cucumber-core/src/test/java/io/cucumber/core/runner/DuplicateStepDefinitionExceptionTest.java
@@ -1,31 +1,62 @@
package io.cucumber.core.runner;
+import io.cucumber.core.backend.CucumberBackendException;
+import io.cucumber.core.backend.CucumberInvocationTargetException;
+import io.cucumber.core.backend.ParameterInfo;
import io.cucumber.core.backend.StepDefinition;
import org.junit.jupiter.api.Test;
+import java.util.List;
+
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.jupiter.api.Assertions.assertAll;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
class DuplicateStepDefinitionExceptionTest {
@Test
void can_report_duplicate_step_definitions() {
- final StepDefinition mockStepDefinitionA = mock(StepDefinition.class);
- when(mockStepDefinitionA.getLocation()).thenReturn("StepDefinitionA_Location");
- final StepDefinition mockStepDefinitionB = mock(StepDefinition.class);
- when(mockStepDefinitionB.getLocation()).thenReturn("StepDefinitionB_Location");
-
- DuplicateStepDefinitionException expectedThrown = new DuplicateStepDefinitionException(mockStepDefinitionA,
- mockStepDefinitionB);
+ DuplicateStepDefinitionException expectedThrown = new DuplicateStepDefinitionException(
+ new StubStepDefinition("StepDefinitionA_Location"),
+ new StubStepDefinition("StepDefinitionB_Location"));
assertAll(
() -> assertThat(expectedThrown.getMessage(),
is(equalTo("Duplicate step definitions in StepDefinitionA_Location and StepDefinitionB_Location"))),
() -> assertThat(expectedThrown.getCause(), is(nullValue())));
}
+ public static class StubStepDefinition implements StepDefinition {
+ private final String location;
+
+ public StubStepDefinition(String location) {
+ this.location = location;
+ }
+
+ @Override
+ public boolean isDefinedAt(StackTraceElement stackTraceElement) {
+ return false;
+ }
+
+ @Override
+ public String getLocation() {
+ return location;
+ }
+
+ @Override
+ public void execute(Object[] args) throws CucumberBackendException, CucumberInvocationTargetException {
+
+ }
+
+ @Override
+ public List parameterInfos() {
+ return null;
+ }
+
+ @Override
+ public String getPattern() {
+ return null;
+ }
+ }
}
diff --git a/cucumber-core/src/test/java/io/cucumber/core/runner/EventBusTest.java b/cucumber-core/src/test/java/io/cucumber/core/runner/EventBusTest.java
index bbbcc49f3c..726d8bf0e5 100644
--- a/cucumber-core/src/test/java/io/cucumber/core/runner/EventBusTest.java
+++ b/cucumber-core/src/test/java/io/cucumber/core/runner/EventBusTest.java
@@ -1,6 +1,8 @@
package io.cucumber.core.runner;
import io.cucumber.core.eventbus.EventBus;
+import io.cucumber.core.plugin.StubPickleStepTestStep;
+import io.cucumber.core.plugin.StubTestCase;
import io.cucumber.core.runtime.TimeServiceEventBus;
import io.cucumber.plugin.event.EventHandler;
import io.cucumber.plugin.event.PickleStepTestStep;
@@ -10,50 +12,54 @@
import io.cucumber.plugin.event.TestStepFinished;
import io.cucumber.plugin.event.TestStepStarted;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.junit.jupiter.MockitoExtension;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneId;
+import java.util.ArrayList;
+import java.util.List;
import java.util.UUID;
import static java.time.Duration.ZERO;
import static java.time.Instant.EPOCH;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-@ExtendWith(MockitoExtension.class)
class EventBusTest {
@Test
void handlers_receive_the_events_they_registered_for() {
- EventHandler handler = mock(EventHandler.class);
- PickleStepTestStep testStep = mock(PickleStepTestStep.class);
+ MockEventHandler handler = new MockEventHandler<>();
+ PickleStepTestStep testStep = new StubPickleStepTestStep();
Result result = new Result(Status.PASSED, ZERO, null);
- TestCase testCase = mock(TestCase.class);
+ TestCase testCase = new StubTestCase();
TestStepFinished event = new TestStepFinished(EPOCH, testCase, testStep, result);
EventBus bus = new TimeServiceEventBus(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC")), UUID::randomUUID);
bus.registerHandlerFor(TestStepFinished.class, handler);
bus.send(event);
- verify(handler).receive(event);
+ assertEquals(event, handler.events.get(0));
}
@Test
void handlers_do_not_receive_the_events_they_did_not_registered_for() {
- EventHandler handler = mock(EventHandler.class);
- PickleStepTestStep testStep = mock(PickleStepTestStep.class);
- TestCase testCase = mock(TestCase.class);
+ MockEventHandler handler = new MockEventHandler<>();
+ PickleStepTestStep testStep = new StubPickleStepTestStep();
+ TestCase testCase = new StubTestCase();
TestStepStarted event = new TestStepStarted(EPOCH, testCase, testStep);
EventBus bus = new TimeServiceEventBus(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC")), UUID::randomUUID);
bus.registerHandlerFor(TestStepFinished.class, handler);
bus.send(event);
- verify(handler, never()).receive(event);
+ assertEquals(0, handler.events.size());
}
+ private static class MockEventHandler implements EventHandler {
+ final List events = new ArrayList<>();
+ @Override
+ public void receive(T event) {
+ events.add(event);
+ }
+ }
}
diff --git a/cucumber-core/src/test/java/io/cucumber/core/runner/HookOrderTest.java b/cucumber-core/src/test/java/io/cucumber/core/runner/HookOrderTest.java
index 4582a8b188..db860a0596 100644
--- a/cucumber-core/src/test/java/io/cucumber/core/runner/HookOrderTest.java
+++ b/cucumber-core/src/test/java/io/cucumber/core/runner/HookOrderTest.java
@@ -3,6 +3,7 @@
import io.cucumber.core.backend.Glue;
import io.cucumber.core.backend.HookDefinition;
import io.cucumber.core.backend.StubStepDefinition;
+import io.cucumber.core.backend.TestCaseState;
import io.cucumber.core.eventbus.EventBus;
import io.cucumber.core.feature.TestFeatureParser;
import io.cucumber.core.gherkin.Feature;
@@ -10,8 +11,6 @@
import io.cucumber.core.options.RuntimeOptions;
import io.cucumber.core.runtime.TimeServiceEventBus;
import org.junit.jupiter.api.Test;
-import org.mockito.ArgumentMatchers;
-import org.mockito.InOrder;
import java.net.URI;
import java.time.Clock;
@@ -19,9 +18,7 @@
import java.util.List;
import java.util.UUID;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.junit.jupiter.api.Assertions.assertTrue;
class HookOrderTest {
@@ -34,10 +31,12 @@ class HookOrderTest {
" Scenario: Test scenario\n" +
" Given I have 4 cukes in my belly\n");
private final Pickle pickle = feature.getPickles().get(0);
+ private final List listener = new ArrayList<>();
@Test
void before_hooks_execute_in_order() {
- final List hooks = mockHooks(3, Integer.MAX_VALUE, 1, -1, 0, 10000, Integer.MIN_VALUE);
+ final List hooks = mockHooks(listener, 3, Integer.MAX_VALUE, 1, -1, 0, 10000,
+ Integer.MIN_VALUE);
TestRunnerSupplier runnerSupplier = new TestRunnerSupplier(bus, runtimeOptions) {
@Override
@@ -52,31 +51,37 @@ public void loadGlue(Glue glue, List gluePaths) {
runnerSupplier.get().runPickle(pickle);
- InOrder inOrder = inOrder(hooks.toArray());
- inOrder.verify(hooks.get(6)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(3)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(4)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(2)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(0)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(5)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(1)).execute(ArgumentMatchers.any());
+ verifyHookDefinitionExecutedInOrder();
}
- private List mockHooks(int... ordering) {
+ private void verifyHookDefinitionExecutedInOrder() {
+ long previousOrder = Long.MIN_VALUE;
+ for (HookDefinition hd : listener) {
+ assertTrue(hd.getOrder() >= previousOrder);
+ previousOrder = hd.getOrder();
+ }
+ }
+
+ private void verifyHookDefinitionExecutedInReverseOrder() {
+ long previousOrder = Long.MAX_VALUE;
+ for (HookDefinition hd : listener) {
+ assertTrue(hd.getOrder() <= previousOrder);
+ previousOrder = hd.getOrder();
+ }
+ }
+
+ private List mockHooks(List listener, int... ordering) {
List hooks = new ArrayList<>();
for (int order : ordering) {
- HookDefinition hook = mock(HookDefinition.class, "Mock number " + order);
- when(hook.getOrder()).thenReturn(order);
- when(hook.getTagExpression()).thenReturn("");
- when(hook.getLocation()).thenReturn("Mock location");
- hooks.add(hook);
+ hooks.add(new MockHookDefinition(order, listener));
}
return hooks;
}
@Test
void before_step_hooks_execute_in_order() {
- final List hooks = mockHooks(3, Integer.MAX_VALUE, 1, -1, 0, 10000, Integer.MIN_VALUE);
+ final List hooks = mockHooks(listener, 3, Integer.MAX_VALUE, 1, -1, 0, 10000,
+ Integer.MIN_VALUE);
TestRunnerSupplier runnerSupplier = new TestRunnerSupplier(bus, runtimeOptions) {
@Override
@@ -91,19 +96,13 @@ public void loadGlue(Glue glue, List gluePaths) {
runnerSupplier.get().runPickle(pickle);
- InOrder inOrder = inOrder(hooks.toArray());
- inOrder.verify(hooks.get(6)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(3)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(4)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(2)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(0)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(5)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(1)).execute(ArgumentMatchers.any());
+ verifyHookDefinitionExecutedInOrder();
}
@Test
void after_hooks_execute_in_reverse_order() {
- final List hooks = mockHooks(Integer.MIN_VALUE, 2, Integer.MAX_VALUE, 4, -1, 0, 10000);
+ final List hooks = mockHooks(listener, Integer.MIN_VALUE, 2, Integer.MAX_VALUE, 4, -1, 0,
+ 10000);
TestRunnerSupplier runnerSupplier = new TestRunnerSupplier(bus, runtimeOptions) {
@Override
@@ -118,19 +117,13 @@ public void loadGlue(Glue glue, List gluePaths) {
runnerSupplier.get().runPickle(pickle);
- InOrder inOrder = inOrder(hooks.toArray());
- inOrder.verify(hooks.get(2)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(6)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(3)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(1)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(5)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(4)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(0)).execute(ArgumentMatchers.any());
+ verifyHookDefinitionExecutedInReverseOrder();
}
@Test
void after_step_hooks_execute_in_reverse_order() {
- final List hooks = mockHooks(Integer.MIN_VALUE, 2, Integer.MAX_VALUE, 4, -1, 0, 10000);
+ final List hooks = mockHooks(listener, Integer.MIN_VALUE, 2, Integer.MAX_VALUE, 4, -1, 0,
+ 10000);
TestRunnerSupplier runnerSupplier = new TestRunnerSupplier(bus, runtimeOptions) {
@Override
@@ -145,20 +138,13 @@ public void loadGlue(Glue glue, List gluePaths) {
runnerSupplier.get().runPickle(pickle);
- InOrder inOrder = inOrder(hooks.toArray());
- inOrder.verify(hooks.get(2)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(6)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(3)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(1)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(5)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(4)).execute(ArgumentMatchers.any());
- inOrder.verify(hooks.get(0)).execute(ArgumentMatchers.any());
+ verifyHookDefinitionExecutedInReverseOrder();
}
@Test
void hooks_order_across_many_backends() {
- final List backend1Hooks = mockHooks(3, Integer.MAX_VALUE, 1);
- final List backend2Hooks = mockHooks(2, Integer.MAX_VALUE, 4);
+ final List backend1Hooks = mockHooks(listener, 3, Integer.MAX_VALUE, 1);
+ final List backend2Hooks = mockHooks(listener, 2, Integer.MAX_VALUE, 4);
TestRunnerSupplier runnerSupplier = new TestRunnerSupplier(bus, runtimeOptions) {
@Override
@@ -177,17 +163,41 @@ public void loadGlue(Glue glue, List gluePaths) {
runnerSupplier.get().runPickle(pickle);
- List allHooks = new ArrayList<>();
- allHooks.addAll(backend1Hooks);
- allHooks.addAll(backend2Hooks);
-
- InOrder inOrder = inOrder(allHooks.toArray());
- inOrder.verify(backend1Hooks.get(2)).execute(ArgumentMatchers.any());
- inOrder.verify(backend2Hooks.get(0)).execute(ArgumentMatchers.any());
- inOrder.verify(backend1Hooks.get(0)).execute(ArgumentMatchers.any());
- inOrder.verify(backend2Hooks.get(2)).execute(ArgumentMatchers.any());
- inOrder.verify(backend1Hooks.get(1)).execute(ArgumentMatchers.any());
- inOrder.verify(backend2Hooks.get(1)).execute(ArgumentMatchers.any());
+ verifyHookDefinitionExecutedInOrder();
}
+ private static class MockHookDefinition implements HookDefinition {
+ private final int order;
+ private final List listener;
+
+ public MockHookDefinition(int order, List listener) {
+ this.order = order;
+ this.listener = listener;
+ }
+
+ @Override
+ public void execute(TestCaseState state) {
+ listener.add(this);
+ }
+
+ @Override
+ public String getTagExpression() {
+ return "";
+ }
+
+ @Override
+ public int getOrder() {
+ return order;
+ }
+
+ @Override
+ public boolean isDefinedAt(StackTraceElement stackTraceElement) {
+ return false;
+ }
+
+ @Override
+ public String getLocation() {
+ return "Mock location";
+ }
+ }
}
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 8570ab96a5..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());
- ObjectFactory objectFactory = mock(ObjectFactory.class);
- 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());
-
+ final List eventListener = new ArrayList<>();
+ final HookDefinition hook = new MockHookDefinition("", "hook-location", eventListener);
+ Backend backend = new StubBackend(hook, eventListener);
+ ObjectFactory objectFactory = new StubObjectFactory();
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());
- ObjectFactory objectFactory = mock(ObjectFactory.class);
- 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());
+ final List eventListener = new ArrayList<>();
+ final HookDefinition hook = new MockHookDefinition("(", "hook-location", eventListener);
+ Backend backend = new StubBackend(hook, eventListener);
+ ObjectFactory objectFactory = new StubObjectFactory();
RuntimeException e = assertThrows(RuntimeException.class,
() -> new Runner(bus, Collections.singleton(backend), objectFactory,
@@ -90,4 +69,92 @@ void hook_throws_exception_with_name_when_tag_expression_is_invalid() {
is("Invalid tag expression at 'hook-location'"));
}
+ private static class StubObjectFactory implements ObjectFactory {
+ @Override
+ public boolean addClass(Class> glueClass) {
+ return false;
+ }
+
+ @Override
+ public T getInstance(Class glueClass) {
+ return null;
+ }
+
+ @Override
+ public void start() {
+
+ }
+
+ @Override
+ 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/HookTestStepTest.java b/cucumber-core/src/test/java/io/cucumber/core/runner/HookTestStepTest.java
index 569cf827e3..78ec6d8df8 100644
--- a/cucumber-core/src/test/java/io/cucumber/core/runner/HookTestStepTest.java
+++ b/cucumber-core/src/test/java/io/cucumber/core/runner/HookTestStepTest.java
@@ -1,18 +1,20 @@
package io.cucumber.core.runner;
+import io.cucumber.core.backend.HookDefinition;
import io.cucumber.core.eventbus.EventBus;
import io.cucumber.core.feature.TestFeatureParser;
import io.cucumber.core.gherkin.Feature;
+import io.cucumber.messages.types.Envelope;
+import io.cucumber.plugin.event.EventHandler;
import io.cucumber.plugin.event.HookType;
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.InOrder;
-import org.mockito.Mockito;
import java.time.Instant;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.List;
import java.util.UUID;
import static io.cucumber.core.backend.Status.PASSED;
@@ -20,10 +22,8 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.mockito.ArgumentMatchers.isA;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
class HookTestStepTest {
@@ -31,7 +31,9 @@ class HookTestStepTest {
"Feature: Test feature\n" +
" Scenario: Test scenario\n" +
" Given I have 4 cukes in my belly\n");
- private final CoreHookDefinition hookDefintion = mock(CoreHookDefinition.class);
+ List
-
- org.mockito
- mockito-junit-jupiter
- ${mockito.version}
- test
-
org.hamcrest
hamcrest
diff --git a/cucumber-guice/src/test/java/io/cucumber/guice/GuiceBackendTest.java b/cucumber-guice/src/test/java/io/cucumber/guice/GuiceBackendTest.java
index 923cd66062..80644e1731 100644
--- a/cucumber-guice/src/test/java/io/cucumber/guice/GuiceBackendTest.java
+++ b/cucumber-guice/src/test/java/io/cucumber/guice/GuiceBackendTest.java
@@ -1,15 +1,23 @@
package io.cucumber.guice;
import io.cucumber.core.backend.BackendProviderService;
+import io.cucumber.core.backend.DataTableTypeDefinition;
+import io.cucumber.core.backend.DefaultDataTableCellTransformerDefinition;
+import io.cucumber.core.backend.DefaultDataTableEntryTransformerDefinition;
+import io.cucumber.core.backend.DefaultParameterTransformerDefinition;
+import io.cucumber.core.backend.DocStringTypeDefinition;
import io.cucumber.core.backend.Glue;
+import io.cucumber.core.backend.HookDefinition;
import io.cucumber.core.backend.ObjectFactory;
+import io.cucumber.core.backend.ParameterTypeDefinition;
+import io.cucumber.core.backend.StaticHookDefinition;
+import io.cucumber.core.backend.StepDefinition;
import io.cucumber.guice.integration.YourInjectorSource;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
import java.util.function.Supplier;
import static java.lang.Thread.currentThread;
@@ -19,38 +27,37 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-@ExtendWith({ MockitoExtension.class })
class GuiceBackendTest {
public final Supplier classLoader = currentThread()::getContextClassLoader;
- @Mock
- private Glue glue;
-
- @Mock
- private ObjectFactory factory;
+ private final Glue glue = new StubGlue();
@Test
void finds_injector_source_impls_by_classpath_url() {
+ MockObjectFactory factory = new MockObjectFactory();
GuiceBackend backend = new GuiceBackend(factory, classLoader);
backend.loadGlue(glue, singletonList(URI.create("classpath:io/cucumber/guice/integration")));
- verify(factory).addClass(YourInjectorSource.class);
+ assertTrue(factory.classes.contains(YourInjectorSource.class));
}
@Test
void finds_injector_source_impls_once_by_classpath_url() {
+ MockObjectFactory factory = new MockObjectFactory();
GuiceBackend backend = new GuiceBackend(factory, classLoader);
backend.loadGlue(glue, asList(URI.create("classpath:io/cucumber/guice/integration"),
URI.create("classpath:io/cucumber/guice/integration")));
- verify(factory, times(1)).addClass(YourInjectorSource.class);
+ assertTrue(factory.classes.contains(YourInjectorSource.class));
+ assertEquals(1, factory.classes.size());
}
@Test
void world_and_snippet_methods_do_nothing() {
+ MockObjectFactory factory = new MockObjectFactory();
GuiceBackend backend = new GuiceBackend(factory, classLoader);
backend.loadGlue(glue, singletonList(URI.create("classpath:io/cucumber/guice/integration")));
backend.buildWorld();
@@ -60,21 +67,121 @@ void world_and_snippet_methods_do_nothing() {
@Test
void doesnt_save_anything_in_glue() {
+ MockObjectFactory factory = new MockObjectFactory();
GuiceBackend backend = new GuiceBackend(factory, classLoader);
backend.loadGlue(null, singletonList(URI.create("classpath:io/cucumber/guice/integration")));
- verify(factory).addClass(YourInjectorSource.class);
+ assertTrue(factory.classes.contains(YourInjectorSource.class));
}
@Test()
void list_of_uris_cant_be_null() {
+ MockObjectFactory factory = new MockObjectFactory();
GuiceBackend backend = new GuiceBackend(factory, classLoader);
assertThrows(NullPointerException.class, () -> backend.loadGlue(glue, null));
}
@Test
void backend_service_creates_backend() {
+ MockObjectFactory factory = new MockObjectFactory();
BackendProviderService backendProviderService = new GuiceBackendProviderService();
assertThat(backendProviderService.create(factory, factory, classLoader), is(notNullValue()));
}
+ private static class MockObjectFactory implements ObjectFactory {
+ List> classes = new ArrayList<>();
+ boolean started = false;
+ boolean stopped = false;
+
+ @Override
+ public boolean addClass(Class> glueClass) {
+ return classes.add(glueClass);
+ }
+
+ @Override
+ public T getInstance(Class glueClass) {
+ return null;
+ }
+
+ @Override
+ public void start() {
+ started = true;
+ }
+
+ @Override
+ public void stop() {
+ stopped = true;
+ }
+ }
+
+ private static class StubGlue implements Glue {
+
+ @Override
+ public void addBeforeAllHook(StaticHookDefinition beforeAllHook) {
+
+ }
+
+ @Override
+ public void addAfterAllHook(StaticHookDefinition afterAllHook) {
+
+ }
+
+ @Override
+ public void addStepDefinition(StepDefinition stepDefinition) {
+
+ }
+
+ @Override
+ public void addBeforeHook(HookDefinition beforeHook) {
+
+ }
+
+ @Override
+ public void addAfterHook(HookDefinition afterHook) {
+
+ }
+
+ @Override
+ public void addBeforeStepHook(HookDefinition beforeStepHook) {
+
+ }
+
+ @Override
+ public void addAfterStepHook(HookDefinition afterStepHook) {
+
+ }
+
+ @Override
+ public void addParameterType(ParameterTypeDefinition parameterType) {
+
+ }
+
+ @Override
+ public void addDataTableType(DataTableTypeDefinition dataTableType) {
+
+ }
+
+ @Override
+ public void addDefaultParameterTransformer(DefaultParameterTransformerDefinition defaultParameterTransformer) {
+
+ }
+
+ @Override
+ public void addDefaultDataTableEntryTransformer(
+ DefaultDataTableEntryTransformerDefinition defaultDataTableEntryTransformer
+ ) {
+
+ }
+
+ @Override
+ public void addDefaultDataTableCellTransformer(
+ DefaultDataTableCellTransformerDefinition defaultDataTableCellTransformer
+ ) {
+
+ }
+
+ @Override
+ public void addDocStringType(DocStringTypeDefinition docStringType) {
+
+ }
+ }
}
diff --git a/cucumber-java/pom.xml b/cucumber-java/pom.xml
index 5f2f15e683..4f06bcb76a 100644
--- a/cucumber-java/pom.xml
+++ b/cucumber-java/pom.xml
@@ -17,7 +17,6 @@
3.0
2.18.0
5.11.2
- 5.14.2
@@ -72,12 +71,6 @@
junit-platform-suite
test
-
- org.mockito
- mockito-junit-jupiter
- ${mockito.version}
- test
-
com.fasterxml.jackson.core
jackson-databind
diff --git a/cucumber-java/src/test/java/io/cucumber/java/JavaBackendTest.java b/cucumber-java/src/test/java/io/cucumber/java/JavaBackendTest.java
index 5ad1a92826..f7e2522148 100644
--- a/cucumber-java/src/test/java/io/cucumber/java/JavaBackendTest.java
+++ b/cucumber-java/src/test/java/io/cucumber/java/JavaBackendTest.java
@@ -1,19 +1,23 @@
package io.cucumber.java;
+import io.cucumber.core.backend.DataTableTypeDefinition;
+import io.cucumber.core.backend.DefaultDataTableCellTransformerDefinition;
+import io.cucumber.core.backend.DefaultDataTableEntryTransformerDefinition;
+import io.cucumber.core.backend.DefaultParameterTransformerDefinition;
+import io.cucumber.core.backend.DocStringTypeDefinition;
import io.cucumber.core.backend.Glue;
+import io.cucumber.core.backend.HookDefinition;
import io.cucumber.core.backend.ObjectFactory;
+import io.cucumber.core.backend.ParameterTypeDefinition;
+import io.cucumber.core.backend.StaticHookDefinition;
import io.cucumber.core.backend.StepDefinition;
import io.cucumber.java.steps.Steps;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.function.Executable;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
import java.net.URI;
+import java.util.ArrayList;
import java.util.List;
import static java.lang.Thread.currentThread;
@@ -23,46 +27,45 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-@ExtendWith(MockitoExtension.class)
class JavaBackendTest {
-
- @Captor
- ArgumentCaptor stepDefinition;
-
- @Mock
- private Glue glue;
-
- @Mock
- private ObjectFactory factory;
+ private MockObjectFactory factory;
private JavaBackend backend;
@BeforeEach
void createBackend() {
+ factory = new MockObjectFactory();
this.backend = new JavaBackend(factory, factory, currentThread()::getContextClassLoader);
}
@Test
void finds_step_definitions_by_classpath_url() {
+ MockGlue glue = new MockGlue();
+
backend.loadGlue(glue, singletonList(URI.create("classpath:io/cucumber/java/steps")));
backend.buildWorld();
- verify(factory).addClass(Steps.class);
+
+ assertIterableEquals(List.of(Steps.class), factory.classes);
}
@Test
void finds_step_definitions_once_by_classpath_url() {
+ MockGlue glue = new MockGlue();
+
backend.loadGlue(glue,
asList(URI.create("classpath:io/cucumber/java/steps"), URI.create("classpath:io/cucumber/java/steps")));
backend.buildWorld();
- verify(factory, times(1)).addClass(Steps.class);
+
+ assertIterableEquals(List.of(Steps.class), factory.classes);
}
@Test
void detects_subclassed_glue_and_throws_exception() {
+ MockGlue glue = new MockGlue();
Executable testMethod = () -> backend.loadGlue(glue, asList(URI.create("classpath:io/cucumber/java/steps"),
URI.create("classpath:io/cucumber/java/incorrectlysubclassedsteps")));
InvalidMethodException expectedThrown = assertThrows(InvalidMethodException.class, testMethod);
@@ -72,10 +75,12 @@ void detects_subclassed_glue_and_throws_exception() {
@Test
void detects_repeated_annotations() {
+ MockGlue glue = new MockGlue();
+
backend.loadGlue(glue, singletonList(URI.create("classpath:io/cucumber/java/repeatable")));
- verify(glue, times(2)).addStepDefinition(stepDefinition.capture());
- List patterns = stepDefinition.getAllValues()
+ assertEquals(2, glue.stepDefinitions.size());
+ List patterns = glue.stepDefinitions
.stream()
.map(StepDefinition::getPattern)
.collect(toList());
@@ -83,4 +88,88 @@ void detects_repeated_annotations() {
}
+ private static class MockGlue implements Glue {
+ final List stepDefinitions = new ArrayList<>();
+
+ @Override
+ public void addBeforeAllHook(StaticHookDefinition beforeAllHook) {
+ }
+
+ @Override
+ public void addAfterAllHook(StaticHookDefinition afterAllHook) {
+ }
+
+ @Override
+ public void addStepDefinition(StepDefinition stepDefinition) {
+ stepDefinitions.add(stepDefinition);
+ }
+
+ @Override
+ public void addBeforeHook(HookDefinition beforeHook) {
+ }
+
+ @Override
+ public void addAfterHook(HookDefinition afterHook) {
+ }
+
+ @Override
+ public void addBeforeStepHook(HookDefinition beforeStepHook) {
+ }
+
+ @Override
+ public void addAfterStepHook(HookDefinition afterStepHook) {
+ }
+
+ @Override
+ public void addParameterType(ParameterTypeDefinition parameterType) {
+ }
+
+ @Override
+ public void addDataTableType(DataTableTypeDefinition dataTableType) {
+ }
+
+ @Override
+ public void addDefaultParameterTransformer(DefaultParameterTransformerDefinition defaultParameterTransformer) {
+ }
+
+ @Override
+ public void addDefaultDataTableEntryTransformer(
+ DefaultDataTableEntryTransformerDefinition defaultDataTableEntryTransformer
+ ) {
+ }
+
+ @Override
+ public void addDefaultDataTableCellTransformer(
+ DefaultDataTableCellTransformerDefinition defaultDataTableCellTransformer
+ ) {
+ }
+
+ @Override
+ public void addDocStringType(DocStringTypeDefinition docStringType) {
+ }
+ }
+
+ private class MockObjectFactory implements ObjectFactory {
+ final List> classes = new ArrayList<>();
+
+ @Override
+ public boolean addClass(Class> glueClass) {
+ return classes.add(glueClass);
+ }
+
+ @Override
+ public T getInstance(Class glueClass) {
+ return null;
+ }
+
+ @Override
+ public void start() {
+
+ }
+
+ @Override
+ public void stop() {
+
+ }
+ }
}
diff --git a/cucumber-java/src/test/java/io/cucumber/java/JavaHookDefinitionTest.java b/cucumber-java/src/test/java/io/cucumber/java/JavaHookDefinitionTest.java
index e1616cd003..51284c74ea 100644
--- a/cucumber-java/src/test/java/io/cucumber/java/JavaHookDefinitionTest.java
+++ b/cucumber-java/src/test/java/io/cucumber/java/JavaHookDefinitionTest.java
@@ -1,15 +1,13 @@
package io.cucumber.java;
import io.cucumber.core.backend.Lookup;
+import io.cucumber.core.backend.Status;
import io.cucumber.core.backend.TestCaseState;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-import org.mockito.junit.jupiter.MockitoSettings;
-import org.mockito.quality.Strictness;
import java.lang.reflect.Method;
+import java.net.URI;
+import java.util.Collection;
import java.util.List;
import static org.hamcrest.CoreMatchers.startsWith;
@@ -18,8 +16,6 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
@SuppressWarnings({ "WeakerAccess" })
-@ExtendWith({ MockitoExtension.class })
-@MockitoSettings(strictness = Strictness.STRICT_STUBS)
public class JavaHookDefinitionTest {
private final Lookup lookup = new Lookup() {
@@ -31,8 +27,7 @@ public T getInstance(Class glueClass) {
}
};
- @Mock
- private TestCaseState state;
+ private TestCaseState state = new StubTestCaseState();
private boolean invoked = false;
@@ -122,4 +117,55 @@ public String string_return_type() {
return "";
}
+ private class StubTestCaseState implements TestCaseState {
+ @Override
+ public Collection getSourceTagNames() {
+ return null;
+ }
+
+ @Override
+ public Status getStatus() {
+ return null;
+ }
+
+ @Override
+ public boolean isFailed() {
+ return false;
+ }
+
+ @Override
+ public void attach(byte[] data, String mediaType, String name) {
+
+ }
+
+ @Override
+ public void attach(String data, String mediaType, String name) {
+
+ }
+
+ @Override
+ public void log(String text) {
+
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public String getId() {
+ return null;
+ }
+
+ @Override
+ public URI getUri() {
+ return null;
+ }
+
+ @Override
+ public Integer getLine() {
+ return null;
+ }
+ }
}
diff --git a/cucumber-java8/pom.xml b/cucumber-java8/pom.xml
index 24a55dc44f..10c81522b2 100644
--- a/cucumber-java8/pom.xml
+++ b/cucumber-java8/pom.xml
@@ -16,7 +16,6 @@
1.1.2
3.0
5.11.2
- 5.14.2
0.6.3
@@ -71,13 +70,6 @@
test
-
- org.mockito
- mockito-junit-jupiter
- ${mockito.version}
- test
-
-
org.hamcrest
hamcrest
diff --git a/cucumber-java8/src/test/java/io/cucumber/java8/Java8BackendTest.java b/cucumber-java8/src/test/java/io/cucumber/java8/Java8BackendTest.java
index 6580190c02..49e5c3e451 100644
--- a/cucumber-java8/src/test/java/io/cucumber/java8/Java8BackendTest.java
+++ b/cucumber-java8/src/test/java/io/cucumber/java8/Java8BackendTest.java
@@ -1,51 +1,133 @@
package io.cucumber.java8;
+import io.cucumber.core.backend.DataTableTypeDefinition;
+import io.cucumber.core.backend.DefaultDataTableCellTransformerDefinition;
+import io.cucumber.core.backend.DefaultDataTableEntryTransformerDefinition;
+import io.cucumber.core.backend.DefaultParameterTransformerDefinition;
+import io.cucumber.core.backend.DocStringTypeDefinition;
import io.cucumber.core.backend.Glue;
+import io.cucumber.core.backend.HookDefinition;
import io.cucumber.core.backend.ObjectFactory;
+import io.cucumber.core.backend.ParameterTypeDefinition;
+import io.cucumber.core.backend.StaticHookDefinition;
+import io.cucumber.core.backend.StepDefinition;
import io.cucumber.java8.steps.Steps;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
import static java.lang.Thread.currentThread;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
+import static org.junit.jupiter.api.Assertions.assertIterableEquals;
-@ExtendWith(MockitoExtension.class)
class Java8BackendTest {
-
- @Mock
- private Glue glue;
-
- @Mock
- private ObjectFactory factory;
+ private MockObjectFactory factory;
private Java8Backend backend;
@BeforeEach
void createBackend() {
+ factory = new MockObjectFactory();
this.backend = new Java8Backend(factory, factory, currentThread()::getContextClassLoader);
}
@Test
void finds_step_definitions_by_classpath_url() {
- backend.loadGlue(glue, singletonList(URI.create("classpath:io/cucumber/java8/steps")));
+ backend.loadGlue(new StubGlue(), singletonList(URI.create("classpath:io/cucumber/java8/steps")));
backend.buildWorld();
- verify(factory).addClass(Steps.class);
+ assertIterableEquals(List.of(Steps.class), factory.classes);
}
@Test
void finds_step_definitions_once_by_classpath_url() {
- backend.loadGlue(glue,
+ backend.loadGlue(new StubGlue(),
asList(URI.create("classpath:io/cucumber/java8/steps"), URI.create("classpath:io/cucumber/java8/steps")));
backend.buildWorld();
- verify(factory, times(1)).addClass(Steps.class);
+ assertIterableEquals(List.of(Steps.class), factory.classes);
+ }
+
+ private static class StubGlue implements Glue {
+ @Override
+ public void addBeforeAllHook(StaticHookDefinition beforeAllHook) {
+ }
+
+ @Override
+ public void addAfterAllHook(StaticHookDefinition afterAllHook) {
+ }
+
+ @Override
+ public void addStepDefinition(StepDefinition stepDefinition) {
+ }
+
+ @Override
+ public void addBeforeHook(HookDefinition beforeHook) {
+ }
+
+ @Override
+ public void addAfterHook(HookDefinition afterHook) {
+ }
+
+ @Override
+ public void addBeforeStepHook(HookDefinition beforeStepHook) {
+ }
+
+ @Override
+ public void addAfterStepHook(HookDefinition afterStepHook) {
+ }
+
+ @Override
+ public void addParameterType(ParameterTypeDefinition parameterType) {
+ }
+
+ @Override
+ public void addDataTableType(DataTableTypeDefinition dataTableType) {
+ }
+
+ @Override
+ public void addDefaultParameterTransformer(DefaultParameterTransformerDefinition defaultParameterTransformer) {
+ }
+
+ @Override
+ public void addDefaultDataTableEntryTransformer(
+ DefaultDataTableEntryTransformerDefinition defaultDataTableEntryTransformer
+ ) {
+ }
+
+ @Override
+ public void addDefaultDataTableCellTransformer(
+ DefaultDataTableCellTransformerDefinition defaultDataTableCellTransformer
+ ) {
+ }
+
+ @Override
+ public void addDocStringType(DocStringTypeDefinition docStringType) {
+ }
}
+ private static class MockObjectFactory implements ObjectFactory {
+ List> classes = new ArrayList<>();
+ @Override
+ public boolean addClass(Class> glueClass) {
+ return classes.add(glueClass);
+ }
+
+ @Override
+ public T getInstance(Class glueClass) {
+ return null;
+ }
+
+ @Override
+ public void start() {
+
+ }
+
+ @Override
+ public void stop() {
+
+ }
+ }
}
diff --git a/cucumber-java8/src/test/java/io/cucumber/java8/LambdaGlueTest.java b/cucumber-java8/src/test/java/io/cucumber/java8/LambdaGlueTest.java
index f502ffab10..2fcd65b64c 100644
--- a/cucumber-java8/src/test/java/io/cucumber/java8/LambdaGlueTest.java
+++ b/cucumber-java8/src/test/java/io/cucumber/java8/LambdaGlueTest.java
@@ -7,12 +7,14 @@
import io.cucumber.core.backend.DocStringTypeDefinition;
import io.cucumber.core.backend.HookDefinition;
import io.cucumber.core.backend.ParameterTypeDefinition;
+import io.cucumber.core.backend.Status;
import io.cucumber.core.backend.StepDefinition;
import io.cucumber.core.backend.TestCaseState;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
+import java.net.URI;
+import java.util.Collection;
import java.util.concurrent.atomic.AtomicBoolean;
import static io.cucumber.java8.LambdaGlue.DEFAULT_AFTER_ORDER;
@@ -25,7 +27,7 @@
class LambdaGlueTest {
private final AtomicBoolean invoked = new AtomicBoolean();
- private final TestCaseState state = Mockito.mock(TestCaseState.class);
+ private final TestCaseState state = new StubTestCaseState();
private final LambdaGlue lambdaGlue = new LambdaGlue() {
};
@@ -200,4 +202,55 @@ void testAfterStepHook() {
assertHook(afterStepHook, "taxExpression", 42);
}
+ private static class StubTestCaseState implements TestCaseState {
+ @Override
+ public Collection getSourceTagNames() {
+ return null;
+ }
+
+ @Override
+ public Status getStatus() {
+ return null;
+ }
+
+ @Override
+ public boolean isFailed() {
+ return false;
+ }
+
+ @Override
+ public void attach(byte[] data, String mediaType, String name) {
+
+ }
+
+ @Override
+ public void attach(String data, String mediaType, String name) {
+
+ }
+
+ @Override
+ public void log(String text) {
+
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public String getId() {
+ return null;
+ }
+
+ @Override
+ public URI getUri() {
+ return null;
+ }
+
+ @Override
+ public Integer getLine() {
+ return null;
+ }
+ }
}
diff --git a/cucumber-junit/pom.xml b/cucumber-junit/pom.xml
index c7691c8e21..384579612d 100644
--- a/cucumber-junit/pom.xml
+++ b/cucumber-junit/pom.xml
@@ -16,7 +16,6 @@
3.0
5.11.2
4.13.2
- 5.14.2
io.cucumber.junit
@@ -64,12 +63,6 @@
junit-vintage-engine
test
-
- org.mockito
- mockito-junit-jupiter
- ${mockito.version}
- test
-
org.hamcrest
hamcrest
diff --git a/cucumber-junit/src/test/java/io/cucumber/junit/CucumberTest.java b/cucumber-junit/src/test/java/io/cucumber/junit/CucumberTest.java
index 3d5ed1185a..29fc5e2c6e 100644
--- a/cucumber-junit/src/test/java/io/cucumber/junit/CucumberTest.java
+++ b/cucumber-junit/src/test/java/io/cucumber/junit/CucumberTest.java
@@ -14,23 +14,23 @@
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.ParentRunner;
import org.junit.runners.model.InitializationError;
-import org.mockito.InOrder;
-import org.mockito.Mockito;
import java.io.File;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
import static java.util.Collections.emptyList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.ArgumentMatchers.argThat;
class CucumberTest {
@@ -96,67 +96,57 @@ void finds_no_features_when_explicit_feature_path_has_no_features() throws Initi
}
@Test
- void cucumber_can_run_features_in_parallel() throws Exception {
+ void cucumber_can_run_features_in_parallel() {
RunNotifier notifier = new RunNotifier();
- RunListener listener = Mockito.mock(RunListener.class);
+ MockRunListener listener = new MockRunListener();
notifier.addListener(listener);
ParallelComputer computer = new ParallelComputer(true, true);
Request.classes(computer, ValidEmpty.class).getRunner().run(notifier);
{
- InOrder order = Mockito.inOrder(listener);
-
- order.verify(listener)
- .testStarted(argThat(new DescriptionMatcher("Followed by some examples #1(Feature A)")));
- order.verify(listener)
- .testFinished(argThat(new DescriptionMatcher("Followed by some examples #1(Feature A)")));
- order.verify(listener)
- .testStarted(argThat(new DescriptionMatcher("Followed by some examples #2(Feature A)")));
- order.verify(listener)
- .testFinished(argThat(new DescriptionMatcher("Followed by some examples #2(Feature A)")));
- order.verify(listener)
- .testStarted(argThat(new DescriptionMatcher("Followed by some examples #3(Feature A)")));
- order.verify(listener)
- .testFinished(argThat(new DescriptionMatcher("Followed by some examples #3(Feature A)")));
+ List events = listener.events.stream()
+ .filter(runListenerEvent -> runListenerEvent.description.startsWith("Followed by some examples"))
+ .collect(Collectors.toList());
+ assertIterableEquals(List.of(
+ new RunListenerEvent("testStarted", "Followed by some examples #1(Feature A)"),
+ new RunListenerEvent("testFinished", "Followed by some examples #1(Feature A)"),
+ new RunListenerEvent("testStarted", "Followed by some examples #2(Feature A)"),
+ new RunListenerEvent("testFinished", "Followed by some examples #2(Feature A)"),
+ new RunListenerEvent("testStarted", "Followed by some examples #3(Feature A)"),
+ new RunListenerEvent("testFinished", "Followed by some examples #3(Feature A)")), events);
}
{
- InOrder order = Mockito.inOrder(listener);
- order.verify(listener).testStarted(argThat(new DescriptionMatcher("A(Feature B)")));
- order.verify(listener).testFinished(argThat(new DescriptionMatcher("A(Feature B)")));
- order.verify(listener).testStarted(argThat(new DescriptionMatcher("B(Feature B)")));
- order.verify(listener).testFinished(argThat(new DescriptionMatcher("B(Feature B)")));
- order.verify(listener).testStarted(argThat(new DescriptionMatcher("C #1(Feature B)")));
- order.verify(listener).testFinished(argThat(new DescriptionMatcher("C #1(Feature B)")));
- order.verify(listener).testStarted(argThat(new DescriptionMatcher("C #2(Feature B)")));
- order.verify(listener).testFinished(argThat(new DescriptionMatcher("C #2(Feature B)")));
- order.verify(listener).testStarted(argThat(new DescriptionMatcher("C #3(Feature B)")));
- order.verify(listener).testFinished(argThat(new DescriptionMatcher("C #3(Feature B)")));
+ List events = listener.events.stream()
+ .filter(runListenerEvent -> runListenerEvent.description.endsWith("(Feature B)"))
+ .collect(Collectors.toList());
+ assertIterableEquals(List.of(
+ new RunListenerEvent("testStarted", "A(Feature B)"),
+ new RunListenerEvent("testFinished", "A(Feature B)"),
+ new RunListenerEvent("testStarted", "B(Feature B)"),
+ new RunListenerEvent("testFinished", "B(Feature B)"),
+ new RunListenerEvent("testStarted", "C #1(Feature B)"),
+ new RunListenerEvent("testFinished", "C #1(Feature B)"),
+ new RunListenerEvent("testStarted", "C #2(Feature B)"),
+ new RunListenerEvent("testFinished", "C #2(Feature B)"),
+ new RunListenerEvent("testStarted", "C #3(Feature B)"),
+ new RunListenerEvent("testFinished", "C #3(Feature B)")), events);
}
}
@Test
- void cucumber_distinguishes_between_identical_features() throws Exception {
+ void cucumber_distinguishes_between_identical_features() {
RunNotifier notifier = new RunNotifier();
- RunListener listener = Mockito.mock(RunListener.class);
+ MockRunListener listener = new MockRunListener();
notifier.addListener(listener);
Request.classes(ValidEmpty.class).getRunner().run(notifier);
- {
- InOrder order = Mockito.inOrder(listener);
-
- order.verify(listener)
- .testStarted(
- argThat(new DescriptionMatcher("A single scenario(A feature with a single scenario #1)")));
- order.verify(listener)
- .testFinished(
- argThat(new DescriptionMatcher("A single scenario(A feature with a single scenario #1)")));
-
- order.verify(listener)
- .testStarted(
- argThat(new DescriptionMatcher("A single scenario(A feature with a single scenario #2)")));
- order.verify(listener)
- .testFinished(
- argThat(new DescriptionMatcher("A single scenario(A feature with a single scenario #2)")));
- }
+ List events = listener.events.stream()
+ .filter(runListenerEvent -> runListenerEvent.description.startsWith("A single scenario"))
+ .collect(Collectors.toList());
+ assertIterableEquals(List.of(
+ new RunListenerEvent("testStarted", "A single scenario(A feature with a single scenario #1)"),
+ new RunListenerEvent("testFinished", "A single scenario(A feature with a single scenario #1)"),
+ new RunListenerEvent("testStarted", "A single scenario(A feature with a single scenario #2)"),
+ new RunListenerEvent("testFinished", "A single scenario(A feature with a single scenario #2)")), events);
}
@Test
@@ -243,4 +233,39 @@ public static class FormatterWithLexerErrorFeature {
}
+ private static class MockRunListener extends RunListener {
+ List events = new ArrayList<>();
+ @Override
+ public void testStarted(Description description) {
+ this.events.add(new RunListenerEvent("testStarted", description.getDisplayName()));
+ }
+
+ @Override
+ public void testFinished(Description description) {
+ this.events.add(new RunListenerEvent("testFinished", description.getDisplayName()));
+ }
+
+ }
+
+ public static class RunListenerEvent {
+ String eventName;
+ String description;
+ public RunListenerEvent(String eventName, String description) {
+ this.eventName = eventName;
+ this.description = description;
+ }
+
+ public boolean equals(Object o) {
+ if (o instanceof RunListenerEvent) {
+ return this.toString().equals(o.toString());
+ } else {
+ return false;
+ }
+ }
+
+ public String toString() {
+ return eventName + ", description=" + description;
+ }
+
+ }
}
diff --git a/cucumber-junit/src/test/java/io/cucumber/junit/DescriptionMatcher.java b/cucumber-junit/src/test/java/io/cucumber/junit/DescriptionMatcher.java
deleted file mode 100644
index 58ef3879da..0000000000
--- a/cucumber-junit/src/test/java/io/cucumber/junit/DescriptionMatcher.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package io.cucumber.junit;
-
-import org.junit.runner.Description;
-import org.mockito.ArgumentMatcher;
-
-final class DescriptionMatcher implements ArgumentMatcher {
-
- private final String name;
-
- DescriptionMatcher(String name) {
- this.name = name;
- }
-
- @Override
- public boolean matches(Description argument) {
- return argument != null && argument.getDisplayName().equals(name);
- }
-
- @Override
- public String toString() {
- return name;
- }
-
-}
diff --git a/cucumber-junit/src/test/java/io/cucumber/junit/FailureMatcher.java b/cucumber-junit/src/test/java/io/cucumber/junit/FailureMatcher.java
deleted file mode 100644
index 79ac340ae7..0000000000
--- a/cucumber-junit/src/test/java/io/cucumber/junit/FailureMatcher.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package io.cucumber.junit;
-
-import org.junit.runner.notification.Failure;
-import org.mockito.ArgumentMatcher;
-
-final class FailureMatcher implements ArgumentMatcher {
-
- private final String name;
-
- FailureMatcher(String name) {
- this.name = name;
- }
-
- @Override
- public boolean matches(Failure argument) {
- return argument != null && argument.getDescription().getDisplayName().equals(name);
- }
-
-}
diff --git a/cucumber-junit/src/test/java/io/cucumber/junit/FeatureRunnerTest.java b/cucumber-junit/src/test/java/io/cucumber/junit/FeatureRunnerTest.java
index ff6b0bb531..9ed6a018a7 100644
--- a/cucumber-junit/src/test/java/io/cucumber/junit/FeatureRunnerTest.java
+++ b/cucumber-junit/src/test/java/io/cucumber/junit/FeatureRunnerTest.java
@@ -19,13 +19,14 @@
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
-import org.mockito.ArgumentCaptor;
-import org.mockito.InOrder;
+import org.junit.runner.notification.StoppedByUserException;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneId;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import java.util.UUID;
@@ -33,11 +34,9 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.ArgumentMatchers.argThat;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
class FeatureRunnerTest {
@@ -141,24 +140,25 @@ void should_not_issue_notification_for_steps_by_default_scenario_outline_with_tw
" Examples: examples 2 name\n" +
" | id |\n" +
" | #3 |\n");
- RunNotifier notifier = runFeatureWithNotifier(feature, new JUnitOptions());
-
- InOrder order = inOrder(notifier);
-
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario #1(feature name)")));
- order.verify(notifier, times(1)).fireTestFailure(argThat(new FailureMatcher("scenario #1(feature name)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario #1(feature name)")));
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario #2(feature name)")));
- order.verify(notifier, times(1)).fireTestFailure(argThat(new FailureMatcher("scenario #2(feature name)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario #2(feature name)")));
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario #3(feature name)")));
- order.verify(notifier, times(1)).fireTestFailure(argThat(new FailureMatcher("scenario #3(feature name)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario #3(feature name)")));
+ MockRunNotifier notifier = runFeatureWithNotifier(feature, new JUnitOptions());
+
+ assertIterableEquals(
+ List.of(
+ new RunNotifierEvent("fireTestStarted", "scenario #1(feature name)"),
+ new RunNotifierEvent("fireTestFailure", "scenario #1(feature name)"),
+ new RunNotifierEvent("fireTestFinished", "scenario #1(feature name)"),
+ new RunNotifierEvent("fireTestStarted", "scenario #2(feature name)"),
+ new RunNotifierEvent("fireTestFailure", "scenario #2(feature name)"),
+ new RunNotifierEvent("fireTestFinished", "scenario #2(feature name)"),
+ new RunNotifierEvent("fireTestStarted", "scenario #3(feature name)"),
+ new RunNotifierEvent("fireTestFailure", "scenario #3(feature name)"),
+ new RunNotifierEvent("fireTestFinished", "scenario #3(feature name)")),
+ notifier.events);
}
- private RunNotifier runFeatureWithNotifier(Feature feature, JUnitOptions options) {
+ private MockRunNotifier runFeatureWithNotifier(Feature feature, JUnitOptions options) {
FeatureRunner runner = createFeatureRunner(feature, options);
- RunNotifier notifier = mock(RunNotifier.class);
+ MockRunNotifier notifier = new MockRunNotifier();
runner.run(notifier);
return notifier;
}
@@ -175,16 +175,17 @@ void should_not_issue_notification_for_steps_by_default_two_scenarios_with_backg
" Scenario: scenario_2 name\n" +
" Then step #2\n");
- RunNotifier notifier = runFeatureWithNotifier(feature, new JUnitOptions());
-
- InOrder order = inOrder(notifier);
-
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario_1 name(feature name)")));
- order.verify(notifier, times(1)).fireTestFailure(argThat(new FailureMatcher("scenario_1 name(feature name)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario_1 name(feature name)")));
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario_2 name(feature name)")));
- order.verify(notifier, times(1)).fireTestFailure(argThat(new FailureMatcher("scenario_2 name(feature name)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario_2 name(feature name)")));
+ MockRunNotifier notifier = runFeatureWithNotifier(feature, new JUnitOptions());
+
+ assertIterableEquals(
+ List.of(
+ new RunNotifierEvent("fireTestStarted", "scenario_1 name(feature name)"),
+ new RunNotifierEvent("fireTestFailure", "scenario_1 name(feature name)"),
+ new RunNotifierEvent("fireTestFinished", "scenario_1 name(feature name)"),
+ new RunNotifierEvent("fireTestStarted", "scenario_2 name(feature name)"),
+ new RunNotifierEvent("fireTestFailure", "scenario_2 name(feature name)"),
+ new RunNotifierEvent("fireTestFinished", "scenario_2 name(feature name)")),
+ notifier.events);
}
@Test
@@ -271,45 +272,49 @@ void step_notification_can_be_turned_on_scenario_outline_with_two_examples_table
" | #3 |\n");
JUnitOptions junitOption = new JUnitOptionsBuilder().setStepNotifications(true).build();
- RunNotifier notifier = runFeatureWithNotifier(feature, junitOption);
-
- InOrder order = inOrder(notifier);
-
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario #1")));
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #1(scenario #1)")));
- order.verify(notifier).fireTestFailure(argThat(new FailureMatcher("step #1(scenario #1)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #1(scenario #1)")));
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #2(scenario #1)")));
- order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #2(scenario #1)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #2(scenario #1)")));
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #3(scenario #1)")));
- order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #3(scenario #1)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #3(scenario #1)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario #1")));
-
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario #2")));
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #1(scenario #2)")));
- order.verify(notifier).fireTestFailure(argThat(new FailureMatcher("step #1(scenario #2)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #1(scenario #2)")));
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #2(scenario #2)")));
- order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #2(scenario #2)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #2(scenario #2)")));
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #3(scenario #2)")));
- order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #3(scenario #2)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #3(scenario #2)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario #2")));
-
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario #3")));
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #1(scenario #3)")));
- order.verify(notifier).fireTestFailure(argThat(new FailureMatcher("step #1(scenario #3)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #1(scenario #3)")));
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #2(scenario #3)")));
- order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #2(scenario #3)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #2(scenario #3)")));
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #3(scenario #3)")));
- order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #3(scenario #3)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #3(scenario #3)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario #3")));
+ MockRunNotifier notifier = runFeatureWithNotifier(feature, junitOption);
+
+ assertIterableEquals(
+ List.of(
+ new RunNotifierEvent("fireTestStarted", "scenario #1"),
+ new RunNotifierEvent("fireTestStarted", "step #1(scenario #1)"),
+ new RunNotifierEvent("fireTestFailure", "step #1(scenario #1)"),
+ new RunNotifierEvent("fireTestFinished", "step #1(scenario #1)"),
+ new RunNotifierEvent("fireTestStarted", "step #2(scenario #1)"),
+ new RunNotifierEvent("fireTestAssumptionFailed", "step #2(scenario #1)"),
+ new RunNotifierEvent("fireTestFinished", "step #2(scenario #1)"),
+ new RunNotifierEvent("fireTestStarted", "step #3(scenario #1)"),
+ new RunNotifierEvent("fireTestAssumptionFailed", "step #3(scenario #1)"),
+ new RunNotifierEvent("fireTestFinished", "step #3(scenario #1)"),
+ new RunNotifierEvent("fireTestFailure", "scenario #1"),
+ new RunNotifierEvent("fireTestFinished", "scenario #1"),
+
+ new RunNotifierEvent("fireTestStarted", "scenario #2"),
+ new RunNotifierEvent("fireTestStarted", "step #1(scenario #2)"),
+ new RunNotifierEvent("fireTestFailure", "step #1(scenario #2)"),
+ new RunNotifierEvent("fireTestFinished", "step #1(scenario #2)"),
+ new RunNotifierEvent("fireTestStarted", "step #2(scenario #2)"),
+ new RunNotifierEvent("fireTestAssumptionFailed", "step #2(scenario #2)"),
+ new RunNotifierEvent("fireTestFinished", "step #2(scenario #2)"),
+ new RunNotifierEvent("fireTestStarted", "step #3(scenario #2)"),
+ new RunNotifierEvent("fireTestAssumptionFailed", "step #3(scenario #2)"),
+ new RunNotifierEvent("fireTestFinished", "step #3(scenario #2)"),
+ new RunNotifierEvent("fireTestFailure", "scenario #2"),
+ new RunNotifierEvent("fireTestFinished", "scenario #2"),
+
+ new RunNotifierEvent("fireTestStarted", "scenario #3"),
+ new RunNotifierEvent("fireTestStarted", "step #1(scenario #3)"),
+ new RunNotifierEvent("fireTestFailure", "step #1(scenario #3)"),
+ new RunNotifierEvent("fireTestFinished", "step #1(scenario #3)"),
+ new RunNotifierEvent("fireTestStarted", "step #2(scenario #3)"),
+ new RunNotifierEvent("fireTestAssumptionFailed", "step #2(scenario #3)"),
+ new RunNotifierEvent("fireTestFinished", "step #2(scenario #3)"),
+ new RunNotifierEvent("fireTestStarted", "step #3(scenario #3)"),
+ new RunNotifierEvent("fireTestAssumptionFailed", "step #3(scenario #3)"),
+ new RunNotifierEvent("fireTestFinished", "step #3(scenario #3)"),
+ new RunNotifierEvent("fireTestFailure", "scenario #3"),
+ new RunNotifierEvent("fireTestFinished", "scenario #3")),
+ notifier.events);
}
@Test
@@ -325,31 +330,33 @@ void step_notification_can_be_turned_on_two_scenarios_with_background() {
" Then another step #2\n");
JUnitOptions junitOption = new JUnitOptionsBuilder().setStepNotifications(true).build();
- RunNotifier notifier = runFeatureWithNotifier(feature, junitOption);
-
- InOrder order = inOrder(notifier);
-
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario_1 name")));
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #1(scenario_1 name)")));
- order.verify(notifier).fireTestFailure(argThat(new FailureMatcher("step #1(scenario_1 name)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #1(scenario_1 name)")));
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #2(scenario_1 name)")));
- order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #2(scenario_1 name)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #2(scenario_1 name)")));
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #3(scenario_1 name)")));
- order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #3(scenario_1 name)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #3(scenario_1 name)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario_1 name")));
-
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario_2 name")));
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #1(scenario_2 name)")));
- order.verify(notifier).fireTestFailure(argThat(new FailureMatcher("step #1(scenario_2 name)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #1(scenario_2 name)")));
- order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("another step #2(scenario_2 name)")));
- order.verify(notifier)
- .fireTestAssumptionFailed(argThat(new FailureMatcher("another step #2(scenario_2 name)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("another step #2(scenario_2 name)")));
- order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario_2 name")));
+ MockRunNotifier notifier = runFeatureWithNotifier(feature, junitOption);
+
+ assertIterableEquals(
+ List.of(
+ new RunNotifierEvent("fireTestStarted", "scenario_1 name"),
+ new RunNotifierEvent("fireTestStarted", "step #1(scenario_1 name)"),
+ new RunNotifierEvent("fireTestFailure", "step #1(scenario_1 name)"),
+ new RunNotifierEvent("fireTestFinished", "step #1(scenario_1 name)"),
+ new RunNotifierEvent("fireTestStarted", "step #2(scenario_1 name)"),
+ new RunNotifierEvent("fireTestAssumptionFailed", "step #2(scenario_1 name)"),
+ new RunNotifierEvent("fireTestFinished", "step #2(scenario_1 name)"),
+ new RunNotifierEvent("fireTestStarted", "step #3(scenario_1 name)"),
+ new RunNotifierEvent("fireTestAssumptionFailed", "step #3(scenario_1 name)"),
+ new RunNotifierEvent("fireTestFinished", "step #3(scenario_1 name)"),
+ new RunNotifierEvent("fireTestFailure", "scenario_1 name"),
+ new RunNotifierEvent("fireTestFinished", "scenario_1 name"),
+
+ new RunNotifierEvent("fireTestStarted", "scenario_2 name"),
+ new RunNotifierEvent("fireTestStarted", "step #1(scenario_2 name)"),
+ new RunNotifierEvent("fireTestFailure", "step #1(scenario_2 name)"),
+ new RunNotifierEvent("fireTestFinished", "step #1(scenario_2 name)"),
+ new RunNotifierEvent("fireTestStarted", "another step #2(scenario_2 name)"),
+ new RunNotifierEvent("fireTestAssumptionFailed", "another step #2(scenario_2 name)"),
+ new RunNotifierEvent("fireTestFinished", "another step #2(scenario_2 name)"),
+ new RunNotifierEvent("fireTestFailure", "scenario_2 name"),
+ new RunNotifierEvent("fireTestFinished", "scenario_2 name")),
+ notifier.events);
}
@Test
@@ -370,20 +377,19 @@ void should_notify_of_failure_to_create_runners_and_request_test_execution_to_st
CucumberExecutionContext context = new CucumberExecutionContext(bus, new ExitStatus(options), runnerSupplier);
FeatureRunner featureRunner = FeatureRunner.create(feature, null, filters, context, new JUnitOptions());
- RunNotifier notifier = mock(RunNotifier.class);
+ MockRunNotifier notifier = new MockRunNotifier();
PickleRunners.PickleRunner pickleRunner = featureRunner.getChildren().get(0);
featureRunner.runChild(pickleRunner, notifier);
Description description = pickleRunner.getDescription();
- ArgumentCaptor failureArgumentCaptor = ArgumentCaptor.forClass(Failure.class);
-
- InOrder order = inOrder(notifier);
- order.verify(notifier).fireTestStarted(description);
- order.verify(notifier).fireTestFailure(failureArgumentCaptor.capture());
- assertThat(failureArgumentCaptor.getValue().getException(), is(equalTo(illegalStateException)));
- assertThat(failureArgumentCaptor.getValue().getDescription(), is(equalTo(description)));
- order.verify(notifier).pleaseStop();
- order.verify(notifier).fireTestFinished(description);
+ assertIterableEquals(
+ List.of(
+ new RunNotifierEvent("fireTestStarted", description.getDisplayName()),
+ new RunNotifierEvent("fireTestFailure", description.getDisplayName()),
+ new RunNotifierEvent("pleaseStop", ""),
+ new RunNotifierEvent("fireTestFinished", description.getDisplayName())),
+ notifier.events);
+ assertEquals(illegalStateException, notifier.events.get(1).throwable);
}
@Test
@@ -416,4 +422,64 @@ void should_filter_pickles() {
is("scenario_2 name(feature name)"));
}
+ private static class MockRunNotifier extends RunNotifier {
+ List events = new ArrayList<>();
+
+ @Override
+ public void fireTestStarted(Description description) throws StoppedByUserException {
+ this.events.add(new RunNotifierEvent("fireTestStarted", description.getDisplayName()));
+ }
+
+ @Override
+ public void fireTestFailure(Failure failure) {
+ this.events.add(new RunNotifierEvent("fireTestFailure", failure.getDescription().getDisplayName(),
+ failure.getException()));
+ }
+
+ @Override
+ public void fireTestAssumptionFailed(Failure failure) {
+ this.events.add(new RunNotifierEvent("fireTestAssumptionFailed", failure.getDescription().getDisplayName(),
+ failure.getException()));
+ }
+
+ @Override
+ public void fireTestFinished(Description description) {
+ this.events.add(new RunNotifierEvent("fireTestFinished", description.getDisplayName()));
+ }
+
+ @Override
+ public void pleaseStop() {
+ this.events.add(new RunNotifierEvent("pleaseStop", ""));
+ }
+
+ }
+
+ private static class RunNotifierEvent {
+ private final String eventName;
+ private final String description;
+ private final Throwable throwable;
+ public RunNotifierEvent(String eventName, String description) {
+ this.eventName = eventName;
+ this.description = description;
+ this.throwable = null;
+ }
+
+ public RunNotifierEvent(String eventName, String description, Throwable throwable) {
+ this.eventName = eventName;
+ this.description = description;
+ this.throwable = throwable;
+ }
+
+ public boolean equals(Object o) {
+ if (o instanceof RunNotifierEvent) {
+ return this.toString().equals(o.toString());
+ } else {
+ return false;
+ }
+ }
+
+ public String toString() {
+ return eventName + ", description=" + description;
+ }
+ }
}
diff --git a/cucumber-junit/src/test/java/io/cucumber/junit/JUnitReporterWithStepNotificationsTest.java b/cucumber-junit/src/test/java/io/cucumber/junit/JUnitReporterWithStepNotificationsTest.java
index f2f3e76925..7816a89df6 100644
--- a/cucumber-junit/src/test/java/io/cucumber/junit/JUnitReporterWithStepNotificationsTest.java
+++ b/cucumber-junit/src/test/java/io/cucumber/junit/JUnitReporterWithStepNotificationsTest.java
@@ -6,34 +6,34 @@
import io.cucumber.core.gherkin.Step;
import io.cucumber.core.runtime.TimeServiceEventBus;
import io.cucumber.junit.PickleRunners.PickleRunner;
-import io.cucumber.plugin.event.HookTestStep;
+import io.cucumber.plugin.event.Argument;
import io.cucumber.plugin.event.Location;
import io.cucumber.plugin.event.PickleStepTestStep;
import io.cucumber.plugin.event.Result;
import io.cucumber.plugin.event.SnippetsSuggestedEvent;
import io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion;
import io.cucumber.plugin.event.Status;
+import io.cucumber.plugin.event.StepArgument;
import io.cucumber.plugin.event.TestCase;
import io.cucumber.plugin.event.TestCaseFinished;
import io.cucumber.plugin.event.TestCaseStarted;
+import io.cucumber.plugin.event.TestStep;
import io.cucumber.plugin.event.TestStepFinished;
import io.cucumber.plugin.event.TestStepStarted;
import org.junit.AssumptionViolatedException;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
+import org.junit.runner.notification.StoppedByUserException;
import org.junit.runners.model.MultipleFailureException;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
import java.net.URI;
import java.time.Clock;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.UUID;
import static java.time.Duration.ZERO;
@@ -44,15 +44,9 @@
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.runner.Description.createTestDescription;
-import static org.mockito.Mockito.lenient;
-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;
-
-@ExtendWith(MockitoExtension.class)
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
class JUnitReporterWithStepNotificationsTest {
private static final Location scenarioLine = new Location(0, 0);
@@ -65,47 +59,26 @@ class JUnitReporterWithStepNotificationsTest {
" Scenario: Test scenario\n" +
" Given step name\n");
private final Step step = feature.getPickles().get(0).getSteps().get(0);
- @Mock
- private TestCase testCase;
- @Mock
- private Description pickleRunnerDescription;
-
- @Mock
- private PickleRunner pickleRunner;
- @Mock
- private RunNotifier runNotifier;
-
- @Captor
- private ArgumentCaptor failureArgumentCaptor;
-
- @BeforeEach
- void mockPickleRunner() {
- when(pickleRunner.getDescription()).thenReturn(pickleRunnerDescription);
- Description runnerStepDescription = createTestDescription("", step.getText());
- lenient().when(pickleRunner.describeChild(step)).thenReturn(runnerStepDescription);
- }
+ private final PickleRunner pickleRunner = new MockPickleRunner(step);
+ private final PickleStepTestStep testStep = new StubPickleStepTestStep(featureUri, step);
+ private final TestCase testCase = new StubTestCase();
@Test
void test_step_started_fires_test_started_for_step() {
+ MockRunNotifier runNotifier = new MockRunNotifier();
jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
bus.send(new TestCaseStarted(now(), testCase));
- bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
+ bus.send(new TestStepStarted(now(), testCase, testStep));
jUnitReporter.finishExecutionUnit();
}
- private static PickleStepTestStep mockTestStep(Step step) {
- PickleStepTestStep testStep = mock(PickleStepTestStep.class);
- lenient().when(testStep.getUri()).thenReturn(featureUri);
- lenient().when(testStep.getStep()).thenReturn(step);
- return testStep;
- }
-
@Test
void disconnects_from_bus_once_execution_unit_finished() {
+ MockRunNotifier runNotifier = new MockRunNotifier();
jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
jUnitReporter.finishExecutionUnit();
bus.send(new TestCaseStarted(now(), testCase));
- verify(runNotifier, never()).fireTestStarted(pickleRunner.getDescription());
+ assertNull(runNotifier.testStartedDescription);
}
@Test
@@ -115,110 +88,114 @@ void ignores_steps_when_step_notification_are_disabled() {
.setStepNotifications(false)
.build());
+ MockRunNotifier runNotifier = new MockRunNotifier();
jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
bus.send(new TestCaseStarted(now(), testCase));
- bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
+ bus.send(new TestStepStarted(now(), testCase, testStep));
Result result = new Result(Status.PASSED, ZERO, null);
- bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
+ bus.send(new TestStepFinished(now(), testCase, testStep, result));
bus.send(new TestCaseFinished(now(), testCase, result));
- verify(runNotifier, never()).fireTestStarted(pickleRunner.describeChild(step));
- verify(runNotifier, never()).fireTestFinished(pickleRunner.describeChild(step));
+ assertNull(runNotifier.testStartedDescription);
+ assertNull(runNotifier.testFinishedDescription);
}
@Test
void test_case_finished_fires_test_finished_for_pickle() {
+ MockRunNotifier runNotifier = new MockRunNotifier();
jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
bus.send(new TestCaseStarted(now(), testCase));
- bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
+ bus.send(new TestStepStarted(now(), testCase, testStep));
Result result = new Result(Status.PASSED, ZERO, null);
- bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
+ bus.send(new TestStepFinished(now(), testCase, testStep, result));
bus.send(new TestCaseFinished(now(), testCase, result));
- verify(runNotifier).fireTestStarted(pickleRunner.describeChild(step));
- verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
+ assertEquals(pickleRunner.describeChild(step), runNotifier.testStartedDescription);
+ assertEquals(pickleRunner.describeChild(step), runNotifier.testFinishedDescription);
}
@Test
void test_step_finished_fires_assumption_failed_and_test_finished_for_skipped_step() {
+ MockRunNotifier runNotifier = new MockRunNotifier();
jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
bus.send(new TestCaseStarted(now(), testCase));
- bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
+ bus.send(new TestStepStarted(now(), testCase, testStep));
Result result = new Result(Status.SKIPPED, ZERO, null);
- bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
+ bus.send(new TestStepFinished(now(), testCase, testStep, result));
- verify(runNotifier).fireTestAssumptionFailed(failureArgumentCaptor.capture());
- verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
- Failure stepFailure = failureArgumentCaptor.getValue();
+ assertEquals(1, runNotifier.testAssumptionFailedFailures.size());
+ assertEquals(pickleRunner.describeChild(step), runNotifier.testFinishedDescription);
+ Failure stepFailure = runNotifier.testAssumptionFailedFailures.get(0);
assertThat(stepFailure.getDescription(), is(equalTo(pickleRunner.describeChild(step))));
assertThat(stepFailure.getException(), instanceOf(SkippedThrowable.class));
assertThat(stepFailure.getException().getMessage(), is(equalTo("This step is skipped")));
bus.send(new TestCaseFinished(now(), testCase, result));
- verify(runNotifier, times(2)).fireTestAssumptionFailed(failureArgumentCaptor.capture());
- Failure pickleFailure = failureArgumentCaptor.getValue();
+ assertEquals(2, runNotifier.testAssumptionFailedFailures.size());
+ Failure pickleFailure = runNotifier.testAssumptionFailedFailures.get(1);
assertThat(pickleFailure.getDescription(), is(equalTo(pickleRunner.getDescription())));
assertThat(pickleFailure.getException(), instanceOf(SkippedThrowable.class));
assertThat(pickleFailure.getException().getMessage(), is(equalTo("This scenario is skipped")));
-
}
@Test
void test_step_finished_fires_assumption_failed_and_test_finished_for_skipped_step_with_assumption_violated() {
+ MockRunNotifier runNotifier = new MockRunNotifier();
jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
bus.send(new TestCaseStarted(now(), testCase));
- bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
+ bus.send(new TestStepStarted(now(), testCase, testStep));
Throwable exception = new AssumptionViolatedException("Oops");
Result result = new Result(Status.SKIPPED, ZERO, exception);
- bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
+ bus.send(new TestStepFinished(now(), testCase, testStep, result));
- verify(runNotifier).fireTestAssumptionFailed(failureArgumentCaptor.capture());
- verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
+ assertEquals(1, runNotifier.testAssumptionFailedFailures.size());
+ assertEquals(pickleRunner.describeChild(step), runNotifier.testFinishedDescription);
- Failure stepFailure = failureArgumentCaptor.getValue();
+ Failure stepFailure = runNotifier.testAssumptionFailedFailures.get(0);
assertThat(stepFailure.getDescription(), is(equalTo(pickleRunner.describeChild(step))));
assertThat(stepFailure.getException(), is(equalTo(exception)));
bus.send(new TestCaseFinished(now(), testCase, result));
- verify(runNotifier, times(2)).fireTestAssumptionFailed(failureArgumentCaptor.capture());
- verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
+ assertEquals(2, runNotifier.testAssumptionFailedFailures.size());
+ assertEquals(pickleRunner.describeChild(step), runNotifier.testFinishedDescription);
- Failure pickleFailure = failureArgumentCaptor.getValue();
+ Failure pickleFailure = runNotifier.testAssumptionFailedFailures.get(1);
assertThat(pickleFailure.getDescription(), is(equalTo(pickleRunner.getDescription())));
assertThat(pickleFailure.getException(), is(equalTo(exception)));
}
@Test
void test_step_finished_fires_test_failure_and_test_finished_for_skipped_step_with_pending_exception() {
+ MockRunNotifier runNotifier = new MockRunNotifier();
jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
bus.send(new TestCaseStarted(now(), testCase));
- bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
+ bus.send(new TestStepStarted(now(), testCase, testStep));
Throwable exception = new TestPendingException("Oops");
Result result = new Result(Status.PENDING, ZERO, exception);
- bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
+ bus.send(new TestStepFinished(now(), testCase, testStep, result));
- verify(runNotifier).fireTestFailure(failureArgumentCaptor.capture());
- verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
+ assertEquals(1, runNotifier.testFailures.size());
+ assertEquals(pickleRunner.describeChild(step), runNotifier.testFinishedDescription);
- Failure stepFailure = failureArgumentCaptor.getValue();
+ Failure stepFailure = runNotifier.testFailures.get(0);
assertThat(stepFailure.getDescription(), is(equalTo(pickleRunner.describeChild(step))));
assertThat(stepFailure.getException(), is(equalTo(exception)));
bus.send(new TestCaseFinished(now(), testCase, result));
- verify(runNotifier, times(2)).fireTestFailure(failureArgumentCaptor.capture());
- verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
+ assertEquals(2, runNotifier.testFailures.size());
+ assertEquals(pickleRunner.describeChild(step), runNotifier.testFinishedDescription);
- Failure pickleFailure = failureArgumentCaptor.getValue();
+ Failure pickleFailure = runNotifier.testFailures.get(1);
assertThat(pickleFailure.getDescription(), is(equalTo(pickleRunner.getDescription())));
assertThat(pickleFailure.getException(), is(equalTo(exception)));
@@ -226,29 +203,30 @@ void test_step_finished_fires_test_failure_and_test_finished_for_skipped_step_wi
@Test
void test_step_undefined_fires_test_failure_and_test_finished_for_undefined_step() {
+ MockRunNotifier runNotifier = new MockRunNotifier();
jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
Suggestion suggestion = new Suggestion("step name", singletonList("some snippet"));
bus.send(new SnippetsSuggestedEvent(now(), featureUri, scenarioLine, scenarioLine, suggestion));
bus.send(new TestCaseStarted(now(), testCase));
- bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
+ bus.send(new TestStepStarted(now(), testCase, testStep));
Throwable exception = new CucumberException("No step definitions found");
Result result = new Result(Status.UNDEFINED, ZERO, exception);
- bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
+ bus.send(new TestStepFinished(now(), testCase, testStep, result));
- verify(runNotifier).fireTestFailure(failureArgumentCaptor.capture());
- verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
+ assertEquals(1, runNotifier.testFailures.size());
+ assertEquals(pickleRunner.describeChild(step), runNotifier.testFinishedDescription);
- Failure stepFailure = failureArgumentCaptor.getValue();
+ Failure stepFailure = runNotifier.testFailures.get(0);
assertThat(stepFailure.getDescription(), is(equalTo(pickleRunner.describeChild(step))));
assertThat(stepFailure.getException(), is(equalTo(exception)));
bus.send(new TestCaseFinished(now(), testCase, result));
- verify(runNotifier, times(2)).fireTestFailure(failureArgumentCaptor.capture());
- verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
+ assertEquals(2, runNotifier.testFailures.size());
+ assertEquals(pickleRunner.describeChild(step), runNotifier.testFinishedDescription);
- Failure pickleFailure = failureArgumentCaptor.getValue();
+ Failure pickleFailure = runNotifier.testFailures.get(1);
assertThat(pickleFailure.getDescription(), is(equalTo(pickleRunner.getDescription())));
assertThat(pickleFailure.getException().getMessage(), is("" +
"The step 'step name' is undefined.\n" +
@@ -259,77 +237,79 @@ void test_step_undefined_fires_test_failure_and_test_finished_for_undefined_step
@Test
void test_step_finished_fires_test_failure_and_test_finished_for_failed_step() {
+ MockRunNotifier runNotifier = new MockRunNotifier();
jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
bus.send(new TestCaseStarted(now(), testCase));
- bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
+ bus.send(new TestStepStarted(now(), testCase, testStep));
Throwable exception = new Exception("Oops");
Result result = new Result(Status.FAILED, ZERO, exception);
- bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
+ bus.send(new TestStepFinished(now(), testCase, testStep, result));
- verify(runNotifier).fireTestFailure(failureArgumentCaptor.capture());
- verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
+ assertEquals(1, runNotifier.testFailures.size());
+ assertEquals(pickleRunner.describeChild(step), runNotifier.testFinishedDescription);
- Failure stepFailure = failureArgumentCaptor.getValue();
+ Failure stepFailure = runNotifier.testFailures.get(0);
assertThat(stepFailure.getDescription(), is(equalTo(pickleRunner.describeChild(step))));
assertThat(stepFailure.getException(), is(equalTo(exception)));
bus.send(new TestCaseFinished(now(), testCase, result));
- verify(runNotifier, times(2)).fireTestFailure(failureArgumentCaptor.capture());
- verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
+ assertEquals(2, runNotifier.testFailures.size());
+ assertEquals(pickleRunner.describeChild(step), runNotifier.testFinishedDescription);
- Failure pickleFailure = failureArgumentCaptor.getValue();
+ Failure pickleFailure = runNotifier.testFailures.get(1);
assertThat(pickleFailure.getDescription(), is(equalTo(pickleRunner.getDescription())));
assertThat(pickleFailure.getException(), is(equalTo(exception)));
}
@Test
void test_step_finished_fires_test_failure_and_test_finished_for_failed_hook() {
-
+ MockRunNotifier runNotifier = new MockRunNotifier();
jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
bus.send(new TestCaseStarted(now(), testCase));
- bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
+ bus.send(new TestStepStarted(now(), testCase, testStep));
Result stepResult = new Result(Status.PASSED, ZERO, null);
- bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), stepResult));
+ bus.send(new TestStepFinished(now(), testCase, testStep, stepResult));
- bus.send(new TestStepStarted(now(), testCase, mock(HookTestStep.class)));
+ bus.send(new TestStepStarted(now(), testCase, new StubHookTestStep()));
Throwable exception = new Exception("Oops");
Result result = new Result(Status.FAILED, ZERO, exception);
- bus.send(new TestStepFinished(now(), testCase, mock(HookTestStep.class), result));
+ bus.send(new TestStepFinished(now(), testCase, new StubHookTestStep(), result));
// Hooks are not included in step failure
- verify(runNotifier, never()).fireTestFailure(failureArgumentCaptor.capture());
- verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
+ assertEquals(0, runNotifier.testFailures.size());
+ assertEquals(pickleRunner.describeChild(step), runNotifier.testFinishedDescription);
bus.send(new TestCaseFinished(now(), testCase, result));
- verify(runNotifier).fireTestFailure(failureArgumentCaptor.capture());
- verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
+ assertEquals(1, runNotifier.testFailures.size());
+ assertEquals(pickleRunner.describeChild(step), runNotifier.testFinishedDescription);
- Failure pickleFailure = failureArgumentCaptor.getValue();
+ Failure pickleFailure = runNotifier.testFailures.get(0);
assertThat(pickleFailure.getDescription(), is(equalTo(pickleRunner.getDescription())));
assertThat(pickleFailure.getException(), is(equalTo(exception)));
}
@Test
void test_step_finished_fires_test_failure_and_test_finished_for_failed_step_with_multiple_failure_exception() {
+ MockRunNotifier runNotifier = new MockRunNotifier();
jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
bus.send(new TestCaseStarted(now(), testCase));
- bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
+ bus.send(new TestStepStarted(now(), testCase, testStep));
List failures = asList(
new Exception("Oops"),
new Exception("I did it again"));
Throwable exception = new MultipleFailureException(failures);
Result result = new Result(Status.FAILED, ZERO, exception);
- bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
+ bus.send(new TestStepFinished(now(), testCase, testStep, result));
- verify(runNotifier, times(2)).fireTestFailure(failureArgumentCaptor.capture());
- verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
+ assertEquals(2, runNotifier.testFailures.size());
+ assertEquals(pickleRunner.describeChild(step), runNotifier.testFinishedDescription);
- List stepFailure = failureArgumentCaptor.getAllValues();
+ List stepFailure = runNotifier.testFailures;
assertThat(stepFailure.get(0).getDescription(), is(equalTo(pickleRunner.describeChild(step))));
assertThat(stepFailure.get(0).getException(), is(equalTo(failures.get(0))));
@@ -339,18 +319,181 @@ void test_step_finished_fires_test_failure_and_test_finished_for_failed_step_wit
bus.send(new TestCaseFinished(now(), testCase, result));
- verify(runNotifier, times(4)).fireTestFailure(failureArgumentCaptor.capture());
- verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
+ assertEquals(4, runNotifier.testFailures.size());
+ assertEquals(pickleRunner.describeChild(step), runNotifier.testFinishedDescription);
- List pickleFailure = failureArgumentCaptor.getAllValues();
+ List pickleFailure = runNotifier.testFailures;
- // Mockito recapture all arguments on .capture() so we end up with the
- // original 2, those 2 repeated and the finally the 2 we expect.
- assertThat(pickleFailure.get(4).getDescription(), is(equalTo(pickleRunner.getDescription())));
- assertThat(pickleFailure.get(4).getException(), is(equalTo(failures.get(0))));
+ assertThat(pickleFailure.get(2).getDescription(), is(equalTo(pickleRunner.getDescription())));
+ assertThat(pickleFailure.get(2).getException(), is(equalTo(failures.get(0))));
- assertThat(pickleFailure.get(5).getDescription(), is(equalTo(pickleRunner.getDescription())));
- assertThat(pickleFailure.get(5).getException(), is(equalTo(failures.get(1))));
+ assertThat(pickleFailure.get(3).getDescription(), is(equalTo(pickleRunner.getDescription())));
+ assertThat(pickleFailure.get(3).getException(), is(equalTo(failures.get(1))));
}
+ private static class MockPickleRunner implements PickleRunner {
+ private final Map childDescriptions = new HashMap<>();
+ private final Description description;
+
+ public MockPickleRunner(io.cucumber.plugin.event.Step step) {
+ childDescriptions.put(step, Description.createTestDescription("", step.getText()));
+ description = Description.createTestDescription("", "pickle name");
+ }
+
+ @Override
+ public void run(RunNotifier notifier) {
+ }
+
+ @Override
+ public Description getDescription() {
+ return description;
+ }
+
+ @Override
+ public Description describeChild(io.cucumber.plugin.event.Step step) {
+ return childDescriptions.get(step);
+ }
+ }
+
+ private static class StubPickleStepTestStep implements PickleStepTestStep {
+ private final URI uri;
+ private final Step step;
+
+ public StubPickleStepTestStep(URI featureUri, Step step) {
+ uri = featureUri;
+ this.step = step;
+ }
+
+ @Override
+ public String getPattern() {
+ return null;
+ }
+
+ @Override
+ public io.cucumber.plugin.event.Step getStep() {
+ return step;
+ }
+
+ @Override
+ public List getDefinitionArgument() {
+ return null;
+ }
+
+ @Override
+ public StepArgument getStepArgument() {
+ return null;
+ }
+
+ @Override
+ public int getStepLine() {
+ return 0;
+ }
+
+ @Override
+ public URI getUri() {
+ return uri;
+ }
+
+ @Override
+ public String getStepText() {
+ return null;
+ }
+
+ @Override
+ public String getCodeLocation() {
+ return null;
+ }
+
+ @Override
+ public UUID getId() {
+ return null;
+ }
+ }
+
+ private static class StubTestCase implements TestCase {
+ @Override
+ public Integer getLine() {
+ return null;
+ }
+
+ @Override
+ public Location getLocation() {
+ return null;
+ }
+
+ @Override
+ public String getKeyword() {
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public String getScenarioDesignation() {
+ return null;
+ }
+
+ @Override
+ public List getTags() {
+ return null;
+ }
+
+ @Override
+ public List getTestSteps() {
+ return null;
+ }
+
+ @Override
+ public URI getUri() {
+ return null;
+ }
+
+ @Override
+ public UUID getId() {
+ return null;
+ }
+ }
+
+ private static class MockRunNotifier extends RunNotifier {
+ List testAssumptionFailedFailures = new ArrayList<>();
+ List testFailures = new ArrayList<>();
+
+ Description testStartedDescription;
+ Description testFinishedDescription;
+
+ @Override
+ public void fireTestAssumptionFailed(Failure failure) {
+ this.testAssumptionFailedFailures.add(failure);
+ }
+
+ @Override
+ public void fireTestFailure(Failure failure) {
+ this.testFailures.add(failure);
+ }
+
+ @Override
+ public void fireTestStarted(Description description) throws StoppedByUserException {
+ this.testStartedDescription = description;
+ }
+
+ @Override
+ public void fireTestFinished(Description description) {
+ this.testFinishedDescription = description;
+ }
+ }
+
+ private static class StubHookTestStep implements TestStep {
+ @Override
+ public String getCodeLocation() {
+ return null;
+ }
+
+ @Override
+ public UUID getId() {
+ return null;
+ }
+ }
}
diff --git a/cucumber-junit/src/test/java/io/cucumber/junit/PickleRunnerWithNoStepDescriptionsTest.java b/cucumber-junit/src/test/java/io/cucumber/junit/PickleRunnerWithNoStepDescriptionsTest.java
index cca3622051..56cf3449d4 100644
--- a/cucumber-junit/src/test/java/io/cucumber/junit/PickleRunnerWithNoStepDescriptionsTest.java
+++ b/cucumber-junit/src/test/java/io/cucumber/junit/PickleRunnerWithNoStepDescriptionsTest.java
@@ -18,13 +18,12 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.mockito.Mockito.mock;
class PickleRunnerWithNoStepDescriptionsTest {
final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
final Options options = RuntimeOptions.defaultOptions();
- final RunnerSupplier runnerSupplier = mock(RunnerSupplier.class);
+ final RunnerSupplier runnerSupplier = new StubRunnerSupplier();
final CucumberExecutionContext context = new CucumberExecutionContext(bus, new ExitStatus(options), runnerSupplier);
@Test
diff --git a/cucumber-junit/src/test/java/io/cucumber/junit/PickleRunnerWithStepDescriptionsTest.java b/cucumber-junit/src/test/java/io/cucumber/junit/PickleRunnerWithStepDescriptionsTest.java
index 83f3cd4ff1..862189ff4a 100644
--- a/cucumber-junit/src/test/java/io/cucumber/junit/PickleRunnerWithStepDescriptionsTest.java
+++ b/cucumber-junit/src/test/java/io/cucumber/junit/PickleRunnerWithStepDescriptionsTest.java
@@ -22,13 +22,12 @@
import static io.cucumber.junit.TestPickleBuilder.picklesFromFeature;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
-import static org.mockito.Mockito.mock;
class PickleRunnerWithStepDescriptionsTest {
final EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
final Options options = RuntimeOptions.defaultOptions();
- final RunnerSupplier runnerSupplier = mock(RunnerSupplier.class);
+ final RunnerSupplier runnerSupplier = new StubRunnerSupplier();
final CucumberExecutionContext context = new CucumberExecutionContext(bus, new ExitStatus(options), runnerSupplier);
@Test
diff --git a/cucumber-junit/src/test/java/io/cucumber/junit/StubRunnerSupplier.java b/cucumber-junit/src/test/java/io/cucumber/junit/StubRunnerSupplier.java
new file mode 100644
index 0000000000..70feaec53d
--- /dev/null
+++ b/cucumber-junit/src/test/java/io/cucumber/junit/StubRunnerSupplier.java
@@ -0,0 +1,11 @@
+package io.cucumber.junit;
+
+import io.cucumber.core.runner.Runner;
+import io.cucumber.core.runtime.RunnerSupplier;
+
+class StubRunnerSupplier implements RunnerSupplier {
+ @Override
+ public Runner get() {
+ return null;
+ }
+}
diff --git a/cucumber-spring/pom.xml b/cucumber-spring/pom.xml
index fcb2683df5..62a2759804 100644
--- a/cucumber-spring/pom.xml
+++ b/cucumber-spring/pom.xml
@@ -17,7 +17,6 @@
5.11.2
6.1.13
io.cucumber.spring
- 5.14.2
@@ -90,12 +89,6 @@
${hamcrest.version}
test
-
- org.mockito
- mockito-junit-jupiter
- ${mockito.version}
- test
-
diff --git a/cucumber-spring/src/test/java/io/cucumber/spring/SpringBackendTest.java b/cucumber-spring/src/test/java/io/cucumber/spring/SpringBackendTest.java
index f3f8a1b035..636689967e 100644
--- a/cucumber-spring/src/test/java/io/cucumber/spring/SpringBackendTest.java
+++ b/cucumber-spring/src/test/java/io/cucumber/spring/SpringBackendTest.java
@@ -1,38 +1,45 @@
package io.cucumber.spring;
+import io.cucumber.core.backend.DataTableTypeDefinition;
+import io.cucumber.core.backend.DefaultDataTableCellTransformerDefinition;
+import io.cucumber.core.backend.DefaultDataTableEntryTransformerDefinition;
+import io.cucumber.core.backend.DefaultParameterTransformerDefinition;
+import io.cucumber.core.backend.DocStringTypeDefinition;
import io.cucumber.core.backend.Glue;
+import io.cucumber.core.backend.HookDefinition;
import io.cucumber.core.backend.ObjectFactory;
+import io.cucumber.core.backend.ParameterTypeDefinition;
+import io.cucumber.core.backend.StaticHookDefinition;
+import io.cucumber.core.backend.StepDefinition;
import io.cucumber.spring.annotationconfig.AnnotationContextConfiguration;
import io.cucumber.spring.cucumbercontextconfigannotation.AbstractWithComponentAnnotation;
import io.cucumber.spring.cucumbercontextconfigannotation.AnnotatedInterface;
import io.cucumber.spring.cucumbercontextconfigannotation.WithMetaAnnotation;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
import static java.lang.Thread.currentThread;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-@ExtendWith(MockitoExtension.class)
class SpringBackendTest {
- @Mock
- private Glue glue;
+ private final Glue glue = new MockGlue();
- @Mock
- private ObjectFactory factory;
+ private MockObjectFactory factory;
private SpringBackend backend;
@BeforeEach
void createBackend() {
+ this.factory = new MockObjectFactory();
this.backend = new SpringBackend(factory, currentThread()::getContextClassLoader);
}
@@ -40,7 +47,7 @@ void createBackend() {
void finds_annotation_context_configuration_by_classpath_url() {
backend.loadGlue(glue, singletonList(URI.create("classpath:io/cucumber/spring/annotationconfig")));
backend.buildWorld();
- verify(factory).addClass(AnnotationContextConfiguration.class);
+ assertTrue(factory.classes.contains(AnnotationContextConfiguration.class));
}
@Test
@@ -49,7 +56,8 @@ void finds_annotaiton_context_configuration_once_by_classpath_url() {
URI.create("classpath:io/cucumber/spring/annotationconfig"),
URI.create("classpath:io/cucumber/spring/annotationconfig")));
backend.buildWorld();
- verify(factory, times(1)).addClass(AnnotationContextConfiguration.class);
+ assertTrue(factory.classes.contains(AnnotationContextConfiguration.class));
+ assertEquals(1, factory.classes.size());
}
@Test
@@ -57,7 +65,7 @@ void ignoresAbstractClassWithCucumberContextConfiguration() {
backend.loadGlue(glue, singletonList(
URI.create("classpath:io/cucumber/spring/cucumbercontextconfigannotation")));
backend.buildWorld();
- verify(factory, times(0)).addClass(AbstractWithComponentAnnotation.class);
+ assertFalse(factory.classes.contains(AbstractWithComponentAnnotation.class));
}
@Test
@@ -65,7 +73,7 @@ void ignoresInterfaceWithCucumberContextConfiguration() {
backend.loadGlue(glue, singletonList(
URI.create("classpath:io/cucumber/spring/cucumbercontextconfigannotation")));
backend.buildWorld();
- verify(factory, times(0)).addClass(AnnotatedInterface.class);
+ assertFalse(factory.classes.contains(AnnotatedInterface.class));
}
@Test
@@ -73,7 +81,105 @@ void considersClassWithCucumberContextConfigurationMetaAnnotation() {
backend.loadGlue(glue, singletonList(
URI.create("classpath:io/cucumber/spring/cucumbercontextconfigannotation")));
backend.buildWorld();
- verify(factory, times(1)).addClass(WithMetaAnnotation.class);
+ assertTrue(factory.classes.contains(WithMetaAnnotation.class));
+ }
+
+ private static class MockObjectFactory implements ObjectFactory {
+ List> classes = new ArrayList<>();
+ boolean started = false;
+ boolean stopped = false;
+
+ @Override
+ public boolean addClass(Class> glueClass) {
+ return classes.add(glueClass);
+ }
+
+ @Override
+ public T getInstance(Class glueClass) {
+ return null;
+ }
+
+ @Override
+ public void start() {
+ started = true;
+ }
+
+ @Override
+ public void stop() {
+ stopped = true;
+ }
+ }
+
+ private static class MockGlue implements Glue {
+
+ @Override
+ public void addBeforeAllHook(StaticHookDefinition beforeAllHook) {
+
+ }
+
+ @Override
+ public void addAfterAllHook(StaticHookDefinition afterAllHook) {
+
+ }
+
+ @Override
+ public void addStepDefinition(StepDefinition stepDefinition) {
+
+ }
+
+ @Override
+ public void addBeforeHook(HookDefinition beforeHook) {
+
+ }
+
+ @Override
+ public void addAfterHook(HookDefinition afterHook) {
+
+ }
+
+ @Override
+ public void addBeforeStepHook(HookDefinition beforeStepHook) {
+
+ }
+
+ @Override
+ public void addAfterStepHook(HookDefinition afterStepHook) {
+
+ }
+
+ @Override
+ public void addParameterType(ParameterTypeDefinition parameterType) {
+
+ }
+
+ @Override
+ public void addDataTableType(DataTableTypeDefinition dataTableType) {
+
+ }
+
+ @Override
+ public void addDefaultParameterTransformer(DefaultParameterTransformerDefinition defaultParameterTransformer) {
+
+ }
+
+ @Override
+ public void addDefaultDataTableEntryTransformer(
+ DefaultDataTableEntryTransformerDefinition defaultDataTableEntryTransformer
+ ) {
+
+ }
+
+ @Override
+ public void addDefaultDataTableCellTransformer(
+ DefaultDataTableCellTransformerDefinition defaultDataTableCellTransformer
+ ) {
+
+ }
+
+ @Override
+ public void addDocStringType(DocStringTypeDefinition docStringType) {
+
+ }
}
}
diff --git a/cucumber-spring/src/test/java/io/cucumber/spring/TestTestContextAdaptorTest.java b/cucumber-spring/src/test/java/io/cucumber/spring/TestContextAdaptorTest.java
similarity index 57%
rename from cucumber-spring/src/test/java/io/cucumber/spring/TestTestContextAdaptorTest.java
rename to cucumber-spring/src/test/java/io/cucumber/spring/TestContextAdaptorTest.java
index 72ea9c0245..2dcdc35724 100644
--- a/cucumber-spring/src/test/java/io/cucumber/spring/TestTestContextAdaptorTest.java
+++ b/cucumber-spring/src/test/java/io/cucumber/spring/TestContextAdaptorTest.java
@@ -3,196 +3,211 @@
import io.cucumber.core.backend.CucumberBackendException;
import io.cucumber.spring.beans.BellyBean;
import io.cucumber.spring.beans.DummyComponent;
-import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
-import org.mockito.InOrder;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;
import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.TestContext;
import org.springframework.test.context.TestContextManager;
import org.springframework.test.context.TestExecutionListener;
+import java.util.ArrayList;
+import java.util.List;
+
import static io.cucumber.spring.TestContextAdaptor.create;
import static java.util.Collections.singletonList;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.inOrder;
-
-@ExtendWith(MockitoExtension.class)
-public class TestTestContextAdaptorTest {
-
- @Mock
- TestExecutionListener listener;
- @AfterEach
- void verifyNoMoroInteractions() {
- Mockito.verifyNoMoreInteractions(listener);
- }
+class TestContextAdaptorTest {
@Test
- void invokesAllLiveCycleHooks() throws Exception {
+ void invokesAllLiveCycleHooks() {
+ MockTestExecutionListener listener = new MockTestExecutionListener();
TestContextManager manager = new TestContextManager(SomeContextConfiguration.class);
TestContextAdaptor adaptor = create(() -> manager, singletonList(SomeContextConfiguration.class));
manager.registerTestExecutionListeners(listener);
- InOrder inOrder = inOrder(listener);
adaptor.start();
- inOrder.verify(listener).beforeTestClass(any());
- inOrder.verify(listener).prepareTestInstance(any());
- inOrder.verify(listener).beforeTestMethod(any());
- inOrder.verify(listener).beforeTestExecution(any());
-
+ assertIterableEquals(List.of(
+ "beforeTestClass",
+ "prepareTestInstance",
+ "beforeTestMethod",
+ "beforeTestExecution"),
+ listener.events);
+
+ listener.events.clear();
adaptor.stop();
- inOrder.verify(listener).afterTestExecution(any());
- inOrder.verify(listener).afterTestMethod(any());
- inOrder.verify(listener).afterTestClass(any());
+ assertIterableEquals(List.of(
+ "afterTestExecution",
+ "afterTestMethod",
+ "afterTestClass"),
+ listener.events);
}
@Test
- void invokesAfterClassIfBeforeClassFailed() throws Exception {
+ void invokesAfterClassIfBeforeClassFailed() {
+ MockTestExecutionListener listener = new MockTestExecutionListener("beforeTestClass");
TestContextManager manager = new TestContextManager(SomeContextConfiguration.class);
TestContextAdaptor adaptor = create(() -> manager, singletonList(SomeContextConfiguration.class));
manager.registerTestExecutionListeners(listener);
- InOrder inOrder = inOrder(listener);
-
- doThrow(new RuntimeException()).when(listener).beforeTestClass(any());
assertThrows(CucumberBackendException.class, adaptor::start);
- inOrder.verify(listener).beforeTestClass(any());
+ assertIterableEquals(List.of(
+ "beforeTestClass"),
+ listener.events);
+ listener.events.clear();
adaptor.stop();
- inOrder.verify(listener).afterTestClass(any());
+ assertIterableEquals(List.of(
+ "afterTestClass"),
+ listener.events);
}
@Test
- void invokesAfterClassIfPrepareTestInstanceFailed() throws Exception {
+ void invokesAfterClassIfPrepareTestInstanceFailed() {
+ MockTestExecutionListener listener = new MockTestExecutionListener("prepareTestInstance");
TestContextManager manager = new TestContextManager(SomeContextConfiguration.class);
TestContextAdaptor adaptor = create(() -> manager, singletonList(SomeContextConfiguration.class));
manager.registerTestExecutionListeners(listener);
- InOrder inOrder = inOrder(listener);
-
- doThrow(new RuntimeException()).when(listener).prepareTestInstance(any());
assertThrows(CucumberBackendException.class, adaptor::start);
- inOrder.verify(listener).beforeTestClass(any());
+ assertIterableEquals(List.of(
+ "beforeTestClass",
+ "prepareTestInstance"),
+ listener.events);
+ listener.events.clear();
adaptor.stop();
- inOrder.verify(listener).afterTestClass(any());
+ assertIterableEquals(List.of(
+ "afterTestClass"),
+ listener.events);
}
@Test
- void invokesAfterMethodIfBeforeMethodThrows() throws Exception {
+ void invokesAfterMethodIfBeforeMethodThrows() {
+ MockTestExecutionListener listener = new MockTestExecutionListener("beforeTestMethod");
TestContextManager manager = new TestContextManager(SomeContextConfiguration.class);
TestContextAdaptor adaptor = create(() -> manager, singletonList(SomeContextConfiguration.class));
manager.registerTestExecutionListeners(listener);
- InOrder inOrder = inOrder(listener);
-
- doThrow(new RuntimeException()).when(listener).beforeTestMethod(any());
assertThrows(CucumberBackendException.class, adaptor::start);
- inOrder.verify(listener).beforeTestClass(any());
- inOrder.verify(listener).prepareTestInstance(any());
- inOrder.verify(listener).beforeTestMethod(any());
+ assertIterableEquals(List.of(
+ "beforeTestClass",
+ "prepareTestInstance",
+ "beforeTestMethod"),
+ listener.events);
+ listener.events.clear();
adaptor.stop();
- inOrder.verify(listener).afterTestMethod(any());
- inOrder.verify(listener).afterTestClass(any());
+ assertIterableEquals(List.of(
+ "afterTestMethod",
+ "afterTestClass"),
+ listener.events);
}
@Test
- void invokesAfterTestExecutionIfBeforeTestExecutionThrows() throws Exception {
+ void invokesAfterTestExecutionIfBeforeTestExecutionThrows() {
+ MockTestExecutionListener listener = new MockTestExecutionListener("beforeTestExecution");
TestContextManager manager = new TestContextManager(SomeContextConfiguration.class);
TestContextAdaptor adaptor = create(() -> manager, singletonList(SomeContextConfiguration.class));
manager.registerTestExecutionListeners(listener);
- InOrder inOrder = inOrder(listener);
-
- doThrow(new RuntimeException()).when(listener).beforeTestExecution(any());
assertThrows(CucumberBackendException.class, adaptor::start);
- inOrder.verify(listener).beforeTestClass(any());
- inOrder.verify(listener).prepareTestInstance(any());
- inOrder.verify(listener).beforeTestMethod(any());
-
+ assertIterableEquals(List.of(
+ "beforeTestClass",
+ "prepareTestInstance",
+ "beforeTestMethod",
+ "beforeTestExecution"),
+ listener.events);
+
+ listener.events.clear();
adaptor.stop();
- inOrder.verify(listener).afterTestExecution(any());
- inOrder.verify(listener).afterTestMethod(any());
- inOrder.verify(listener).afterTestClass(any());
+ assertIterableEquals(List.of(
+ "afterTestExecution",
+ "afterTestMethod",
+ "afterTestClass"),
+ listener.events);
}
@Test
- void invokesAfterTestMethodIfAfterTestExecutionThrows() throws Exception {
+ void invokesAfterTestMethodIfAfterTestExecutionThrows() {
+ MockTestExecutionListener listener = new MockTestExecutionListener("afterTestExecution");
TestContextManager manager = new TestContextManager(SomeContextConfiguration.class);
TestContextAdaptor adaptor = create(() -> manager, singletonList(SomeContextConfiguration.class));
manager.registerTestExecutionListeners(listener);
- InOrder inOrder = inOrder(listener);
-
- doThrow(new RuntimeException()).when(listener).afterTestExecution(any());
adaptor.start();
- inOrder.verify(listener).beforeTestClass(any());
- inOrder.verify(listener).prepareTestInstance(any());
- inOrder.verify(listener).beforeTestMethod(any());
- inOrder.verify(listener).beforeTestExecution(any());
-
+ assertIterableEquals(List.of(
+ "beforeTestClass",
+ "prepareTestInstance",
+ "beforeTestMethod",
+ "beforeTestExecution"),
+ listener.events);
+
+ listener.events.clear();
assertThrows(CucumberBackendException.class, adaptor::stop);
- inOrder.verify(listener).afterTestExecution(any());
- inOrder.verify(listener).afterTestMethod(any());
- inOrder.verify(listener).afterTestClass(any());
+ assertIterableEquals(List.of(
+ "afterTestExecution",
+ "afterTestMethod",
+ "afterTestClass"),
+ listener.events);
}
@Test
void invokesAfterTesClassIfAfterTestMethodThrows() throws Exception {
+ MockTestExecutionListener listener = new MockTestExecutionListener("afterTestMethod");
TestContextManager manager = new TestContextManager(SomeContextConfiguration.class);
TestContextAdaptor adaptor = create(() -> manager, singletonList(SomeContextConfiguration.class));
manager.registerTestExecutionListeners(listener);
- InOrder inOrder = inOrder(listener);
-
- doThrow(new RuntimeException()).when(listener).afterTestMethod(any());
adaptor.start();
- inOrder.verify(listener).beforeTestClass(any());
- inOrder.verify(listener).prepareTestInstance(any());
- inOrder.verify(listener).beforeTestMethod(any());
- inOrder.verify(listener).beforeTestExecution(any());
-
+ assertIterableEquals(List.of(
+ "beforeTestClass",
+ "prepareTestInstance",
+ "beforeTestMethod",
+ "beforeTestExecution"),
+ listener.events);
+
+ listener.events.clear();
assertThrows(CucumberBackendException.class, adaptor::stop);
- inOrder.verify(listener).afterTestExecution(any());
- inOrder.verify(listener).afterTestMethod(any());
- inOrder.verify(listener).afterTestClass(any());
+ assertIterableEquals(List.of(
+ "afterTestExecution",
+ "afterTestMethod",
+ "afterTestClass"),
+ listener.events);
}
@Test
- void invokesAllMethodsPriorIfAfterTestClassThrows() throws Exception {
+ void invokesAllMethodsPriorIfAfterTestClassThrows() {
+ MockTestExecutionListener listener = new MockTestExecutionListener("afterTestExecution");
TestContextManager manager = new TestContextManager(SomeContextConfiguration.class);
TestContextAdaptor adaptor = create(() -> manager, singletonList(SomeContextConfiguration.class));
manager.registerTestExecutionListeners(listener);
- InOrder inOrder = inOrder(listener);
-
- doThrow(new RuntimeException()).when(listener).afterTestExecution(any());
adaptor.start();
- inOrder.verify(listener).beforeTestClass(any());
- inOrder.verify(listener).prepareTestInstance(any());
- inOrder.verify(listener).beforeTestMethod(any());
- inOrder.verify(listener).beforeTestExecution(any());
-
+ assertIterableEquals(List.of(
+ "beforeTestClass",
+ "prepareTestInstance",
+ "beforeTestMethod",
+ "beforeTestExecution"),
+ listener.events);
+
+ listener.events.clear();
assertThrows(CucumberBackendException.class, adaptor::stop);
- inOrder.verify(listener).afterTestExecution(any());
- inOrder.verify(listener).afterTestMethod(any());
- inOrder.verify(listener).afterTestClass(any());
+ assertIterableEquals(List.of(
+ "afterTestExecution",
+ "afterTestMethod",
+ "afterTestClass"),
+ listener.events);
}
@ParameterizedTest
@@ -316,4 +331,54 @@ public DummyComponent getDummyComponent() {
}
}
+ private static class MockTestExecutionListener implements TestExecutionListener {
+ private final List eventsThrowingExceptions;
+ List events = new ArrayList<>();
+
+ public MockTestExecutionListener(String... eventsThrowingExceptions) {
+ this.eventsThrowingExceptions = List.of(eventsThrowingExceptions);
+ }
+
+ private void addEvent(String eventName) {
+ events.add(eventName);
+ if (eventsThrowingExceptions.contains(eventName)) {
+ throw new RuntimeException(eventName);
+ }
+ }
+
+ @Override
+ public void beforeTestClass(TestContext testContext) {
+ addEvent("beforeTestClass");
+ }
+
+ @Override
+ public void prepareTestInstance(TestContext testContext) {
+ addEvent("prepareTestInstance");
+ }
+
+ @Override
+ public void beforeTestMethod(TestContext testContext) {
+ addEvent("beforeTestMethod");
+ }
+
+ @Override
+ public void beforeTestExecution(TestContext testContext) {
+ addEvent("beforeTestExecution");
+ }
+
+ @Override
+ public void afterTestExecution(TestContext testContext) {
+ addEvent("afterTestExecution");
+ }
+
+ @Override
+ public void afterTestMethod(TestContext testContext) {
+ addEvent("afterTestMethod");
+ }
+
+ @Override
+ public void afterTestClass(TestContext testContext) {
+ addEvent("afterTestClass");
+ }
+ }
}
diff --git a/cucumber-testng/pom.xml b/cucumber-testng/pom.xml
index 932e662a63..fc36ba85ea 100644
--- a/cucumber-testng/pom.xml
+++ b/cucumber-testng/pom.xml
@@ -16,7 +16,6 @@
3.0
7.10.2
1.1.2
- 5.14.2
@@ -47,12 +46,6 @@
testng
${testng.version}
-
- org.mockito
- mockito-core
- ${mockito.version}
- test
-
org.hamcrest
hamcrest
diff --git a/cucumber-testng/src/test/java/io/cucumber/testng/TestCaseResultObserverTest.java b/cucumber-testng/src/test/java/io/cucumber/testng/TestCaseResultObserverTest.java
index 7bdbd79844..7c8070e048 100644
--- a/cucumber-testng/src/test/java/io/cucumber/testng/TestCaseResultObserverTest.java
+++ b/cucumber-testng/src/test/java/io/cucumber/testng/TestCaseResultObserverTest.java
@@ -2,6 +2,7 @@
import io.cucumber.core.eventbus.EventBus;
import io.cucumber.core.runtime.TimeServiceEventBus;
+import io.cucumber.plugin.event.Argument;
import io.cucumber.plugin.event.Location;
import io.cucumber.plugin.event.PickleStepTestStep;
import io.cucumber.plugin.event.Result;
@@ -9,14 +10,17 @@
import io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion;
import io.cucumber.plugin.event.Status;
import io.cucumber.plugin.event.Step;
+import io.cucumber.plugin.event.StepArgument;
import io.cucumber.plugin.event.TestCase;
import io.cucumber.plugin.event.TestCaseFinished;
+import io.cucumber.plugin.event.TestStep;
import io.cucumber.plugin.event.TestStepFinished;
import org.testng.SkipException;
import org.testng.annotations.Test;
import java.net.URI;
import java.time.Clock;
+import java.util.List;
import java.util.UUID;
import static io.cucumber.plugin.event.Status.AMBIGUOUS;
@@ -31,8 +35,6 @@
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.expectThrows;
@@ -43,16 +45,11 @@ public class TestCaseResultObserverTest {
private final URI uri = URI.create("file:path/to.feature");
private final Location location = new Location(0, -1);
private final Exception error = new Exception();
- private final TestCase testCase = mock(TestCase.class);
+ private final TestCase testCase = new MockTestCase();
private final PickleStepTestStep step = createPickleStepTestStep();
private PickleStepTestStep createPickleStepTestStep() {
- PickleStepTestStep testStep = mock(PickleStepTestStep.class);
- Step step = mock(Step.class);
- when(step.getLocation()).thenReturn(location);
- when(testStep.getStep()).thenReturn(step);
- when(testStep.getUri()).thenReturn(uri);
- return testStep;
+ return new MockPickleStepTestStep(new MockStep(location), uri);
}
@Test
@@ -200,4 +197,138 @@ public void should_be_skipped_for_skipped_result() {
assertThat(exception.getCause(), instanceOf(SkipException.class));
}
+ private static final class MockStep implements Step {
+ Location location;
+ public MockStep(Location location) {
+ this.location = location;
+ }
+
+ @Override
+ public StepArgument getArgument() {
+ return null;
+ }
+
+ @Override
+ public String getKeyword() {
+ return null;
+ }
+
+ @Override
+ public String getText() {
+ return null;
+ }
+
+ @Override
+ public int getLine() {
+ return 0;
+ }
+
+ @Override
+ public Location getLocation() {
+ return location;
+ }
+ }
+
+ private static class MockPickleStepTestStep implements PickleStepTestStep {
+ private final Step step;
+ private final URI uri;
+
+ public MockPickleStepTestStep(Step step, URI uri) {
+ this.step = step;
+ this.uri = uri;
+ }
+
+ @Override
+ public String getPattern() {
+ return null;
+ }
+
+ @Override
+ public Step getStep() {
+ return step;
+ }
+
+ @Override
+ public List getDefinitionArgument() {
+ return null;
+ }
+
+ @Override
+ public StepArgument getStepArgument() {
+ return null;
+ }
+
+ @Override
+ public int getStepLine() {
+ return 0;
+ }
+
+ @Override
+ public URI getUri() {
+ return uri;
+ }
+
+ @Override
+ public String getStepText() {
+ return null;
+ }
+
+ @Override
+ public String getCodeLocation() {
+ return null;
+ }
+
+ @Override
+ public UUID getId() {
+ return null;
+ }
+ }
+
+ private static class MockTestCase implements TestCase {
+
+ @Override
+ public Integer getLine() {
+ return null;
+ }
+
+ @Override
+ public Location getLocation() {
+ return null;
+ }
+
+ @Override
+ public String getKeyword() {
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public String getScenarioDesignation() {
+ return null;
+ }
+
+ @Override
+ public List getTags() {
+ return null;
+ }
+
+ @Override
+ public List getTestSteps() {
+ return null;
+ }
+
+ @Override
+ public URI getUri() {
+ return null;
+ }
+
+ @Override
+ public UUID getId() {
+ return null;
+ }
+ }
}
diff --git a/datatable/pom.xml b/datatable/pom.xml
index f12a1ce115..35cde460e1 100644
--- a/datatable/pom.xml
+++ b/datatable/pom.xml
@@ -20,7 +20,6 @@
3.0
2.18.0
5.11.2
- 5.14.2
@@ -75,13 +74,6 @@
test
-
- org.mockito
- mockito-junit-jupiter
- ${mockito.version}
- test
-
-
com.google.guava
guava