### Question:
CSVExporter extends Exporter<T> { @Override public void exportStream(OutputStream outputStream, Iterator<T> iterator) throws IOException, ClassNotFoundException, IllegalAccessException { if (iterator == null) throw new NullPointerException("List can not be null or empty."); Writer writer = new OutputStreamWriter(outputStream, "UTF-8"); ICsvBeanWriter beanWriter = new CsvBeanWriter(writer, preference); while (iterator.hasNext()) { T entry = iterator.next(); beanWriter.write(entry, fieldNames, processors); } beanWriter.flush(); } CSVExporter(Class clazz);  CSVExporter(Class clazz, CsvPreference preference); @Override void exportStream(OutputStream outputStream, Iterator<T> iterator);  }### Answer:
@Test public void testExportStream() throws Exception { ByteArrayOutputStream os = new ByteArrayOutputStream(); CSVExporter<SamplePojo> exporter = new CSVExporter(SamplePojo.class); exporter.exportStream(os, TestData.getData().iterator()); os.flush(); os.close(); CSVImporter<SamplePojo> importer = new CSVImporter<>(SamplePojo.class); List<SamplePojo> list = importer.importStream(new ByteArrayInputStream(os.toByteArray())); assert list.size() == TestData.getData().size(); int index = 0; for (SamplePojo importedPojo : list) { SamplePojo ref = TestData.getData().get(index++); assert importedPojo.equals(ref); } }
@Test(expected = NullPointerException.class) public void testExportNullIterator() throws Exception { ByteArrayOutputStream os = new ByteArrayOutputStream(); CSVExporter<SamplePojo> exporter = new CSVExporter(SamplePojo.class); exporter.exportStream(os, null); }