KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > filters > SeverityMatchFilterTest


1 package com.puppycrawl.tools.checkstyle.filters;
2
3 import java.util.regex.PatternSyntaxException JavaDoc;
4
5 import com.puppycrawl.tools.checkstyle.api.AuditEvent;
6 import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;
7 import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
8
9 import junit.framework.TestCase;
10
11 /** Tests SeverityMatchFilter */
12 public class SeverityMatchFilterTest extends TestCase
13 {
14     private SeverityMatchFilter filter;
15
16     public void setUp()
17         throws PatternSyntaxException JavaDoc
18     {
19         filter = new SeverityMatchFilter();
20     }
21
22     public void testDefault()
23     {
24         final AuditEvent ev = new AuditEvent(this, "Test.java");
25         assertFalse("no message", filter.accept(ev));
26         SeverityLevel level = SeverityLevel.ERROR;
27         LocalizedMessage message =
28             new LocalizedMessage(0, 0, "", "", null,
29                 level, null, this.getClass());
30         final AuditEvent ev2 = new AuditEvent(this, "ATest.java", message);
31         assertTrue("level:" + level, filter.accept(ev2));
32         level = SeverityLevel.INFO;
33         message = new LocalizedMessage(0, 0, "", "", null, level, null, this
34                 .getClass());
35         final AuditEvent ev3 = new AuditEvent(this, "ATest.java", message);
36         assertFalse("level:" + level, filter.accept(ev3));
37     }
38
39     public void testSeverity()
40     {
41         filter.setSeverity("info");
42         final AuditEvent ev = new AuditEvent(this, "Test.java");
43         // event with no message has severity level INFO
44
assertTrue("no message", filter.accept(ev));
45         SeverityLevel level = SeverityLevel.ERROR;
46         LocalizedMessage message =
47             new LocalizedMessage(0, 0, "", "", null,
48                 level, null, this.getClass());
49         final AuditEvent ev2 = new AuditEvent(this, "ATest.java", message);
50         assertFalse("level:" + level, filter.accept(ev2));
51         level = SeverityLevel.INFO;
52         message = new LocalizedMessage(0, 0, "", "", null, level, null, this
53                 .getClass());
54         final AuditEvent ev3 = new AuditEvent(this, "ATest.java", message);
55         assertTrue("level:" + level, filter.accept(ev3));
56     }
57
58     public void testAcceptOnMatch()
59     {
60         filter.setSeverity("info");
61         filter.setAcceptOnMatch(false);
62         final AuditEvent ev = new AuditEvent(this, "Test.java");
63         // event with no message has severity level INFO
64
assertFalse("no message", filter.accept(ev));
65         SeverityLevel level = SeverityLevel.ERROR;
66         LocalizedMessage message =
67             new LocalizedMessage(0, 0, "", "", null,
68                 level, null, this.getClass());
69         final AuditEvent ev2 = new AuditEvent(this, "ATest.java", message);
70         assertTrue("level:" + level, filter.accept(ev2));
71         level = SeverityLevel.INFO;
72         message = new LocalizedMessage(0, 0, "", "", null, level, null, this
73                 .getClass());
74         final AuditEvent ev3 = new AuditEvent(this, "ATest.java", message);
75         assertFalse("level:" + level, filter.accept(ev3));
76     }
77 }
78
Popular Tags