-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JUnit/TestNG] Print snippets for undefined steps as needed
(cherry picked from commit 93659b9)
- Loading branch information
1 parent
e353575
commit 1b5db2b
Showing
9 changed files
with
122 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
core/src/main/java/io/cucumber/core/plugin/UndefinedStepsPrinter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.cucumber.core.plugin; | ||
|
||
import io.cucumber.plugin.EventListener; | ||
import io.cucumber.plugin.StrictAware; | ||
import io.cucumber.plugin.event.EventPublisher; | ||
import io.cucumber.plugin.event.SnippetsSuggestedEvent; | ||
import io.cucumber.plugin.event.TestRunFinished; | ||
|
||
import java.io.PrintStream; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Work around for | ||
*/ | ||
public class UndefinedStepsPrinter implements EventListener, StrictAware { | ||
|
||
private final PrintStream out; | ||
private final List<String> snippets = new ArrayList<>(); | ||
private boolean strict; | ||
|
||
public UndefinedStepsPrinter() { | ||
this.out = System.out; | ||
} | ||
|
||
@Override | ||
public void setStrict(boolean strict) { | ||
this.strict = strict; | ||
} | ||
|
||
@Override | ||
public void setEventPublisher(EventPublisher publisher) { | ||
publisher.registerHandlerFor(SnippetsSuggestedEvent.class, this::handleSnippetSuggestedEvent); | ||
publisher.registerHandlerFor(TestRunFinished.class, this::handleTestRunFinishedEvent); | ||
} | ||
|
||
private void handleSnippetSuggestedEvent(SnippetsSuggestedEvent event) { | ||
snippets.addAll(event.getSnippets()); | ||
} | ||
|
||
private void handleTestRunFinishedEvent(TestRunFinished event) { | ||
if (strict) { | ||
return; | ||
} | ||
|
||
if (!snippets.isEmpty()) { | ||
out.append("\n"); | ||
out.println("There were undefined steps. You can implement missing steps with the snippets below:"); | ||
out.println(); | ||
for (String snippet : snippets) { | ||
out.println(snippet); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters