Skip to content

[JUnit] Add --[no-]step-notifications options to JunitOptions #1135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions core/src/main/java/cucumber/runtime/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
*/
public class Runtime {

private static final String[] PENDING_EXCEPTIONS = {
private static final String[] ASSUMPTION_VIOLATED_EXCEPTIONS = {
"org.junit.AssumptionViolatedException",
"org.junit.internal.AssumptionViolatedException"
};

static {
Arrays.sort(PENDING_EXCEPTIONS);
Arrays.sort(ASSUMPTION_VIOLATED_EXCEPTIONS);
}

private static final byte ERRORS = 0x1;
Expand Down Expand Up @@ -236,7 +236,14 @@ public static boolean isPending(Throwable t) {
if (t == null) {
return false;
}
return t.getClass().isAnnotationPresent(Pending.class) || Arrays.binarySearch(PENDING_EXCEPTIONS, t.getClass().getName()) >= 0;
return t.getClass().isAnnotationPresent(Pending.class) || isAssumptionViolated(t);
}

public static boolean isAssumptionViolated(Throwable t) {
if (t == null) {
return false;
}
return Arrays.binarySearch(ASSUMPTION_VIOLATED_EXCEPTIONS, t.getClass().getName()) >= 0;
}

private void addStepToCounterAndResult(Result result) {
Expand Down
161 changes: 0 additions & 161 deletions junit/src/main/java/cucumber/runtime/junit/ExecutionUnitRunner.java

This file was deleted.

28 changes: 19 additions & 9 deletions junit/src/main/java/cucumber/runtime/junit/FeatureRunner.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package cucumber.runtime.junit;

import static cucumber.runtime.junit.PickleRunners.withNoStepDescriptions;
import static cucumber.runtime.junit.PickleRunners.withStepDescriptions;

import cucumber.runtime.CucumberException;
import cucumber.runtime.Runtime;
import cucumber.runtime.junit.PickleRunners.PickleRunner;
import cucumber.runtime.model.CucumberFeature;
import gherkin.ast.Feature;
import gherkin.events.PickleEvent;
Expand All @@ -16,8 +20,8 @@
import java.util.ArrayList;
import java.util.List;

public class FeatureRunner extends ParentRunner<ParentRunner> {
private final List<ParentRunner> children = new ArrayList<ParentRunner>();
public class FeatureRunner extends ParentRunner<PickleRunner> {
private final List<PickleRunner> children = new ArrayList<PickleRunner>();

private final CucumberFeature cucumberFeature;
private Description description;
Expand All @@ -38,7 +42,7 @@ public String getName() {
public Description getDescription() {
if (description == null) {
description = Description.createSuiteDescription(getName(), new FeatureId(cucumberFeature));
for (ParentRunner child : getChildren()) {
for (PickleRunner child : getChildren()) {
description.addChild(describeChild(child));
}
}
Expand All @@ -50,17 +54,17 @@ public boolean isEmpty() {
}

@Override
protected List<ParentRunner> getChildren() {
protected List<PickleRunner> getChildren() {
return children;
}

@Override
protected Description describeChild(ParentRunner child) {
protected Description describeChild(PickleRunner child) {
return child.getDescription();
}

@Override
protected void runChild(ParentRunner child, RunNotifier notifier) {
protected void runChild(PickleRunner child, RunNotifier notifier) {
child.run(notifier);
}

Expand All @@ -78,9 +82,15 @@ private void buildFeatureElementRunners(Runtime runtime, JUnitReporter jUnitRepo
for (PickleEvent pickleEvent : pickleEvents) {
if (runtime.matchesFilters(pickleEvent)) {
try {
ParentRunner pickleRunner;
pickleRunner = new ExecutionUnitRunner(runtime.getRunner(), pickleEvent, jUnitReporter);
children.add(pickleRunner);
if(jUnitReporter.stepNotifications()) {
PickleRunner picklePickleRunner;
picklePickleRunner = withStepDescriptions(runtime.getRunner(), pickleEvent, jUnitReporter);
children.add(picklePickleRunner);
} else {
PickleRunner picklePickleRunner;
picklePickleRunner = withNoStepDescriptions(runtime.getRunner(), pickleEvent, jUnitReporter);
children.add(picklePickleRunner);
}
} catch (InitializationError e) {
throw new CucumberException("Failed to create scenario runner", e);
}
Expand Down
8 changes: 7 additions & 1 deletion junit/src/main/java/cucumber/runtime/junit/JUnitOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class JUnitOptions {

private boolean allowStartedIgnored = false;
private boolean filenameCompatibleNames = false;
private boolean stepNotifications = true;

/**
* Create a new instance from a list of options, for example:
Expand All @@ -38,7 +39,9 @@ private void parse(List<String> args) {
allowStartedIgnored = !arg.startsWith("--no-");
} else if (arg.equals("--no-filename-compatible-names") || arg.equals("--filename-compatible-names")) {
filenameCompatibleNames = !arg.startsWith("--no-");
} else {
} else if (arg.equals("--no-step-notifications") || arg.equals("--step-notifications")) {
stepNotifications = !arg.startsWith("--no-");
} else{
throw new CucumberException("Unknown option: " + arg);
}
}
Expand All @@ -50,6 +53,9 @@ boolean allowStartedIgnored() {
boolean filenameCompatibleNames() {
return filenameCompatibleNames;
}
public boolean stepNotifications(){
return stepNotifications;
}

private void printOptions() {
loadUsageTextIfNeeded();
Expand Down
Loading