Assert an Exception Is Thrown in JUnit 4 and 5 | Baeldung
Have a look at how to test if an exception was thrown using JUnit.