1 16 package org.apache.commons.collections; 17 18 import java.util.ArrayList ; 19 import java.util.Collection ; 20 import java.util.List ; 21 22 29 public abstract class TestTypedCollection extends BulkTest { 30 31 public TestTypedCollection(String name) { 32 super(name); 33 } 34 35 36 protected abstract Collection typedCollection(); 37 38 protected Class getType() { 39 return String .class; 40 } 41 42 43 public void testIllegalAdd() { 44 Collection c = typedCollection(); 45 Integer i = new Integer (3); 46 try { 47 c.add(i); 48 fail("Integer should fail string predicate."); 49 } catch (IllegalArgumentException e) { 50 } 52 assertTrue("Collection shouldn't contain illegal element", 53 !c.contains(i)); 54 } 55 56 57 public void testIllegalAddAll() { 58 Collection c = typedCollection(); 59 List elements = new ArrayList (); 60 elements.add("one"); 61 elements.add("two"); 62 elements.add(new Integer (3)); 63 elements.add("four"); 64 try { 65 c.addAll(elements); 66 fail("Integer should fail string predicate."); 67 } catch (IllegalArgumentException e) { 68 } 70 assertTrue("Collection shouldn't contain illegal element", 71 !c.contains("one")); 72 assertTrue("Collection shouldn't contain illegal element", 73 !c.contains("two")); 74 assertTrue("Collection shouldn't contain illegal element", 75 !c.contains(new Integer (3))); 76 assertTrue("Collection shouldn't contain illegal element", 77 !c.contains("four")); 78 } 79 80 } 81 | Popular Tags |