package io.cucumber.core.plugin;

import io.cucumber.core.eventbus.EventBus;
import io.cucumber.core.runtime.TimeServiceEventBus;
import io.cucumber.plugin.event.SnippetsSuggestedEvent;
import io.cucumber.plugin.event.TestRunFinished;
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.ZoneId;
import java.util.UUID;

import static java.nio.charset.StandardCharsets.UTF_8;
import static java.time.Instant.ofEpochSecond;
import static java.util.Collections.singletonList;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

class DefaultSummaryPrinterTest {

    private final ByteArrayOutputStream out = new ByteArrayOutputStream();
    private final DefaultSummaryPrinter summaryPrinter = new DefaultSummaryPrinter(out);
    private final EventBus bus = new TimeServiceEventBus(
        Clock.fixed(ofEpochSecond(0), ZoneId.of("UTC")),
        UUID::randomUUID
    );

    @BeforeEach
    void setup() {
        summaryPrinter.setEventPublisher(bus);
    }

    @Test
    void does_not_print_duplicate_snippets() {
        bus.send(new SnippetsSuggestedEvent(
            bus.getInstant(),
            URI.create("classpath:com/example.feature"),
            12,
            13,
            singletonList("snippet")
        ));

        bus.send(new SnippetsSuggestedEvent(
            bus.getInstant(),
            URI.create("classpath:com/example.feature"),
            12,
            14,
            singletonList("snippet")
        ));

        bus.send(new TestRunFinished(
            bus.getInstant()
        ));

        assertThat(new String(out.toByteArray(), UTF_8), is("" +
            "\n" +
            "0 Scenarios\n" +
            "0 Steps\n" +
            "0m0.000s\n" +
            "\n" +
            "\n" +
            "You can implement missing steps with the snippets below:\n" +
            "\n" +
            "snippet\n" +
            "\n" +
            "\n"
        ));

    }

}
@@ -621,23 +621,32 @@
 est.
-Core
 Matcher
-s.is
+Assert.assertThat
 ;%0Aim
@@ -674,32 +674,70 @@
 est.
-MatcherAssert.assertThat
+text.IsEqualCompressingWhiteSpace.equalToCompressingWhiteSpace
 ;%0A%0Ac
@@ -1793,18 +1793,44 @@
 UTF_8), 
-is
+equalToCompressingWhiteSpace
 (%22%22 +%0A  

fix for DefaultSummaryPrinterTest on Windows (#1957)