View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd;
5   
6   import static org.junit.Assert.assertEquals;
7   import static org.junit.Assert.assertTrue;
8   import net.sourceforge.pmd.lang.LanguageRegistry;
9   import net.sourceforge.pmd.lang.ecmascript.EcmascriptLanguageModule;
10  import net.sourceforge.pmd.lang.ecmascript.ast.ASTFunctionNode;
11  import net.sourceforge.pmd.lang.ecmascript.rule.AbstractEcmascriptRule;
12  import net.sourceforge.pmd.lang.ecmascript.rule.EcmascriptRuleViolationFactory;
13  import net.sourceforge.pmd.testframework.RuleTst;
14  
15  import org.junit.Test;
16  
17  
18  public class ReportTest extends RuleTst {
19  
20      @Test
21      public void testExclusionsInReportWithNOPMDEcmascript() throws Exception {
22          Report rpt = new Report();
23          Rule rule = new AbstractEcmascriptRule() {
24              @Override
25              public Object visit(ASTFunctionNode node, Object data) {
26                  EcmascriptRuleViolationFactory.INSTANCE.addViolation((RuleContext)data, this, node, "Test", null);
27                  return super.visit(node, data);
28              }
29          };
30          String code = "function(x) // NOPMD test suppress\n"
31                  + "{ x = 1; }";
32          runTestFromString(code, rule, rpt, LanguageRegistry.getLanguage(EcmascriptLanguageModule.NAME).getDefaultVersion());
33          assertTrue(rpt.isEmpty());
34          assertEquals(1, rpt.getSuppressedRuleViolations().size());
35      }
36  }