title: How to test a print method in Java using Junit
body: <p>I have written a method that is printing output to a console. How should I test it?</p>
  
  <pre><code>public class PrinterForConsole implements Printer&lt;Item&gt;{
  
     public void printResult(List&lt;Item&gt; items) {
          for (Item item: items){
              System.out.println("Name: " + item.getName());
              System.out.println("Number: " + item.getNumber());
  
              }
          }
  }
  </code></pre>
  
  <p>currently, my test looks like this</p>
  
  <pre><code>public class TestPrinter{
      @Test
      public void printResultTest() throws Exception {
              (am figuring out what to put here)
  
          }
  }
  </code></pre>
  
  <p>I have read the solution at this <a href="https://stackoverflow.com/questions/1119385/junit-test-for-system-out-println">post</a> (thanks @Codebender and @KDM for highlighting this) but don't quite understand it. How does the solution there test the print(List items) method? Hence, asking it afresh here.</p>