Skip to content

Commit

Permalink
Introduce EventConditions.finishedWithFailure() varargs variant
Browse files Browse the repository at this point in the history
Issue: #1621
  • Loading branch information
sbrannen committed Dec 14, 2018
1 parent b37b48e commit c50a343
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// @formatter:off
// tag::user_guide[]

import static org.assertj.core.api.Assertions.allOf;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
import static org.junit.platform.testkit.engine.EventConditions.event;
import static org.junit.platform.testkit.engine.EventConditions.finishedWithFailure;
Expand All @@ -36,8 +35,7 @@ void verifyJupiterMethodFailed() {
.tests() // <4>
.assertThatEvents().haveExactly(1, // <5>
event(test("failingTest"),
finishedWithFailure(
allOf(isA(ArithmeticException.class), message("/ by zero")))));
finishedWithFailure(isA(ArithmeticException.class), message("/ by zero"))));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.junit.platform.testkit.engine;

import static java.util.function.Predicate.isEqual;
import static java.util.stream.Collectors.toCollection;
import static org.apiguardian.api.API.Status.EXPERIMENTAL;
import static org.junit.platform.commons.util.FunctionUtils.where;
import static org.junit.platform.engine.TestExecutionResult.Status.ABORTED;
Expand All @@ -24,6 +25,9 @@
import static org.junit.platform.testkit.engine.EventType.SKIPPED;
import static org.junit.platform.testkit.engine.EventType.STARTED;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

import org.apiguardian.api.API;
Expand Down Expand Up @@ -136,6 +140,23 @@ public static Condition<Event> finishedWithFailure(Condition<? super Throwable>
return finishedWithCause(FAILED, causeCondition);
}

@SafeVarargs
public static Condition<Event> finishedWithFailure(Condition<Throwable>... conditions) {
return finishedWithCause(FAILED, conditions);
}

@SuppressWarnings("unchecked")
private static Condition<Event> finishedWithCause(Status expectedStatus, Condition<Throwable>... conditions) {

List<Condition<TestExecutionResult>> list = Arrays.stream(conditions)//
.map(TestExecutionResultConditions::throwable)//
.collect(toCollection(ArrayList::new));

list.add(0, TestExecutionResultConditions.status(expectedStatus));

return finished(Assertions.allOf(list));
}

private static Condition<Event> finishedWithCause(Status expectedStatus,
Condition<? super Throwable> causeCondition) {

Expand Down

0 comments on commit c50a343

Please sign in to comment.