title: Using mockito to test methods which throw uncaught custom exceptions
body: <p>How do I write a Mockito-based JUnit method to test this method <code>adduser()</code>? I tried writing one, but it's failing with an error message saying exception is not handled. The error is displayed for:</p>
  
  <pre><code>when(service.addUser("nginx")).thenReturn("apache");
  </code></pre>
  
  <p>Assume <code>addUser()</code> method in business class never catches any exception and rethrowing is not done.</p>
  
  <pre><code>class Business {
      public User addUser() throws ServiceException{
          User user = service.addUser("nginx");
          return user;
      }
  }
  </code></pre>
  
  <p>TEST CASE METHOD :</p>
  
  <p>Here in the test class I am mocking the service layer class with <code>@Mock</code> attribute and injecting it.</p>
  
  <pre><code>@Mock
  Service service;   
  
  @InjectMocks
  Business business = new Business();
  
  @Test
  public void testAddUser() {
      when(service.addUser("nginx")).thenReturn("apache");    
      User user = business.addUser("nginx");
      assertNotNull(user);
  }
  </code></pre>
  
  <p>Please tell me how to handle the exception scenario in the test case.</p>