Skip to content

Commit

Permalink
Tightened assertException() implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Mar 30, 2017
1 parent 4da3001 commit 17bba54
Showing 1 changed file with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,7 @@ private Assert()
public static <E extends Exception> void assertException( ThrowingAction<E> f, Class typeOfException ) throws
Exception
{
try
{
f.apply();
fail( "Expected exception of type " + typeOfException + ", but no exception was thrown" );
}
catch ( Exception e )
{
if ( !typeOfException.isInstance( e ) )
{
fail( "Got unexpected exception " + e.getClass() + "\nExpected: " + typeOfException );
}
}
assertException( f, typeOfException, null );
}

public static <E extends Exception> void assertException( ThrowingAction<E> f, Class typeOfException,
Expand All @@ -70,7 +59,10 @@ public static <E extends Exception> void assertException( ThrowingAction<E> f, C
{
if ( typeOfException.isInstance( e ) )
{
assertThat( e.getMessage(), containsString( partOfErrorMessage ) );
if ( partOfErrorMessage != null )
{
assertThat( e.getMessage(), containsString( partOfErrorMessage ) );
}
}
else
{
Expand Down

0 comments on commit 17bba54

Please sign in to comment.