Skip to content

Commit

Permalink
Merge #1135 'Add --[no-]step-notifications JUnit option'
Browse files Browse the repository at this point in the history
Also update History.md.
  • Loading branch information
brasmusson committed May 28, 2017
2 parents 8831fb3 + b0b26a3 commit a38911e
Show file tree
Hide file tree
Showing 16 changed files with 703 additions and 290 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [2.0.0-SNAPSHOT](https://github.com/cucumber/cucumber-jvm/compare/v1.2.5...master) (In Git)

* [JUnit] Add `--[no-]step-notifications` option to JunitOptions ([#1135](https://github.com/cucumber/cucumber-jvm/pull/1135), [#263](https://github.com/cucumber/cucumber-jvm/issues/263), [#577](https://github.com/cucumber/cucumber-jvm/issues/577) mpkorstanje)
* [JUnit] Use deterministic unique ids in Descriptions ([#1134](https://github.com/cucumber/cucumber-jvm/pull/1134), [#1120](https://github.com/cucumber/cucumber-jvm/issues/1120) mpkorstanje)
* [All] Support [Tag Expressions](https://github.com/cucumber/cucumber/tree/master/tag-expressions) (part of [#1035](https://github.com/cucumber/cucumber-jvm/pull/1035) Björn Rasmusson)
* [All] Upgrade to Gherkin 4.1 ([#1035](https://github.com/cucumber/cucumber-jvm/pull/1035), [#1131](https://github.com/cucumber/cucumber-jvm/pull/1131), [#1133](https://github.com/cucumber/cucumber-jvm/pull/1133) Björn Rasmusson, mpkorstanje). This also fixes:
Expand Down
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

0 comments on commit a38911e

Please sign in to comment.