KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > UtilsTest


1 package com.puppycrawl.tools.checkstyle;
2
3 import com.puppycrawl.tools.checkstyle.api.Utils;
4 import junit.framework.TestCase;
5 import org.apache.commons.beanutils.ConversionException;
6 import java.util.regex.Pattern JavaDoc;
7
8 public class UtilsTest
9     extends TestCase
10 {
11     /**
12      * Test Utils.countCharInString.
13      */

14     public void testLengthExpandedTabs()
15         throws Exception JavaDoc
16     {
17         String JavaDoc s1 = "\t";
18         assertEquals(8, Utils.lengthExpandedTabs(s1, s1.length(), 8));
19
20         String JavaDoc s2 = " \t";
21         assertEquals(8, Utils.lengthExpandedTabs(s2, s2.length(), 8));
22
23         String JavaDoc s3 = "\t\t";
24         assertEquals(16, Utils.lengthExpandedTabs(s3, s3.length(), 8));
25
26         String JavaDoc s4 = " \t ";
27         assertEquals(9, Utils.lengthExpandedTabs(s4, s4.length(), 8));
28
29         assertEquals(0, Utils.lengthMinusTrailingWhitespace(""));
30         assertEquals(0, Utils.lengthMinusTrailingWhitespace(" \t "));
31         assertEquals(3, Utils.lengthMinusTrailingWhitespace(" 23"));
32         assertEquals(3, Utils.lengthMinusTrailingWhitespace(" 23 \t "));
33
34         final Pattern JavaDoc r1 = Utils.getPattern("a");
35         final Pattern JavaDoc r2 = Utils.getPattern("a");
36         assertEquals(r1, r2);
37     }
38
39     public void testBadRegex()
40     {
41         try {
42             Utils.createPattern("[");
43             fail("expected to get conversion exception");
44         }
45         catch (ConversionException e) {
46             ; // what is expected
47
}
48     }
49
50 }
51
Popular Tags