title: How can I unit test this inputStream has been closed?
body: <p>I have a <code>Runnable</code> along the lines of:</p>
  
  <pre><code>    public void run() {
          InputStream inputStream = null;
          try {
              inputStream = new FileInputStream(file);
              //more stuff here
          } 
          catch (Exception e) {
              //simplified for reading
          }
          finally {
              if(inputStream != null) {
                  try {
                      inputStream.close();
                  } catch (IOException e) {}
              }
          }
      }
  </code></pre>
  
  <p>How do I test <code>inputStream.close()</code> was invoked? I am currently using Mockito and JUnit. I know injecting the <code>inputStream</code> in is an idea, but I don't want the resources to be used until <code>run?()</code> is called, hence it being a local variable. So how can I redesign my code in a way that allows me to test whether close was called?</p>