Skip to content

Commit b0b26a3

Browse files
committed
[JUnit] fireTestAssumptionFailed only for violated assumptions.
* Extract Runtime.isAssumptionViolated from Runtime.isPending. * Use Runtime.isAssumptionViolated as the condition for fireTestAssumptionFailed
1 parent 6beaa7e commit b0b26a3

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

core/src/main/java/cucumber/runtime/Runtime.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
*/
3434
public class Runtime {
3535

36-
private static final String[] PENDING_EXCEPTIONS = {
36+
private static final String[] ASSUMPTION_VIOLATED_EXCEPTIONS = {
3737
"org.junit.AssumptionViolatedException",
3838
"org.junit.internal.AssumptionViolatedException"
3939
};
4040

4141
static {
42-
Arrays.sort(PENDING_EXCEPTIONS);
42+
Arrays.sort(ASSUMPTION_VIOLATED_EXCEPTIONS);
4343
}
4444

4545
private static final byte ERRORS = 0x1;
@@ -236,7 +236,14 @@ public static boolean isPending(Throwable t) {
236236
if (t == null) {
237237
return false;
238238
}
239-
return t.getClass().isAnnotationPresent(Pending.class) || Arrays.binarySearch(PENDING_EXCEPTIONS, t.getClass().getName()) >= 0;
239+
return t.getClass().isAnnotationPresent(Pending.class) || isAssumptionViolated(t);
240+
}
241+
242+
public static boolean isAssumptionViolated(Throwable t) {
243+
if (t == null) {
244+
return false;
245+
}
246+
return Arrays.binarySearch(ASSUMPTION_VIOLATED_EXCEPTIONS, t.getClass().getName()) >= 0;
240247
}
241248

242249
private void addStepToCounterAndResult(Result result) {

junit/src/main/java/cucumber/runtime/junit/JUnitReporter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.junit.runner.notification.RunNotifier;
1414
import org.junit.runners.model.MultipleFailureException;
1515

16+
import static cucumber.runtime.Runtime.isAssumptionViolated;
1617
import static cucumber.runtime.Runtime.isPending;
1718

1819
public class JUnitReporter {
@@ -202,7 +203,7 @@ static class EachTestNotifier implements TestNotifier {
202203
public void addFailure(Throwable targetException) {
203204
if (targetException instanceof MultipleFailureException) {
204205
addMultipleFailureException((MultipleFailureException) targetException);
205-
} else if (isPending(targetException)) {
206+
} else if (isAssumptionViolated(targetException)) {
206207
addFailedAssumption(targetException);
207208
} else {
208209
notifier.fireTestFailure(new Failure(description, targetException));

0 commit comments

Comments
 (0)