title: How to test the Spring Boot services Catch Block using Junit 5?
body: <p>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.</p>
  <p>But for sonar coverage I need to cover catch block too in my services.</p>
  <p>My sample code be like</p>
  <pre><code>public void employeeDetails(Object Employee) throws CustomException {
          try {
              int count = commonUtils.calculateEmployeeCount(Employee)
          } catch (Exception e) {
              throw new CustomException(&quot; Exception occurred&quot;, e);
          }
      } 
  </code></pre>
  <p>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.</p>
  <p><strong>Reference</strong></p>
  <p><a href="https://stackoverflow.com/questions/156503/how-do-you-assert-that-a-certain-exception-is-thrown-in-junit-4-tests">How do you assert that a certain exception is thrown in JUnit 4 tests?</a></p>
  <p><a href="https://stackoverflow.com/questions/50458538/how-to-junit-test-a-try-catch-block-in-my-code">How to Junit test a try catch block in my code</a></p>