public void testWriteResultsToFile() {
    List<ITestResult> testResult1 = mock(List.class);
    ResultsForAllTests results1 = mock(ResultsForAllTests.class);
    when(results1.getTestResults()).thenReturn(testResult1);

    List<ITestResult> testResult2 = mock(List.class);
    ResultsForAllTests results2 = mock(ResultsForAllTests.class);
    when(results2.getTestResults()).thenReturn(testResult2);

    String expectedCsvContents1 = "expected-csv-contents1";
    String expectedCsvContents2 = "expected-csv-contents2";
    String expectedSummaryFileContents = "expected-summary-file";
    when(_csvFormater.format(testResult1)).thenReturn(expectedCsvContents1);
    when(_csvFormater.format(testResult2)).thenReturn(expectedCsvContents2);

    _resultsFileWriter.begin();
    _resultsFileWriter.writeResults(results1, "config1.json");

    File resultsFile1 = new File(_outputDir, "config1.csv");
    assertEquals(expectedCsvContents1, FileUtils.readFileAsString(resultsFile1));

    _resultsFileWriter.writeResults(results2, "config2.json");

    File resultsFile2 = new File(_outputDir, "config2.csv");
    assertEquals(expectedCsvContents2, FileUtils.readFileAsString(resultsFile2));

    when(_csvFormater.format(any(List.class))).thenReturn(expectedSummaryFileContents);

    _resultsFileWriter.end();

    File summaryFile = new File(_outputDir, ResultsCsvWriter.TEST_SUMMARY_FILE_NAME);
    assertEquals(expectedSummaryFileContents, FileUtils.readFileAsString(summaryFile));
  }
 @Override
 public void setUp() {
   _resultsFileWriter.setCsvFormater(_csvFormater);
 }