KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ml > SplitCamelCaseIdentifierTest


1 package edu.umd.cs.findbugs.ml;
2
3 import java.util.Collection JavaDoc;
4
5 import junit.framework.Assert;
6 import junit.framework.TestCase;
7
8 public class SplitCamelCaseIdentifierTest extends TestCase {
9     SplitCamelCaseIdentifier splitter;
10     SplitCamelCaseIdentifier splitter2;
11     SplitCamelCaseIdentifier splitterLong;
12     SplitCamelCaseIdentifier allLower;
13     SplitCamelCaseIdentifier allUpper;
14     SplitCamelCaseIdentifier capitalized;
15     
16     //@Override
17
@Override JavaDoc
18     protected void setUp() throws Exception JavaDoc {
19         splitter = new SplitCamelCaseIdentifier("displayGUIWindow");
20         splitter2 = new SplitCamelCaseIdentifier("DisplayGUIWindow");
21         splitterLong = new SplitCamelCaseIdentifier("nowIsTheWINTEROfOURDiscontent");
22         allLower = new SplitCamelCaseIdentifier("foobar");
23         allUpper = new SplitCamelCaseIdentifier("NSA");
24         capitalized = new SplitCamelCaseIdentifier("Maryland");
25     }
26     
27     public void testSplit() {
28         Collection JavaDoc<String JavaDoc> words = splitter.split();
29         checkContents(words, new String JavaDoc[]{"display","gui","window"});
30     }
31     
32     public void testSplit2() {
33         Collection JavaDoc<String JavaDoc> words = splitter2.split();
34         checkContents(words, new String JavaDoc[]{"display","gui","window"});
35     }
36     
37     public void testSplitLong() {
38         Collection JavaDoc<String JavaDoc> words = splitterLong.split();
39         checkContents(words, new String JavaDoc[]{"now","is","the","winter","of","our","discontent"});
40     }
41     
42     public void testAllLower() {
43         Collection JavaDoc<String JavaDoc> words = allLower.split();
44         checkContents(words, new String JavaDoc[]{"foobar"});
45     }
46     
47     public void testAllUpper() {
48         Collection JavaDoc<String JavaDoc> words = allUpper.split();
49         checkContents(words, new String JavaDoc[]{"nsa"});
50     }
51     
52     public void testCapitalized() {
53         Collection JavaDoc<String JavaDoc> words = capitalized.split();
54         checkContents(words, new String JavaDoc[]{"maryland"});
55     }
56
57     private void checkContents(Collection JavaDoc<String JavaDoc> words, String JavaDoc[] expected) {
58         Assert.assertEquals( expected.length, words.size());
59         for (String JavaDoc anExpected : expected) {
60             Assert.assertTrue(words.contains(anExpected));
61         }
62     }
63 }
64
Popular Tags