File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
src/main/java/org/cornutum/hamcrest Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 99
1010import java .util .Optional ;
1111import java .util .function .Consumer ;
12+ import java .util .function .Function ;
1213import java .util .function .Supplier ;
1314
1415/**
@@ -30,12 +31,22 @@ public ExpectedFailure( Class<T> failureType)
3031 /**
3132 * Throws an AssertionError if the expected Throwable is not thrown by the given action.
3233 */
33- @ SuppressWarnings ("unchecked" )
3434 public ExpectedFailure <T > when ( Failable action )
35+ {
36+ return when ( action , Function .identity ());
37+ }
38+
39+ /**
40+ * Throws an AssertionError if the expected Throwable is not thrown by the given action.
41+ * The expected Throwable is defined by applying the <CODE>failureMapper</CODE> to the
42+ * Throwable produced by the action.
43+ */
44+ @ SuppressWarnings ("unchecked" )
45+ public ExpectedFailure <T > when ( Failable action , Function <Throwable ,Throwable > failureMapper )
3546 {
3647 expected = Optional .empty ();
3748
38- Throwable failure = action .get ().orElse ( null );
49+ Throwable failure = action .get ().map ( t -> failureMapper . apply ( t )). orElse ( null );
3950 if ( failure == null )
4051 {
4152 throw new AssertionError ( "Expected " + failureType .getSimpleName () + " was not thrown" );
You can’t perform that action at this time.
0 commit comments