title: Is it possible to throw an abstract exception using Mockito?
body: <p>I have a use case where I'm trying to ensure that an abstract exception is thrown when a particular method is called in my class. </p>
  
  <p>I am using Mockito to do this, but have noticed that Mockito is simply not throwing an exception when the method is being called.</p>
  
  <p>Class to be tested:</p>
  
  <pre><code>public void doSomething() throws CustomException {
    try {
      Collection&lt;T&gt; results = dao.getDatabaseResults();
        } catch (ProblemException e) {
            throw new CustomException("There was an exception", e);
    }
  }
  </code></pre>
  
  <p>Problem Exception class:</p>
  
  <pre><code>public abstract class ProblemException extends RuntimeException {
  
    public ProblemException(String message) {
        super(message);
    }
  
    public ProblemException(String message, Throwable e) {
        super(message, e);
    }
  </code></pre>
  
  <p>Test Class:</p>
  
  <pre><code>public testDoSomething() throws Exception {
     CustomDAO mockDAO = Mockito.mock(CustomDAO.class);
  
     Mockito.when(mockDAO.getDatabaseResults()).thenThrow(new ProblemException);
  
     try {
         foo.doSomething();
         Assert.fail();
     } catch (CustomException e) {
        //Some more asserts
     }
  </code></pre>
  
  <p>Currently the above test class won't compile because you can't create a new instance of an abstract class.</p>
  
  <p>I do not have the access to change the AbstractException class and I also cannot change the exception type that is thrown by the getDatabaseResults() method on the DAO class.</p>
  
  <p>Do you have any suggestions on the cleanest solution for this problem?</p>
  
  <p>One thing I can think of is to catch a RuntimeException within my doSomething() method (as ProblemException extends this class).  I was just curious if there are any better ways?</p>
  
  <p>Thanks</p>