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 java.io.File;
7   import java.io.FileNotFoundException;
8   import java.io.Reader;
9   import java.io.StringReader;
10  
11  import net.sourceforge.pmd.PMD;
12  import net.sourceforge.pmd.Report.ProcessingError;
13  
14  public class PapariTextRendererTest extends AbstractRendererTst {
15  
16      private static String naString = "n/a";
17      static {
18          naString = naString.substring(naString.lastIndexOf(File.separator) + 1);
19      }
20      
21      public Renderer getRenderer() {
22          TextColorRenderer result = new TextColorRenderer(){
23              protected Reader getReader(String sourceFile) throws FileNotFoundException {
24                  return new StringReader("public class Foo {}");
25              }
26          };
27          result.setProperty(TextColorRenderer.COLOR, "false");
28          return result;
29      }
30  
31      public String getExpected() {
32          return "* file: n/a" + PMD.EOL + "    src:  " + naString + ":1:1" + PMD.EOL + "    rule: Foo" + PMD.EOL + "    msg:  msg" + PMD.EOL + "    code: public class Foo {}" + PMD.EOL + PMD.EOL + PMD.EOL + PMD.EOL + "Summary:" + PMD.EOL + PMD.EOL + " : 1" + PMD.EOL + "* warnings: 1" + PMD.EOL;
33      }
34      
35      public String getExpectedEmpty() {
36          return PMD.EOL + PMD.EOL + "Summary:" + PMD.EOL + PMD.EOL + "* warnings: 0" + PMD.EOL;
37      }
38      
39      public String getExpectedMultiple() {
40          return "* file: n/a" + PMD.EOL + "    src:  " + naString + ":1:1" + PMD.EOL + "    rule: Foo" + PMD.EOL + "    msg:  msg" + PMD.EOL + "    code: public class Foo {}" + PMD.EOL + PMD.EOL + "    src:  " + naString + ":1:1" + PMD.EOL + "    rule: Foo" + PMD.EOL + "    msg:  msg" + PMD.EOL + "    code: public class Foo {}" + PMD.EOL + PMD.EOL + PMD.EOL + PMD.EOL + "Summary:" + PMD.EOL + PMD.EOL + " : 2" + PMD.EOL + "* warnings: 2" + PMD.EOL;
41      }
42      
43      public String getExpectedError(ProcessingError error) {
44          return PMD.EOL + PMD.EOL + "Summary:" + PMD.EOL + PMD.EOL + "    err:  Error" + PMD.EOL + PMD.EOL + "* errors:   0" + PMD.EOL + "* warnings: 0" + PMD.EOL;
45      }
46  
47      public static junit.framework.Test suite() {
48          return new junit.framework.JUnit4TestAdapter(PapariTextRendererTest.class);
49      }
50  }