1   /***
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package test.net.sourceforge.pmd.renderers;
5   
6   import net.sourceforge.pmd.AbstractRule;
7   import net.sourceforge.pmd.PMD;
8   import net.sourceforge.pmd.Report;
9   import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
10  import net.sourceforge.pmd.renderers.TextPadRenderer;
11  import test.net.sourceforge.pmd.testframework.RuleTst;
12  
13  public class TextPadRendererTest extends RuleTst {
14  
15      private static class FooRule extends AbstractRule {
16          public Object visit(ASTClassOrInterfaceDeclaration c, Object ctx) {
17              if (c.getImage().equals("Foo")) addViolation(ctx, c);
18              return ctx;
19          }
20  
21          public String getMessage() {
22              return "msg";
23          }
24  
25          public String getName() {
26              return "Foo";
27          }
28  
29          public String getRuleSetName() {
30              return "RuleSet";
31          }
32  
33          public String getDescription() {
34              return "desc";
35          }
36      }
37  
38  
39      public void testNullPassedIn() {
40          try {
41              (new TextPadRenderer()).render(null);
42              fail("Providing a render(null) should throw an npx");
43          } catch (NullPointerException npx) {
44              // cool
45          }
46      }
47  
48      public void testRenderer() throws Throwable {
49          Report rep = new Report();
50          runTestFromString(TEST1, new FooRule(), rep);
51          String actual = (new TextPadRenderer()).render(rep);
52          String expected = PMD.EOL + "n/a(1,  Foo):  msg";
53          assertEquals(expected, actual);
54      }
55  
56      private static final String TEST1 =
57              "public class Foo {}" + PMD.EOL;
58  }
59  
60  
61  
62  
63  
64  
65  
66  
67