View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.renderers;
5   
6   import net.sourceforge.pmd.PMD;
7   import net.sourceforge.pmd.Report.ProcessingError;
8   
9   public class XMLRendererTest extends AbstractRendererTst {
10  
11      @Override
12      public Renderer getRenderer() {
13          return new XMLRenderer();
14      }
15  
16      @Override
17      public String getExpected() {
18          return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
19                  + PMD.EOL
20                  + "<pmd version=\""
21                  + PMD.VERSION
22                  + "\" timestamp=\"2014-10-06T19:30:51.262\">"
23                  + PMD.EOL
24                  + "<file name=\"n/a\">"
25                  + PMD.EOL
26                  + "<violation beginline=\"1\" endline=\"1\" begincolumn=\"1\" endcolumn=\"1\" rule=\"Foo\" ruleset=\"RuleSet\" priority=\"5\">"
27                  + PMD.EOL + "blah" + PMD.EOL + "</violation>" + PMD.EOL + "</file>" + PMD.EOL + "</pmd>" + PMD.EOL;
28      }
29  
30      @Override
31      public String getExpectedEmpty() {
32          return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + PMD.EOL + "<pmd version=\"" + PMD.VERSION
33                  + "\" timestamp=\"2014-10-06T19:30:51.262\">" + PMD.EOL + "</pmd>" + PMD.EOL;
34      }
35  
36      @Override
37      public String getExpectedMultiple() {
38          return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
39                  + PMD.EOL
40                  + "<pmd version=\""
41                  + PMD.VERSION
42                  + "\" timestamp=\"2014-10-06T19:30:51.239\">"
43                  + PMD.EOL
44                  + "<file name=\"n/a\">"
45                  + PMD.EOL
46                  + "<violation beginline=\"1\" endline=\"1\" begincolumn=\"1\" endcolumn=\"1\" rule=\"Foo\" ruleset=\"RuleSet\" priority=\"5\">"
47                  + PMD.EOL
48                  + "blah"
49                  + PMD.EOL
50                  + "</violation>"
51                  + PMD.EOL
52                  + "<violation beginline=\"1\" endline=\"1\" begincolumn=\"1\" endcolumn=\"2\" rule=\"Foo\" ruleset=\"RuleSet\" priority=\"5\">"
53                  + PMD.EOL + "blah" + PMD.EOL + "</violation>" + PMD.EOL + "</file>" + PMD.EOL + "</pmd>" + PMD.EOL;
54      }
55  
56      @Override
57      public String getExpectedError(ProcessingError error) {
58          return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + PMD.EOL + "<pmd version=\"" + PMD.VERSION
59                  + "\" timestamp=\"2014-10-06T19:30:51.222\">" + PMD.EOL + "<error filename=\"file\" msg=\"Error\"/>"
60                  + PMD.EOL + "</pmd>" + PMD.EOL;
61      }
62  
63      @Override
64      public String filter(String expected) {
65          String result = expected.replaceAll(" timestamp=\"[^\"]+\">", " timestamp=\"\">");
66          return result;
67      }
68  }