title: JUnit AssertionError - Expected exception not thrown
body: <p>I'm trying to familiarise myself with JUnit/Mockito and am using the below method to attempt some unit tests:</p>
  
  <pre><code>public FSDataInputStream getObj(String hName, Path p) throws IOException {
  
      String myKey = pathToKey(hName, p);
      FileStatus status = memoryCache.getStatus(p.toString());
      if (status == null) {
        status = getStatus(hName, p, "getObj");
      }
      if (status.isDirectory()) {
          throw new FileNotFoundException("Can't open " + path
    + " because it is a directory");
      }
      InputStream inputStream = new InputStream(bucket, myKey,
      status.getLen(), client, readAhead, inputPolicy);
  
      return new FSDataInputStream(inputStream);
  }
  </code></pre>
  
  <p>I wish to test that the fileNotFoundException is thrown if status.isDirectory == true.</p>
  
  <p>I believe I must invoke the getObj() method and for <code>if (status.isDirectory())</code> I must ensure the value is true. I think this is done with <code>when(fileStatus.isDirectory()).thenReturn(true);</code> I'm not sure how to invoke the method and make sure this takes place.</p>
  
  <p>So far I've got this JUnit but it doesn't seem to be correct as its returning the below error:</p>
  
  <pre><code>public class ClientTest {
      MemoryCache memoryCache = mock(MemoryCache.class);
      FileStatus fileStatus = mock(FileStatus.class);
  
      @Rule
      public final ExpectedException exception = ExpectedException.none();
  
      @Test
      public void getObjTest() throws Exception {
          Path path = new Path("xyz://aa-bb-cc/data7-1-23-a.txt");
  
          when(memoryCache.getFileStatus(path.toString())).thenReturn(fileStatus);
          when(fileStatus.isDirectory()).thenReturn(true);
          exception.expect(FileNotFoundException.class);
      }
  }
  </code></pre>
  
  <blockquote>
    <p>java.lang.AssertionError: Expected test to throw an instance of java.io.FileNotFoundException
        at org.junit.Assert.fail(Assert.java:88)
        at org.junit.rules.ExpectedException.failDueToMissingException(ExpectedException.java:263)
        at org.junit.rules.ExpectedException.access$200(ExpectedException.java:106)
        at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:245)
        at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:91)
        at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282)
        at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:87)
        at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:50)
        at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:207)
        at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:146)
        at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
        at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
        at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
        at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:122)
        at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:106)
        at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
        at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)</p>
  </blockquote>
  
  <p>Can anybody advise what I'm doing wrong?</p>