I particularly like the fluent style for asserting features of the thrown exception. (from the README) ..
// given: an empty list
List myList = new ArrayList();
// when: we try to get the first element of the list
when(myList).get(1);
// then: we expect an IndexOutOfBoundsException
then(caughtException())
.isInstanceOf(IndexOutOfBoundsException.class)
.hasMessage("Index: 1, Size: 0")
.hasNoCause();
I always recommend some testing of the message to ensure your failing for the right reason. I've seen countless examples where the exception type was valid but the reason was not what was expected.
I wondered if you'd seen: https://github.com/Codearte/catch-exception
I particularly like the fluent style for asserting features of the thrown exception. (from the README) ..
I always recommend some testing of the message to ensure your failing for the right reason. I've seen countless examples where the exception type was valid but the reason was not what was expected.