In my business logic I don't have any scenario for exception, Not sure how to test the catch block in sprint boot Service class. Most of the scenarios are handled in controller level.
But for sonar coverage I need to cover catch block too in my services.
My sample code be like
public void employeeDetails(Object Employee) throws CustomException {
try {
int count = commonUtils.calculateEmployeeCount(Employee)
} catch (Exception e) {
throw new CustomException(" Exception occurred", e);
}
}
Whether my business logic should have any failure scenarios to test or we have any option to mock custom virtual exception for testing purpose. Any one please advice on this.
Reference
How do you assert that a certain exception is thrown in JUnit 4 tests?