title: How to test read from file and path (using junit)?
body: <p>I need to execute test coverage with the JUnit framework. </p>
  
  <p>I read <a href="http://www.vogella.com/articles/JUnit/article.html" rel="nofollow">JUnit - Tutorial</a> but I can't bind this knowledge with my example. </p>
  
  <p>I understand how I can test method read from file alone but don't know how do this completely with test some path and askUserPathAndWord. How can I make good tests for this?</p>
  
  <pre><code>package task;
  import java.io.*;
  
  class SearchPhrase {
      public void walk(String path, String whatFind) throws IOException {
          File root = new File(path);
          File[] list = root.listFiles();
          for (File titleName : list) {
              if (titleName.isDirectory()) {
                  walk(titleName.getAbsolutePath(), whatFind);
              } else {
                  if (read(titleName.getAbsolutePath()).contains(whatFind)) {
                      System.out.println("File:" + titleName.getAbsolutePath());
                  }
              }
          }
      }
  
      // Read file as one line
      public static String read(String fileName) {
          StringBuilder strBuider = new StringBuilder();
          try {
              BufferedReader in = new BufferedReader(new FileReader(new File(
                      fileName)));
              String strInput;
              while ((strInput = in.readLine()) != null) {
                  strBuider.append(strInput);
                  strBuider.append("\n");
              }
  
              in.close();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          return strBuider.toString();
      }
  
      public void askUserPathAndWord() {
          BufferedReader bufferedReader = new BufferedReader(
                  new InputStreamReader(System.in));
          String path, whatFind;
          try {
              System.out.println("Please, enter a Path and Word"
                      + "(which you want to find):");
              System.out.println("Please enter a Path:");
              path = bufferedReader.readLine();
              System.out.println("Please enter a Word:");
              whatFind = bufferedReader.readLine();
  
              if (path != null &amp;&amp; whatFind != null) {
                  walk(path, whatFind);
                  System.out.println("Thank you!");
              } else {
                  System.out.println("You did not enter anything");
              }
          } catch (IOException | RuntimeException e) {
              System.out.println("Wrong input!");
              e.printStackTrace();
          }
      }
  
      public static void main(String[] args) {
              SearchPhrase example = new SearchPhrase();
              example.askUserPathAndWord();
      }
  }
  </code></pre>
  
  <p>Next <em>questions:</em></p>
  
  <ul>
  <li>How we can completely test integration dependencies and check path?</li>
  <li>Which point should have good, understandably junit test?</li>
  <li>Do we need use fail test in this situations?</li>
  <li>Which max percent program we can cover?</li>
  <li>Should we test private and protected methods (generally)?</li>
  </ul>