title: How to unit test a method that reads a given file
body: <p>I know this is a bit naive. How to unit test this piece of code without giving physical file as input.
  I am new to mockito and unit testing. So I am not sure. Please help.</p>
  
  <pre><code>public static String fileToString(File file) throws IOException
  {
      BufferedReader br = new BufferedReader(new FileReader(file));
      try {
          StringBuilder sb = new StringBuilder();
          String line = br.readLine();
  
          while (line != null) {
              sb.append(line);
              sb.append("\n");
              line = br.readLine();
          }
          return sb.toString();
      } finally {
          br.close();
      }
  }
  </code></pre>