11package io .cucumber .core .plugin ;
22
33import io .cucumber .messages .types .Envelope ;
4- import io .cucumber .messages .types .TestCase ;
54import io .cucumber .messages .types .TestRunFinished ;
6- import io .cucumber .messages .types .TestStep ;
75import io .cucumber .messages .types .TestStepFinished ;
86import io .cucumber .messages .types .TestStepResultStatus ;
97import io .cucumber .plugin .ColorAware ;
1513import java .io .PrintWriter ;
1614import java .nio .charset .StandardCharsets ;
1715import java .util .EnumMap ;
18- import java .util .HashMap ;
1916import java .util .Map ;
2017
2118import static io .cucumber .messages .types .TestStepResultStatus .AMBIGUOUS ;
2825
2926public final class ProgressFormatter implements ConcurrentEventListener , ColorAware {
3027
31- private final Map <String , TestStep > testStepById = new HashMap <>();
3228 private final Map <TestStepResultStatus , String > chars = new EnumMap <>(TestStepResultStatus .class );
3329 private final Map <TestStepResultStatus , AnsiEscapes > escapes = new EnumMap <>(TestStepResultStatus .class );
3430 private final PrintWriter writer ;
3531 private boolean monochrome = false ;
36-
32+
3733 public ProgressFormatter (OutputStream out ) {
3834 this .writer = createPrintWriter (out );
39-
35+
4036 chars .put (PASSED , "." );
4137 chars .put (UNDEFINED , "U" );
4238 chars .put (PENDING , "P" );
@@ -69,20 +65,12 @@ public void setMonochrome(boolean monochrome) {
6965 @ Override
7066 public void setEventPublisher (EventPublisher publisher ) {
7167 publisher .registerHandlerFor (Envelope .class , event -> {
72- event .getTestCase ().ifPresent (this ::updateTestCase );
7368 event .getTestStepFinished ().ifPresent (this ::handleTestStepFinished );
7469 event .getTestRunFinished ().ifPresent (this ::handleTestRunFinished );
7570 });
7671 }
7772
78- private void updateTestCase (TestCase event ) {
79- event .getTestSteps ().forEach (testStep -> testStepById .put (testStep .getId (), testStep ));
80- }
81-
8273 private void handleTestStepFinished (TestStepFinished event ) {
83- if (!includeStep (event )) {
84- return ;
85- }
8674 TestStepResultStatus status = event .getTestStepResult ().getStatus ();
8775 // Prevent tearing in output when multiple threads write to System.out
8876 StringBuilder buffer = new StringBuilder ();
@@ -97,15 +85,6 @@ private void handleTestStepFinished(TestStepFinished event) {
9785 writer .flush ();
9886 }
9987
100- private boolean includeStep (TestStepFinished testStepFinished ) {
101- TestStepResultStatus status = testStepFinished .getTestStepResult ().getStatus ();
102- if (status == FAILED ) {
103- return true ;
104- }
105- TestStep testStep = testStepById .get (testStepFinished .getTestStepId ());
106- return testStep != null && testStep .getPickleStepId ().isPresent ();
107- }
108-
10988 private void handleTestRunFinished (TestRunFinished testRunFinished ) {
11089 writer .println ();
11190 writer .close ();
0 commit comments