Skip to content

Commit 56ea5b3

Browse files
U117293U117293
U117293
authored and
U117293
committed
fix: flatten commits for #2767
1 parent 88b70dd commit 56ea5b3

File tree

54 files changed

+3073
-1220
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3073
-1220
lines changed

cucumber-core/pom.xml

-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
<xmlunit.version>2.10.0</xmlunit.version>
2121
<hamcrest.version>3.0</hamcrest.version>
2222
<hamcrest-json.version>0.2</hamcrest-json.version>
23-
<mockito.version>5.14.2</mockito.version>
2423
<vertx.version>4.5.10</vertx.version>
2524
<reactive-streams.version>1.0.4</reactive-streams.version>
2625
</properties>
@@ -143,12 +142,6 @@
143142
<artifactId>junit-jupiter</artifactId>
144143
<scope>test</scope>
145144
</dependency>
146-
<dependency>
147-
<groupId>org.mockito</groupId>
148-
<artifactId>mockito-junit-jupiter</artifactId>
149-
<version>${mockito.version}</version>
150-
<scope>test</scope>
151-
</dependency>
152145
<dependency>
153146
<groupId>io.vertx</groupId>
154147
<artifactId>vertx-web</artifactId>
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,24 @@
11
package io.cucumber.core.order;
22

33
import io.cucumber.core.gherkin.Pickle;
4+
import io.cucumber.core.gherkin.Step;
45
import io.cucumber.plugin.event.Location;
56
import org.junit.jupiter.api.Test;
6-
import org.junit.jupiter.api.extension.ExtendWith;
7-
import org.mockito.Mock;
8-
import org.mockito.junit.jupiter.MockitoExtension;
97

108
import java.net.URI;
119
import java.util.Arrays;
1210
import java.util.List;
1311

1412
import static org.hamcrest.MatcherAssert.assertThat;
1513
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
16-
import static org.mockito.Mockito.when;
1714

