CSVRenderer implements Renderer, CPDRenderer { @Override public String render(Iterator<Match> matches) { StringWriter writer = new StringWriter(1000); try { render(matches, writer); } catch (IOException ignored) { } return writer.toString(); } CSVRenderer();  CSVRenderer(boolean lineCountPerFile);  CSVRenderer(char separatorChar);  CSVRenderer(char separatorChar, boolean lineCountPerFile); @Override String render(Iterator<Match> matches); @Override void render(Iterator<Match> matches, Writer writer); static final char DEFAULT_SEPARATOR; static final boolean DEFAULT_LINECOUNTPERFILE; }
@Test public void testLineCountPerFile() throws IOException { CPDRenderer renderer = new CSVRenderer(true); List<Match> list = new ArrayList<>(); String codeFragment = "code\nfragment"; Mark mark1 = createMark("public", "/var/Foo.java", 48, 10, codeFragment); Mark mark2 = createMark("stuff", "/var/Bar.java", 73, 20, codeFragment); Match match = new Match(75, mark1, mark2); list.add(match); StringWriter sw = new StringWriter(); renderer.render(list.iterator(), sw); String report = sw.toString(); String expectedReport = "tokens,occurrences" + PMD.EOL + "75,2,48,10,/var/Foo.java,73,20,/var/Bar.java" + PMD.EOL; assertEquals(expectedReport, report); }
@Test public void testFilenameEscapes() throws IOException { CPDRenderer renderer = new CSVRenderer(); List<Match> list = new ArrayList<>(); String codeFragment = "code\nfragment"; Mark mark1 = createMark("public", "/var,with,commas/Foo.java", 48, 10, codeFragment); Mark mark2 = createMark("stuff", "/var,with,commas/Bar.java", 73, 20, codeFragment); Match match = new Match(75, mark1, mark2); list.add(match); StringWriter sw = new StringWriter(); renderer.render(list.iterator(), sw); String report = sw.toString(); String expectedReport = "lines,tokens,occurrences" + PMD.EOL + "10,75,2,48,\"/var,with,commas/Foo.java\",73,\"/var,with,commas/Bar.java\"" + PMD.EOL; assertEquals(expectedReport, report); }