1 package com.diasparsoftware.java.util.test; 2 3 import java.util.*; 4 5 import junit.framework.TestCase; 6 7 import com.diasparsoftware.java.util.CollectionUtil; 8 9 public class CaseInsensitiveStringCollectionSearchTest 10 extends TestCase { 11 private Collection empty; 12 private Collection notAStringCollection; 13 private Collection singletonHello; 14 15 protected void setUp() throws Exception { 16 empty = Collections.EMPTY_LIST; 17 notAStringCollection = 18 new HashSet( 19 Arrays.asList( 20 new Object[] { 21 "this is a string", 22 new Integer(762), 23 "this is also a string" })); 24 25 singletonHello = Collections.singleton("hello"); 26 } 27 28 public void testEmptyCollection() { 29 assertFalse( 30 CollectionUtil.stringCollectionContainsIgnoreCase( 31 empty, 32 "hello")); 33 } 34 35 public void testNotAStringCollection() { 36 try { 37 CollectionUtil.stringCollectionContainsIgnoreCase( 38 notAStringCollection, 39 ""); 40 fail("How did you compare a String to not a String?!"); 41 } 42 catch (ClassCastException expected) { 43 } 44 } 45 46 public void testSingleItemMatches() { 47 assertTrue( 48 CollectionUtil.stringCollectionContainsIgnoreCase( 49 singletonHello, 50 "hello")); 51 } 52 53 public void testSingleItemDoesNotMatch() { 54 assertFalse( 55 CollectionUtil.stringCollectionContainsIgnoreCase( 56 singletonHello, 57 "goodbye")); 58 } 59 }