18-
@ExtendWith(MockitoExtension.class)
1915
class PickleOrderTest {
2016

21-
@Mock
22-
Pickle firstPickle;
23-
24-
@Mock
25-
Pickle secondPickle;
26-
27-
@Mock
28-
Pickle thirdPickle;
29-
3017
@Test
3118
void lexical_uri_order() {
32-
when(firstPickle.getUri()).thenReturn(URI.create("file:com/example/a.feature"));
33-
when(firstPickle.getLocation()).thenReturn(new Location(2, -1));
34-
when(secondPickle.getUri()).thenReturn(URI.create("file:com/example/a.feature"));
35-
when(secondPickle.getLocation()).thenReturn(new Location(3, -1));
36-
when(thirdPickle.getUri()).thenReturn(URI.create("file:com/example/b.feature"));
19+
Pickle firstPickle = new StubPickle(new Location(2, -1), URI.create("file:com/example/a.feature"));
20+
Pickle secondPickle = new StubPickle(new Location(3, -1), URI.create("file:com/example/a.feature"));
21+
Pickle thirdPickle = new StubPickle(null, URI.create("file:com/example/b.feature"));
3722

3823
PickleOrder order = StandardPickleOrders.lexicalUriOrder();
3924
List<Pickle> pickles = order.orderPickles(Arrays.asList(thirdPickle, secondPickle, firstPickle));
@@ -42,11 +27,9 @@ void lexical_uri_order() {
4227

4328
@Test
4429
void reverse_lexical_uri_order() {
45-
when(firstPickle.getUri()).thenReturn(URI.create("file:com/example/a.feature"));
46-
when(firstPickle.getLocation()).thenReturn(new Location(2, -1));
47-
when(secondPickle.getUri()).thenReturn(URI.create("file:com/example/a.feature"));
48-
when(secondPickle.getLocation()).thenReturn(new Location(3, -1));
49-
when(thirdPickle.getUri()).thenReturn(URI.create("file:com/example/b.feature"));
30+
Pickle firstPickle = new StubPickle(new Location(2, -1), URI.create("file:com/example/a.feature"));
31+
Pickle secondPickle = new StubPickle(new Location(3, -1), URI.create("file:com/example/a.feature"));
32+
Pickle thirdPickle = new StubPickle(null, URI.create("file:com/example/b.feature"));
5033

5134
PickleOrder order = StandardPickleOrders.reverseLexicalUriOrder();
5235
List<Pickle> pickles = order.orderPickles(Arrays.asList(secondPickle, thirdPickle, firstPickle));
@@ -55,9 +38,67 @@ void reverse_lexical_uri_order() {
5538

5639
@Test
5740
void random_order() {
41+
Pickle firstPickle = new StubPickle(new Location(2, -1), URI.create("file:com/example/a.feature"));
42+
Pickle secondPickle = new StubPickle(new Location(3, -1), URI.create("file:com/example/a.feature"));
43+
Pickle thirdPickle = new StubPickle(null, URI.create("file:com/example/b.feature"));
44+
5845
PickleOrder order = StandardPickleOrders.random(42);
5946
List<Pickle> pickles = order.orderPickles(Arrays.asList(firstPickle, secondPickle, thirdPickle));
6047
assertThat(pickles, contains(secondPickle, firstPickle, thirdPickle));
6148
}
6249

50+
private static class StubPickle implements Pickle {
51+
private final Location location;
52+
private final URI uri;
53+
54+
public StubPickle(Location location, URI uri) {
55+
this.location = location;
56+
this.uri = uri;
57+
}
58+
59+
@Override
60+
public String getKeyword() {
61+
return null;
62+
}
63+
64+
@Override
65+
public String getLanguage() {
66+
return null;
67+
}
68+
69+
@Override
70+
public String getName() {
71+
return null;
72+
}
73+
74+
@Override
75+
public Location getLocation() {
76+
return location;
77+
}
78+
79+
@Override
80+
public Location getScenarioLocation() {
81+
return null;
82+
}
83+
84+
@Override
85+
public List<Step> getSteps() {
86+
return null;
87+
}
88+
89+
@Override
90+
public List<String> getTags() {
91+
return null;
92+
}
93+
94+
@Override
95+
public URI getUri() {
96+
return uri;
97+
}
98+
99+
@Override
100+
public String getId() {
101+
return null;
102+
}
103+
}
63104
}

cucumber-core/src/test/java/io/cucumber/core/plugin/CanonicalEventOrderTest.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import io.cucumber.plugin.event.SnippetsSuggestedEvent;
77
import io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion;
88
import io.cucumber.plugin.event.Status;
9-
import io.cucumber.plugin.event.TestCase;
109
import io.cucumber.plugin.event.TestCaseStarted;
1110
import io.cucumber.plugin.event.TestRunFinished;
1211
import io.cucumber.plugin.event.TestRunStarted;
@@ -27,8 +26,6 @@
2726
import static org.hamcrest.number.OrderingComparison.greaterThan;
2827
import static org.hamcrest.number.OrderingComparison.lessThan;
2928
import static org.junit.jupiter.api.Assertions.assertAll;
30-
import static org.mockito.BDDMockito.given;
31-
import static org.mockito.Mockito.mock;
3229

3330
class CanonicalEventOrderTest {
3431

@@ -81,10 +78,7 @@ class CanonicalEventOrderTest {
8178
new Result(Status.PASSED, Duration.ZERO, null));
8279

8380
private static TestCaseStarted createTestCaseEvent(Instant instant, URI uri, int line) {
84-
final TestCase testCase = mock(TestCase.class);
85-
given(testCase.getUri()).willReturn(uri);
86-
given(testCase.getLocation()).willReturn(new Location(line, -1));
87-
return new TestCaseStarted(instant, testCase);
81+
return new TestCaseStarted(instant, new StubTestCase(uri, new Location(line, -1)));
8882
}
8983

9084
@Test

cucumber-core/src/test/java/io/cucumber/core/plugin/PluginFactoryTest.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
import io.cucumber.plugin.EventListener;
1111
import io.cucumber.plugin.event.EventHandler;
1212
import io.cucumber.plugin.event.EventPublisher;
13-
import io.cucumber.plugin.event.PickleStepTestStep;
1413
import io.cucumber.plugin.event.Result;
1514
import io.cucumber.plugin.event.Status;
16-
import io.cucumber.plugin.event.TestCase;
1715
import io.cucumber.plugin.event.TestRunFinished;
1816
import io.cucumber.plugin.event.TestRunStarted;
1917
import io.cucumber.plugin.event.TestStepFinished;
@@ -48,7 +46,6 @@
4846
import static org.junit.jupiter.api.Assertions.assertAll;
4947
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
5048
import static org.junit.jupiter.api.Assertions.assertThrows;
51-
import static org.mockito.Mockito.mock;
5249

5350
class PluginFactoryTest {
5451

@@ -196,8 +193,8 @@ void plugin_does_not_buffer_its_output() {
196193
EventBus bus = new TimeServiceEventBus(new ClockStub(ZERO), UUID::randomUUID);
197194
plugin.setEventPublisher(bus);
198195
Result result = new Result(Status.PASSED, ZERO, null);
199-
TestStepFinished event = new TestStepFinished(bus.getInstant(), mock(TestCase.class),
200-
mock(PickleStepTestStep.class), result);
196+
TestStepFinished event = new TestStepFinished(bus.getInstant(), new StubTestCase(),
197+
new StubPickleStepTestStep(), result);
201198
bus.send(event);
202199

203200
assertThat(mockSystemOut.toString(), is(not(equalTo(""))));

cucumber-core/src/test/java/io/cucumber/core/plugin/PluginsTest.java

+79-31
Original file line numberDiff line numberDiff line change
@@ -6,79 +6,127 @@
66
import io.cucumber.plugin.EventListener;
77
import io.cucumber.plugin.StrictAware;
88
import io.cucumber.plugin.event.Event;
9+
import io.cucumber.plugin.event.EventHandler;
910
import io.cucumber.plugin.event.EventPublisher;
1011
import org.junit.jupiter.api.Test;
11-
import org.junit.jupiter.api.extension.ExtendWith;
12-
import org.mockito.ArgumentCaptor;
13-
import org.mockito.ArgumentMatchers;
14-
import org.mockito.Captor;
15-
import org.mockito.Mock;
16-
import org.mockito.junit.jupiter.MockitoExtension;
17-
18-
import static org.hamcrest.MatcherAssert.assertThat;
19-
import static org.hamcrest.core.Is.is;
20-
import static org.hamcrest.core.IsEqual.equalTo;
21-
import static org.mockito.ArgumentMatchers.eq;
22-
import static org.mockito.Mockito.mock;
23-
import static org.mockito.Mockito.times;
24-
import static org.mockito.Mockito.verify;
25-
26-
@ExtendWith({ MockitoExtension.class })
12+
13+
import java.util.ArrayList;
14+
import java.util.HashMap;
15+
import java.util.List;
16+
import java.util.Map;
17+
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertFalse;
20+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
21+
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
24+
2725
class PluginsTest {
2826

2927
private final PluginFactory pluginFactory = new PluginFactory();
30-
@Mock
31-
private EventPublisher rootEventPublisher;
32-
@Captor
33-
private ArgumentCaptor<EventPublisher> eventPublisher;
3428

3529
@Test
3630
void shouldSetStrictOnPlugin() {
3731
RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
3832
Plugins plugins = new Plugins(pluginFactory, runtimeOptions);
39-
StrictAware plugin = mock(StrictAware.class);
33+
MockStrictAware plugin = new MockStrictAware();
4034
plugins.addPlugin(plugin);
41-
verify(plugin).setStrict(true);
35+
assertTrue(plugin.strict);
4236
}
4337

4438
@Test
4539
void shouldSetMonochromeOnPlugin() {
4640
RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
4741
Plugins plugins = new Plugins(pluginFactory, runtimeOptions);
48-
ColorAware plugin = mock(ColorAware.class);
42+
MockColorAware plugin = new MockColorAware();
4943
plugins.addPlugin(plugin);
50-
verify(plugin).setMonochrome(false);
44+
assertFalse(plugin.monochrome);
5145
}
5246

5347
@Test
5448
void shouldSetConcurrentEventListener() {
5549
RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
5650
Plugins plugins = new Plugins(pluginFactory, runtimeOptions);
57-
ConcurrentEventListener plugin = mock(ConcurrentEventListener.class);
51+
MockConcurrentEventListener plugin = new MockConcurrentEventListener();
52+
EventPublisher rootEventPublisher = new MockEventPublisher();
5853
plugins.addPlugin(plugin);
5954
plugins.setEventBusOnEventListenerPlugins(rootEventPublisher);
60-
verify(plugin, times(1)).setEventPublisher(rootEventPublisher);
55+
56+
assertIterableEquals(List.of(rootEventPublisher), plugin.eventPublishers);
6157
}
6258

6359
@Test
6460
void shouldSetNonConcurrentEventListener() {
6561
RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
6662
Plugins plugins = new Plugins(pluginFactory, runtimeOptions);
67-
EventListener plugin = mock(EventListener.class);
63+
MockEventListener plugin = new MockEventListener();
64+
EventPublisher rootEventPublisher = new MockEventPublisher();
6865
plugins.addPlugin(plugin);
6966
plugins.setSerialEventBusOnEventListenerPlugins(rootEventPublisher);
70-
verify(plugin, times(1)).setEventPublisher(eventPublisher.capture());
71-
assertThat(eventPublisher.getValue().getClass(), is(equalTo(CanonicalOrderEventPublisher.class)));
67+
68+
assertEquals(1, plugin.eventPublishers.size());
69+
assertInstanceOf(CanonicalOrderEventPublisher.class, plugin.eventPublishers.get(0));
7270
}
7371

7472
@Test
7573
void shouldRegisterCanonicalOrderEventPublisherWithRootEventPublisher() {
7674
RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
7775
Plugins plugins = new Plugins(pluginFactory, runtimeOptions);
78-
EventListener plugin = mock(EventListener.class);
76+
MockEventListener plugin = new MockEventListener();
77+
MockEventPublisher rootEventPublisher = new MockEventPublisher();
7978
plugins.addPlugin(plugin);
8079
plugins.setSerialEventBusOnEventListenerPlugins(rootEventPublisher);
81-
verify(rootEventPublisher, times(1)).registerHandlerFor(eq(Event.class), ArgumentMatchers.any());
80+
81+
List<EventHandler<?>> eventHandlers = rootEventPublisher.handlers.get(Event.class);
82+
assertNotNull(eventHandlers);
83+
assertEquals(1, eventHandlers.size());
84+
}
85+
86+
@SuppressWarnings("deprecation")
87+
private static class MockStrictAware implements StrictAware {
88+
Boolean strict;
89+
@Override
90+
public void setStrict(boolean strict) {
91+
this.strict = strict;
92+
}
8293
}
8394

95+
private static class MockColorAware implements ColorAware {
96+
Boolean monochrome;
97+
@Override
98+
public void setMonochrome(boolean monochrome) {
99+
this.monochrome = monochrome;
100+
}
101+
}
102+
103+
private static class MockConcurrentEventListener implements ConcurrentEventListener {
104+
final List<EventPublisher> eventPublishers = new ArrayList<>();
105+
@Override
106+
public void setEventPublisher(EventPublisher publisher) {
107+
eventPublishers.add(publisher);
108+
}
109+
}
110+
111+
private static class MockEventListener implements EventListener {
112+
final List<EventPublisher> eventPublishers = new ArrayList<>();
113+
@Override
114+
public void setEventPublisher(EventPublisher publisher) {
115+
eventPublishers.add(publisher);
116+
}
117+
}
118+
119+
private static class MockEventPublisher implements EventPublisher {
120+
final Map<Class<?>, List<EventHandler<?>>> handlers = new HashMap<>();
121+
@Override
122+
public <T> void registerHandlerFor(Class<T> eventType, EventHandler<T> handler) {
123+
List<EventHandler<?>> eventHandlers = handlers.computeIfAbsent(eventType, key -> new ArrayList<>());
124+
eventHandlers.add(handler);
125+
}
126+
127+
@Override
128+
public <T> void removeHandlerFor(Class<T> eventType, EventHandler<T> handler) {
129+
130+
}
131+
}
84132
}

0 commit comments

Comments
 (0)