assertThrows

public T assertThrows<T extends Throwable>(Class<T> type, Supplier<String> messageSupplier)(source)

Asserts that the call resulted in a throwable of type type and returns the throwable. Otherwise, an AssertionFailedError containing the message supplied by messageSupplier will be thrown. messageSupplier is allowed to supply null.

Return

the throwable resulted by the call

Parameters

type

the type of the expected throwable

messageSupplier

a supplier for the message if the throwable was not thrown

<E>

the type of the expected throwable

See also

Throws

AssertionFailedError

if the call did not result in a throwable of type type