public static <T> void assertThrows(String message, Class<? extends Exception> exceptionClass, Callable<T> callable) {
        T result;
        try {
            result = callable.call();
            fail(message, "No exception was thrown (expected " + exceptionClass.getSimpleName() + " but '" + result + "' was returned instead)");
        } catch (Exception e) {
            if (!e.getClass().equals(exceptionClass)) {
                fail(message, e.getClass().getSimpleName() + " was thrown instead of " + exceptionClass.getSimpleName());
            }
        }

        pass(message);
    }
public static < T > void assertThrows ( String message , Class < ? extends Exception > exceptionClass , Callable < T > callable ) { T result ; try { result = callable . call ( ) ; fail ( message , "No exception was thrown (expected " + exceptionClass . getSimpleName ( ) + " but '" + result + "' was returned instead)" ) ; } catch ( Exception e ) { if ( ! e . getClass ( ) . equals ( exceptionClass ) ) { fail ( message , e . getClass ( ) . getSimpleName ( ) + " was thrown instead of " + exceptionClass . getSimpleName ( ) ) ; } } pass ( message ) ; }
Assert that a given callable throws an exception of a particular class.
<p>
The assertion passes if the callable throws exactly the same class of exception (not a subclass).
<p>
If the callable doesn't throw an exception at all, or if another class of exception is thrown, the assertion
fails.
<p>
If the assertion passes, a green tick will be shown. If the assertion fails, a red cross will be shown.

@param message        message to display alongside the assertion outcome
@param exceptionClass the expected exception class
@param callable       a Callable to invoke
@param <T>            return type of the callable