From a6e1e8323a9a509bb0a0cc55053032c13d25d75e Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Fri, 22 Apr 2022 15:00:19 +0200 Subject: [PATCH] [Core] Fix Cucumber report spam --- CHANGELOG.md | 1 + .../core/plugin/NoPublishFormatter.java | 4 ++-- .../core/plugin/NoPublishFormatterTest.java | 19 ++++++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51d956c827..3cf4e5407c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Removed ### Fixed +- [Core] Fix cucumber report spam `Collectors.toUnmodifiableList()` ([#2533](https://github.com/cucumber/cucumber-jvm/pull/2533) M.P. Korstanje) ## [7.3.1] (2022-04-20) diff --git a/core/src/main/java/io/cucumber/core/plugin/NoPublishFormatter.java b/core/src/main/java/io/cucumber/core/plugin/NoPublishFormatter.java index 9eb27481d7..b7e0d4ac52 100644 --- a/core/src/main/java/io/cucumber/core/plugin/NoPublishFormatter.java +++ b/core/src/main/java/io/cucumber/core/plugin/NoPublishFormatter.java @@ -35,12 +35,12 @@ public void setEventPublisher(EventPublisher publisher) { } private void writeMessage(Envelope envelope) { - if (envelope.getTestRunFinished() != null) { + if (envelope.getTestRunFinished().isPresent()) { printBanner(); } } - void printBanner() { + private void printBanner() { Banner banner = new Banner(out, monochrome); banner.print( asList( diff --git a/core/src/test/java/io/cucumber/core/plugin/NoPublishFormatterTest.java b/core/src/test/java/io/cucumber/core/plugin/NoPublishFormatterTest.java index d5050dc1af..63c70f8869 100644 --- a/core/src/test/java/io/cucumber/core/plugin/NoPublishFormatterTest.java +++ b/core/src/test/java/io/cucumber/core/plugin/NoPublishFormatterTest.java @@ -1,11 +1,22 @@ package io.cucumber.core.plugin; +import io.cucumber.core.eventbus.EventBus; +import io.cucumber.core.runtime.TimeServiceEventBus; +import io.cucumber.messages.types.Envelope; +import io.cucumber.messages.types.TestRunFinished; +import io.cucumber.messages.types.TestRunStarted; +import io.cucumber.messages.types.Timestamp; +import io.cucumber.plugin.event.EventHandler; +import io.cucumber.plugin.event.EventPublisher; import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; +import java.time.Clock; +import java.time.Instant; +import java.util.UUID; import static io.cucumber.core.plugin.BytesEqualTo.isBytesEqualTo; import static org.hamcrest.MatcherAssert.assertThat; @@ -15,9 +26,15 @@ class NoPublishFormatterTest { public void should_print_banner() throws UnsupportedEncodingException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); PrintStream out = new PrintStream(bytes, false, StandardCharsets.UTF_8.name()); + EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID); + NoPublishFormatter noPublishFormatter = new NoPublishFormatter(out); noPublishFormatter.setMonochrome(true); - noPublishFormatter.printBanner(); + noPublishFormatter.setEventPublisher(bus); + + bus.send(Envelope.of(new TestRunStarted(new Timestamp(0L, 0L)))); + bus.send(Envelope.of(new TestRunFinished(null, true, new Timestamp(0L, 0L)))); + assertThat(bytes, isBytesEqualTo("" + "┌───────────────────────────────────────────────────────────────────────────────────┐\n" + "│ Share your Cucumber Report with your team at https://reports.cucumber.io │\n" +