### Question:
CsvFiles { public static void writeCsv(List<String[]> csvData, String fileName) throws IOException { Preconditions.checkNotNull(csvData, "Null CSV data"); Preconditions.checkNotNull(fileName, "Null file name"); CSVWriter writer = null; try { writer = new CSVWriter(Files.newWriter(new File(fileName), StandardCharsets.UTF_8)); for (String[] line : csvData) { writer.writeNext(line); } } finally { if (writer != null) { writer.close(); } } } private  CsvFiles(); static Map<String, String> getCsvDataMap(String fileName,
      final int key, final int value, boolean headerPresent); static Map<String, String> getCsvDataMap(String fileName, boolean headerPresent); static Map<String, String[]> getCsvDataMapArray(String fileName, boolean headerPresent); static List<Map<String, String>> getCsvDataListMap(String fileName,
      boolean headerPresent); static List<String> getCsvDataByColumn(String fileName, final int column,
      boolean headerPresent); static List<String[]> getCsvDataArray(String fileName, boolean headerPresent); static List<String[]> getCsvDataArray(Reader csvReader, boolean headerPresent); static void writeCsv(List<String[]> csvData, String fileName);  }### Answer:
@Test public void testWriteCsv() throws IOException { File csvFile = tempFolder.newFile(); CsvFiles.writeCsv(dataList, csvFile.getPath()); List<String> actualLines = Files.readLines(csvFile, StandardCharsets.UTF_8); assertEquals(dataList.size(), actualLines.size()); Splitter splitter = Splitter.on(',').trimResults(CharMatcher.is('"')); for (int i = 0; i < dataList.size(); i++) { String actualLine = actualLines.get(i); String[] actualValues = Iterables.toArray(splitter.split(actualLine), String.class); String[] expectedValues = dataList.get(i); assertArrayEquals("Row " + i + " does not match", expectedValues, actualValues); } }
@Test public void testWriteCsv_nullData_fails() throws IOException { thrown.expect(NullPointerException.class); thrown.expectMessage("Null CSV data"); CsvFiles.writeCsv(null, "/tmp/foobar"); }
@Test public void testWriteCsv_null_fails() throws IOException { thrown.expect(NullPointerException.class); thrown.expectMessage("Null file name"); CsvFiles.writeCsv(dataList, null); }