1 package org.apache.maven.plugins.checkstyle;
2
3 import org.apache.maven.plugins.checkstyle.RuleUtil;
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import junit.framework.TestCase;
25
26 public class RuleUtilTest
27 extends TestCase
28 {
29 private static final String CHECKSTYLE_PACKAGE = "com.puppycrawl.tools.checkstyle.checks";
30
31 public void testGetName()
32 {
33 assertEquals( "FinalParameters", RuleUtil.getName( CHECKSTYLE_PACKAGE + ".FinalParameters" ) );
34 assertEquals( "FinalParameters", RuleUtil.getName( CHECKSTYLE_PACKAGE + ".FinalParametersCheck" ) );
35 assertNull( RuleUtil.getName( (String) null ) );
36 }
37
38 public void testGetCategory()
39 {
40 assertEquals( "misc", RuleUtil.getCategory( CHECKSTYLE_PACKAGE + ".FinalParametersCheck" ) );
41 assertEquals( "test", RuleUtil.getCategory( CHECKSTYLE_PACKAGE + ".test.FinalParametersCheck" ) );
42 assertEquals( "extension", RuleUtil.getCategory( "test.FinalParametersCheck" ) );
43 assertNull( RuleUtil.getCategory( (String) null ) );
44 }
45
46 public void testMatcher()
47 {
48 String[] specs = ( "misc, test, extension, Header, " + CHECKSTYLE_PACKAGE + ".test2" ).split( "," );
49 String[] eventSrcNames =
50 new String[] { CHECKSTYLE_PACKAGE + ".FinalParametersCheck",
51 CHECKSTYLE_PACKAGE + ".test.FinalParametersCheck", "test.FinalParametersCheck",
52 CHECKSTYLE_PACKAGE + ".whitespace.HeaderCheck", CHECKSTYLE_PACKAGE + ".test2.FinalParametersCheck" };
53
54 RuleUtil.Matcher[] matchers = RuleUtil.parseMatchers( specs );
55
56 for ( int i = 0; i < matchers.length; i++ )
57 {
58 String spec = specs[i];
59 RuleUtil.Matcher matcher = matchers[i];
60 for ( int j = 0; j < matchers.length; j++ )
61 {
62 String eventSrcName = eventSrcNames[j];
63 assertEquals( spec + " should" + ( ( i == j ) ? " " : " not " ) + "match " + eventSrcName, i == j,
64 matcher.match( eventSrcName ) );
65 }
66 }
67 }
68 }