In Java 8 and JUnit 5 (Jupiter) we can assert for exceptions as follows. Using org.junit.jupiter.api.Assertions.assertThrows. public static T assertThrows (Class expectedType, Executable executable) Asserts that execution of the supplied executable throws an exception of the expectedType and returns the exception. More @Wikipedia
Hover over any link to get a description of the article. Please note that search keywords are sometimes hidden within the full article and don't appear in the description or title.