title: Test a method which throws an exception using Junit
body: <p>I am trying to write a test case for a method which throws an exception based on certain logic. However the test case fails as the expected exception and obtained exceptions are different.</p>
  
  <p>Method to test - </p>
  
  <pre><code>public void methodA (//parameters) throws ExceptionA
  {
  certainlogic=//call some method
  if (certainlogic)
  throw new ExceptionA(//exception details)
  else
  //code snippet
  }
  </code></pre>
  
  <p>Test method - </p>
  
  <pre><code>    @Test (expected=ExceptionA.class)
      public void testMethodA
      {
      try
      {
      when (//mock method).thenReturn(true);
      //call methodA
      }
      catch (ExceptionA e)
      {
      fail(e.printStackTrace(e));
      }
      }
  </code></pre>
  
  <p>I am receiving the below error - </p>
  
  <pre><code>Unexpected exception, expected&lt;cExceptionA&gt; but was&lt;java.lang.AssertionError&gt;
  </code></pre>
  
  <p>How do I solve this issue?</p>