title: Getting Mockito Exception : checked exception is invalid for this method
body: <p>I have a method which I am trying to test</p>
  
  <pre><code>public List&lt;User&gt; getUsers(String state) {
  
          LOG.debug("Executing getUsers");
  
          LOG.info("Fetching users from " + state);
          List&lt;User&gt; users = null;
          try {
              users = userRepo.findByState(state);
              LOG.info("Fetched: " + mapper.writeValueAsString(users));
          }catch (Exception e) {
              LOG.info("Exception occurred while trying to fetch users");
              LOG.debug(e.toString());
              throw new GenericException("FETCH_REQUEST_ERR_002", e.getMessage(), "Error processing fetch request");
          }
          return users;
      }
  </code></pre>
  
  <p>Below is my test code:</p>
  
  <pre><code>@InjectMocks
      private DataFetchService dataFetchService;
  
      @Mock
      private UserRepository userRepository;
  
  @Test
      public void getUsersTest_exception() {
          when(userRepository.findByState("Karnataka")).thenThrow(new Exception("Exception"));
          try {
              dataFetchService.getUsers("Karnataka");
          }catch (Exception e) {
              assertEquals("Exception", e.getMessage());
      }
      }
  </code></pre>
  
  <p>Below is my UserRepository interface:</p>
  
  <pre><code>@Repository
  public interface UserRepository extends CrudRepository&lt;User, Integer&gt; {
  
  public List&lt;User&gt; findByState(String state);
  }
  </code></pre>
  
  <p>When the run my test as Junit test, it gives me following error:</p>
  
  <pre><code>org.mockito.exceptions.base.MockitoException: 
  Checked exception is invalid for this method!
  Invalid: java.lang.Exception: Exception occurred
  </code></pre>
  
  <p>Any idea on how to resolve this? Thanks in advance.</p>