|
1 | 1 | package io.cucumber.core.plugin; |
2 | 2 |
|
3 | | -import io.cucumber.core.eventbus.EventBus; |
| 3 | +import io.cucumber.core.backend.StubStepDefinition; |
| 4 | +import io.cucumber.core.feature.TestFeatureParser; |
| 5 | +import io.cucumber.core.gherkin.Feature; |
| 6 | +import io.cucumber.core.options.RuntimeOptionsBuilder; |
| 7 | +import io.cucumber.core.runner.StepDurationTimeService; |
| 8 | +import io.cucumber.core.runtime.Runtime; |
| 9 | +import io.cucumber.core.runtime.StubBackendSupplier; |
| 10 | +import io.cucumber.core.runtime.StubFeatureSupplier; |
4 | 11 | import io.cucumber.core.runtime.TimeServiceEventBus; |
5 | | -import io.cucumber.plugin.event.Location; |
6 | | -import io.cucumber.plugin.event.Result; |
7 | | -import io.cucumber.plugin.event.SnippetsSuggestedEvent; |
8 | | -import io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion; |
9 | | -import io.cucumber.plugin.event.Status; |
10 | | -import io.cucumber.plugin.event.TestRunFinished; |
11 | | -import org.junit.jupiter.api.BeforeEach; |
12 | 12 | import org.junit.jupiter.api.Test; |
13 | 13 |
|
14 | 14 | import java.io.ByteArrayOutputStream; |
15 | | -import java.net.URI; |
16 | | -import java.time.Clock; |
17 | 15 | import java.time.Duration; |
18 | | -import java.time.ZoneId; |
19 | 16 | import java.util.Locale; |
20 | 17 | import java.util.UUID; |
21 | 18 |
|
| 19 | +import static io.cucumber.core.plugin.Bytes.bytes; |
22 | 20 | import static io.cucumber.core.plugin.IsEqualCompressingLineSeparators.equalCompressingLineSeparators; |
23 | | -import static java.nio.charset.StandardCharsets.UTF_8; |
24 | | -import static java.time.Instant.ofEpochSecond; |
25 | | -import static java.util.Collections.singletonList; |
| 21 | +import static io.cucumber.core.plugin.PrettyFormatterStepDefinition.oneReference; |
| 22 | +import static io.cucumber.core.plugin.PrettyFormatterStepDefinition.threeReference; |
| 23 | +import static io.cucumber.core.plugin.PrettyFormatterStepDefinition.twoReference; |
26 | 24 | import static org.hamcrest.MatcherAssert.assertThat; |
27 | 25 |
|
28 | 26 | class DefaultSummaryPrinterTest { |
29 | 27 |
|
30 | | - private final ByteArrayOutputStream out = new ByteArrayOutputStream(); |
31 | | - private final DefaultSummaryPrinter summaryPrinter = new DefaultSummaryPrinter(out, Locale.US); |
32 | | - private final EventBus bus = new TimeServiceEventBus( |
33 | | - Clock.fixed(ofEpochSecond(0), ZoneId.of("UTC")), |
34 | | - UUID::randomUUID); |
35 | | - |
36 | | - @BeforeEach |
37 | | - void setup() { |
38 | | - summaryPrinter.setEventPublisher(bus); |
39 | | - } |
40 | | - |
41 | 28 | @Test |
42 | | - void does_not_print_duplicate_snippets() { |
43 | | - bus.send(new SnippetsSuggestedEvent( |
44 | | - bus.getInstant(), |
45 | | - URI.create("classpath:com/example.feature"), |
46 | | - new Location(12, -1), |
47 | | - new Location(13, -1), |
48 | | - new Suggestion("", singletonList("snippet")))); |
49 | | - |
50 | | - bus.send(new SnippetsSuggestedEvent( |
51 | | - bus.getInstant(), |
52 | | - URI.create("classpath:com/example.feature"), |
53 | | - new Location(12, -1), |
54 | | - new Location(14, -1), |
55 | | - new Suggestion("", singletonList("snippet")))); |
56 | | - |
57 | | - bus.send(new TestRunFinished(bus.getInstant(), new Result(Status.PASSED, Duration.ZERO, null))); |
58 | | - |
59 | | - assertThat(new String(out.toByteArray(), UTF_8), equalCompressingLineSeparators("" + |
| 29 | + void writesSummary() { |
| 30 | + Feature feature = TestFeatureParser.parse("path/test.feature", "" + |
| 31 | + "Feature: feature name\n" + |
| 32 | + " Scenario: scenario name\n" + |
| 33 | + " Given first step\n" + |
| 34 | + " When second step\n" + |
| 35 | + " Then third step\n"); |
| 36 | + |
| 37 | + StepDurationTimeService timeService = new StepDurationTimeService(Duration.ofMillis(1128)); |
| 38 | + ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 39 | + Runtime.builder() |
| 40 | + .withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)) |
| 41 | + .withFeatureSupplier(new StubFeatureSupplier(feature)) |
| 42 | + .withAdditionalPlugins(timeService, new DefaultSummaryPrinter(out, Locale.US)) |
| 43 | + .withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()) |
| 44 | + .withBackendSupplier(new StubBackendSupplier( |
| 45 | + new StubStepDefinition("first step", oneReference()), |
| 46 | + new StubStepDefinition("second step", twoReference()), |
| 47 | + new StubStepDefinition("third step", threeReference()))) |
| 48 | + .build() |
| 49 | + .run(); |
| 50 | + |
| 51 | + assertThat(out, bytes(equalCompressingLineSeparators("" + |
60 | 52 | "\n" + |
61 | | - "0 Scenarios\n" + |
62 | | - "0 Steps\n" + |
63 | | - "0m0.000s\n" + |
64 | | - "\n" + |
65 | | - "\n" + |
66 | | - "You can implement missing steps with the snippets below:\n" + |
67 | | - "\n" + |
68 | | - "snippet\n" + |
69 | | - "\n" + |
70 | | - "\n")); |
71 | | - |
| 53 | + "1 Scenarios (1 passed)\n" + |
| 54 | + "3 Steps (3 passed)\n" + |
| 55 | + "0m3.384s\n"))); |
72 | 56 | } |
73 | 57 |
|
74 | 58 | } |
0 commit comments