Skip to content

Commit

Permalink
[Core] The SummaryPrinter should only depend on api classes
Browse files Browse the repository at this point in the history
A plugin interface like the SummaryPrinter should only depend on
classes in cucumber.api packages.
  • Loading branch information
brasmusson committed May 13, 2018
1 parent 8c69975 commit 9aea0fb
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 16 deletions.
8 changes: 5 additions & 3 deletions core/src/main/java/cucumber/api/SummaryPrinter.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package cucumber.api;

import cucumber.runtime.Runtime;

/**
* Interface for plugins that print a summary after test execution.
*
* @see Plugin
*/
public interface SummaryPrinter extends Plugin {
void print(Runtime runtime);
/**
* Handles the printing of the summary to the console
* @param summaryPrinter Provides method to print the stats, errors and snippets
*/
void print(SummaryPrintingInterface summaryPrinting);
}
31 changes: 31 additions & 0 deletions core/src/main/java/cucumber/api/SummaryPrintingInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cucumber.api;

import java.io.PrintStream;
import java.util.List;

/**
* Provides methods for printing the statistics, errors and snippets to
* a SummaryPrinter plugin.
*
*/
public interface SummaryPrintingInterface {
/**
* Prints the statistics to the PrintStream argument.
* @param out The PrintStrema to print to.
*/
void printStats(PrintStream out);

/**
* Returns the errors that occurred during the execution of the test cases
* from the feature files.
* @return the errors.
*/
List<Throwable> getErrors();

/**
* Returns the snippets created for the undefined steps encountered during
* the execution of the test cases from the feature files.
* @return the snippets.
*/
List<String> getSnippets();
}
21 changes: 11 additions & 10 deletions core/src/main/java/cucumber/runtime/DefaultSummaryPrinter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cucumber.runtime;

import cucumber.api.SummaryPrinter;
import cucumber.api.SummaryPrintingInterface;

import java.io.PrintStream;
import java.util.List;
Expand All @@ -13,27 +14,27 @@ public DefaultSummaryPrinter() {
}

@Override
public void print(Runtime runtime) {
public void print(SummaryPrintingInterface summaryPrinting) {
out.println();
printStats(runtime);
printStats(summaryPrinting);
out.println();
printErrors(runtime);
printSnippets(runtime);
printErrors(summaryPrinting);
printSnippets(summaryPrinting);
}

private void printStats(Runtime runtime) {
runtime.printStats(out);
private void printStats(SummaryPrintingInterface summaryPrinting) {
summaryPrinting.printStats(out);
}

private void printErrors(Runtime runtime) {
for (Throwable error : runtime.getErrors()) {
private void printErrors(SummaryPrintingInterface summaryPrinting) {
for (Throwable error : summaryPrinting.getErrors()) {
error.printStackTrace(out);
out.println();
}
}

private void printSnippets(Runtime runtime) {
List<String> snippets = runtime.getSnippets();
private void printSnippets(SummaryPrintingInterface summaryPrinting) {
List<String> snippets = summaryPrinting.getSnippets();
if (!snippets.isEmpty()) {
out.append("\n");
out.println("You can implement missing steps with the snippets below:");
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/cucumber/runtime/NullSummaryPrinter.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package cucumber.runtime;

import cucumber.api.SummaryPrinter;
import cucumber.api.SummaryPrintingInterface;

public class NullSummaryPrinter implements SummaryPrinter {

@Override
public void print(Runtime runtime) {
public void print(SummaryPrintingInterface summaryPrinting) {
// Do nothing
}

Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/cucumber/runtime/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cucumber.api.StepDefinitionReporter;
import cucumber.api.SummaryPrinter;
import cucumber.api.SummaryPrintingInterface;
import cucumber.api.event.TestRunFinished;
import cucumber.runner.EventBus;
import cucumber.runner.Runner;
Expand All @@ -24,7 +25,7 @@
/**
* This is the main entry point for running Cucumber features.
*/
public class Runtime {
public class Runtime implements SummaryPrintingInterface {

final Stats stats; // package private to be available for tests.
private final UndefinedStepsTracker undefinedStepsTracker = new UndefinedStepsTracker();
Expand Down Expand Up @@ -143,7 +144,7 @@ public void printSummary() {
summaryPrinter.print(this);
}

void printStats(PrintStream out) {
public void printStats(PrintStream out) {
stats.printStats(out, runtimeOptions.isStrict());
}

Expand Down

0 comments on commit 9aea0fb

Please sign in to comment.