core - CSVRenderer: add unit test for escaping filenames (#100)

This commit is contained in:
Andreas Dangel 2016-06-25 09:07:21 +02:00
parent a92bac5d84
commit 8ab06f3f9e

View File

@ -13,7 +13,6 @@ import net.sourceforge.pmd.PMD;
import org.junit.Test;
public class CSVRendererTest {
@Test
public void testLineCountPerFile() {
Renderer renderer = new CSVRenderer(true);
@ -32,6 +31,23 @@ public class CSVRendererTest {
assertEquals(expectedReport, report);
}
@Test
public void testFilenameEscapes() {
Renderer 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);
String report = renderer.render(list.iterator());
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);
}
private Mark createMark(String image, String tokenSrcID, int beginLine, int lineCount, String code) {
Mark result = new Mark(new TokenEntry(image, tokenSrcID, beginLine));
@ -39,9 +55,5 @@ public class CSVRendererTest {
result.setSoureCodeSlice(code);
return result;
}
public static junit.framework.Test suite() {
return new junit.framework.JUnit4TestAdapter(CSVRendererTest.class);
}
}