title: Test Class using File and FileInputStream with Mockito/PowerMockito
body: <p>I would like to mock a File and FileInputStream Object for an JUnit test.</p>
  
  <p>Let us say we are having a Parser. From outside the Parser is just accessible via the parse(File myFile) method. The other methods like readMyStream....are private.</p>
  
  <p>Example Code:</p>
  
  <pre><code>public class Parser {
  
     public HashMap&lt;String, String&gt; parse(File myFile) throws Exception {
           HashMap&lt;String, String&gt; myConfig;
           Config config;
  
           try {
               //this line gives me a headache
               FileInputStream myFileInputStream = new FileInputStream(myFile);
  
               configStream = readMyStream(myFileInputStream);
                 ..........
           } catch (FileNotFoundException e) {
                  throw e;
           }
           return myConfig;
     }
     //reads the stream 
     private Config readMyStream(FileInputStream myFileInputStream) {
        Config config;    
  
        ...JDOM stuff....    
  
        return config;
     }
  }
  </code></pre>
  
  <p><strong>The problems I face:</strong></p>
  
  <ul>
  <li>how to assert a File Object an FileInputStream (PowerMockito) like this File belongs to this FileInputStream with the following content</li>
  <li>how to mock a private method (Mockito/PowerMockito)</li>
  </ul>
  
  <p>an example of the Mocking/not working :)....</p>
  
  <pre><code>public class ParserTest {
  
     @Test
     public final void testParse() {
        File MOCKEDFILE = PowerMockito.mock(File.class);
        PowerMockito.when(MOCKEDFILE.exists()).thenReturn(true);
        PowerMockito.when(MOCKEDFILE.isFile()).thenReturn(true);
        PowerMockito.when(MOCKEDFILE.isDirectory()).thenReturn(false);
        PowerMockito.when(MOCKEDFILE.createNewFile()).thenReturn(true);
        PowerMockito.when(MOCKEDFILE.length()).thenReturn(11111111L);
  
        //what about the path of MOCKEDFILE which isn't existing
        PowerMockito.when(MOCKEDFILE.getPath()).thenReturn(?????);
  
        //how to assign a File an FileInputStream? (I thought something like)
        PowerMockito.mockStatic(FileInputStream.class);
        FileInputStream MOCKEDINPUTSTREAM = PowerMockito.mock(FileInputStream.class);
        PowerMockito.whenNew(FileInputStream.class).withArguments(File.class).thenReturn(MOCKEDINPUTSTREAM);
  
        //how to mock the private method readMyStream
     }
  </code></pre>