CsvConverter implements Converter { @VisibleForTesting static void fillEmptyCells(List<Object[]> rows) { if (rows.size() < 2) { return; } Object[] lastData = rows.get(0).clone(); for (Object[] row : rows) { for (int i = 0; i < row.length; i++) { if (row[i] == null) { row[i] = lastData[i]; } else { lastData[i] = row[i]; } } } } @VisibleForTesting  CsvConverter(Preferences prefs); @Override String formatName(); @Override String fileExtension(); @Override void export(Recording recording, Path destination); @Override List<Group> getSettings(); @SuppressFBWarnings(value = "UC_USELESS_OBJECT", justification = "False positive with List.forEach") String convertToCsv(Recording recording); static final CsvConverter Instance; }
@Test public void testFillEmptyCells() { var rows = List.of( new Object[]{"a", "b"}, new Object[]{null, "b1"}, new Object[]{"a1", null} ); var expected = List.of( new Object[]{"a", "b"}, new Object[]{"a", "b1"}, new Object[]{"a1", "b1"} ); CsvConverter.fillEmptyCells(rows); assertAll( IntStream.range(0, 3) .mapToObj(i -> () -> assertArrayEquals(expected.get(i), rows.get(i), "Row " + i)) ); }