title: How to test exception scenario in junit 5 in spring boot?
body: <p>I have a void method that does some tasks trying to test exception scenarios but the test case is getting failed.</p>
  <pre><code>public void completetask(){
     try{
       RemoteUser rm = usrRepo.findById(12);
       assistenRepo.save(rm);
     }catch(Exception e){
      log.error(&quot;Exception occurred while making changes {}&quot;, e,getMessage());
     }
  }
  
  </code></pre>
  <p>How can we test the exception scenario here on JUnit 5?</p>
  <p>I have tried this but it's not working</p>
  <pre><code>
  @Test
  public void completetaskTest(){
      RemoteUser rm = getDummyRemoteUsr();
      Mockito.when(usrRepo.findById(12)).thenReturn(rm);
      Mockito.when(assistenRepo.save(rm)).thenThrow(new Exception(&quot;Error Abnormal&quot;));
      Exception exception = Assestions.assertThrow(Exception.class, () -&gt; usrService.completetask());
      String expectedMessage = &quot;Exception occurred while making changes&quot;;
      String actualMessage = exception.getMessage();
      Assertions.assetTrue(actualMessage.contains(expectedMessage));
  }
  
  </code></pre>
  <p>I am getting an error for this test case - the check exception is invalid for this method
  Invalid java.lang.Exception : Error</p>
  <p>Can I know what wrong I am doing here ?</p>