title: How can I unit test a method that uses a Scanner and an InputStream?
body: <p>So here is the code:</p>
  
  <pre><code>public int foo(InputStream in) {
      int counter = 0;
      Scanner scanner = new Scanner(in);
      while(scanner.hasNextLine()) {
          counter++;
          scanner.nextLine();
      }
      return counter;
  }
  </code></pre>
  
  <p>Normally I will be passing a FileInputStream to this method, however I want to be able to test it without accessing a physical file. </p>
  
  <p>Should I mock the File object? How to I implement</p>
  
  <pre><code>@Test
  public void shouldReturnThree(){
  
  }
  </code></pre>