title: Test output contents to file
body: <p>I have a function write(). This function will output text to a text file and I want to test the output.</p>
  
  <pre><code>public class Item {
  
      String itemOne, itemTwo;
  
      public Item(String itemOne, String itemTwo) {
          this.itemOne = itemOne;
          this.itemTwo = itemTwo;
      }
  
      public String getItemOne() {
          return itemOne;
      }
  
      public String getItemTwo() {
          return itemTwo;
      }
  
      public static void main(String args[]) {
          File outFile = new File("out.txt");
          ArrayList&lt;Item&gt; item = new ArrayList&lt;Item&gt;();
          FileWriter fw = new FileWriter(outFile.getAbsoluteFile());
          BufferedWriter bw = new BufferedWriter(fw);
  
          item.add(new Item("Item 1", "Item 2"));
          item.add(new Item("Item 3", "Item 4"));
          write(bw,item);
      }
  
      public static void write(BufferedWriter bw,ArrayList&lt;Item&gt; item) throws IOException {
          for(int i = 0; i &lt; item.size(); i++) {
  
              bw.write(item.get(i).getItemOne() + "," + item.get(i).getItemTwo());
              bw.newLine();
  
          }
          bw.close();
      }
  }
  </code></pre>
  
  <p>I tried writing the test case but I am not sure how should I write</p>
  
  <pre><code>public class TestCase {
      TestCase testCase = new TestCase();
      @Test
      public void testOutputToFile() throws IOException {
          File outFile = new File("out.txt");
          ArrayList&lt;Item&gt; itemList = new ArrayList&lt;Item&gt;();
          FileWriter fw = new FileWriter(outFile.getAbsoluteFile());
          BufferedWriter bw = new BufferedWriter(fw);
  
          itemList.add(new Item("Item1","Item2")); 
          itemList.add(new Item("Item3","Item4")); 
  
          assertEquals(new Item("Item1","Item2")), bw); 
          assertEquals(new Item("Item3","Item4")), bw); 
      }
  }
  </code></pre>
  
  <p>Please help. I got StackoverflowError after I run my TestCase.java</p>