src/main/java/org/cornutum/hamcrest/ExpectedFailure.java
/**
   * Throws an AssertionError if the expected Throwable is not thrown by the given action.
   * The expected Throwable is defined by applying the <CODE>failureMapper</CODE> to the
   * Throwable produced by the action.
   */
Throws an AssertionError if the expected Throwable is not thrown by the given action.
The expected Throwable is defined by applying the failureMapper to the
Throwable produced by the action.
Throws an AssertionError if the expected Throwable is not thrown by the given action . The expected Throwable is defined by applying the failureMapper to the Throwable produced by the action .
@SuppressWarnings("unchecked")
  public ExpectedFailure<T> when( Failable action, Function<Throwable,Throwable> failureMapper)
    {
    expected = Optional.empty();
    Throwable failure = action.get().map( t -> failureMapper.apply(t)).orElse( null);
    if( failure == null)
      {
      throw new AssertionError( "Expected " + failureType.getSimpleName() + " was not thrown");
      }
    if( !failureType.isInstance( failure))
      {
      throw new AssertionError( "Unexpected failure: " + failure);
      }
    expected = Optional.of( (T) failure);
    return this;
    }
@ SuppressWarnings ( "unchecked" ) public ExpectedFailure < T > when ( Failable action , Function < Throwable , Throwable > failureMapper ) { expected = Optional . empty ( ) ; Throwable failure = action . get ( ) . map ( t -> failureMapper . apply ( t ) ) . orElse ( null ) ; if ( failure == null ) { throw new AssertionError ( "Expected " + failureType . getSimpleName ( ) + " was not thrown" ) ; } if ( ! failureType . isInstance ( failure ) ) { throw new AssertionError ( "Unexpected failure: " + failure ) ; } expected = Optional . of ( ( T ) failure ) ; return this ; }
Throws an AssertionError if the expected Throwable is not thrown by the given action.
Throws an AssertionError if the expected Throwable is not thrown by the given action .