Getting Mockito Exception : checked exception is invalid for this method
You should use RuntimeException
or subclass it. Your method has to declare checked exception (example: findByState(String state) throws IOException;
) otherwise use RuntimeException
:
when(userRepository.findByState("Karnataka"))
.thenThrow(new RuntimeException("Exception"));