title: Mock FileInputStream() with Spock
body: <p>I have the following method which I need to write unit tests with Spock.</p>
  <pre><code>  private Credentials getCredentials() throws IOException {
      return GoogleCredentials.fromStream(new FileInputStream(gcpKey));
    }
  </code></pre>
  <p>I was unable to mock &quot;new FileInputStream(gcpKey)&quot; part.</p>
  <p>what I tried so far is below.
  1.</p>
  <pre><code>given: &quot;mock service&quot;
  
          InputStream inputStream = Mock(InputStream.class)
          
          FileInputStream fileInputStream = Stub(FileInputStream.class){
              new FileInputStream(_) &gt;&gt; inputStream
          }
  </code></pre>
  <ol start="2">
  <li></li>
  </ol>
  <p>given: &quot;mock service&quot;</p>
  <pre><code>        FileInputStream fileInputStream = GroovySpy(name : &quot;name&quot;)
          1 * new FileInputStream(&quot;name&quot;)
  </code></pre>
  <p>Any one have idea regarding this</p>