1 package edu.umd.cs.findbugs.ml; 2 3 import java.util.Collection ; 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 18 protected void setUp() throws Exception { 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 <String > words = splitter.split(); 29 checkContents(words, new String []{"display","gui","window"}); 30 } 31 32 public void testSplit2() { 33 Collection <String > words = splitter2.split(); 34 checkContents(words, new String []{"display","gui","window"}); 35 } 36 37 public void testSplitLong() { 38 Collection <String > words = splitterLong.split(); 39 checkContents(words, new String []{"now","is","the","winter","of","our","discontent"}); 40 } 41 42 public void testAllLower() { 43 Collection <String > words = allLower.split(); 44 checkContents(words, new String []{"foobar"}); 45 } 46 47 public void testAllUpper() { 48 Collection <String > words = allUpper.split(); 49 checkContents(words, new String []{"nsa"}); 50 } 51 52 public void testCapitalized() { 53 Collection <String > words = capitalized.split(); 54 checkContents(words, new String []{"maryland"}); 55 } 56 57 private void checkContents(Collection <String > words, String [] expected) { 58 Assert.assertEquals( expected.length, words.size()); 59 for (String anExpected : expected) { 60 Assert.assertTrue(words.contains(anExpected)); 61 } 62 } 63 } 64 | Popular Tags |