1 16 package org.apache.commons.collections.set; 17 18 import java.util.Arrays ; 19 import java.util.Set ; 20 import java.util.SortedSet ; 21 import java.util.TreeSet ; 22 23 import junit.framework.Test; 24 25 import org.apache.commons.collections.BulkTest; 26 27 28 37 public class TestTypedSortedSet extends AbstractTestSortedSet{ 38 39 public TestTypedSortedSet(String testName) { 40 super(testName); 41 } 42 43 public static Test suite() { 44 return BulkTest.makeSuite(TestTypedSortedSet.class); 45 } 46 47 public static void main(String args[]) { 48 String [] testCaseName = { TestTypedSortedSet.class.getName()}; 49 junit.textui.TestRunner.main(testCaseName); 50 } 51 52 protected Class integerType = new Integer (0).getClass(); 54 55 public Set makeEmptySet() { 56 return TypedSortedSet.decorate(new TreeSet (), integerType); 57 } 58 59 public Set makeFullSet() { 60 TreeSet set = new TreeSet (); 61 set.addAll(Arrays.asList(getFullElements())); 62 return TypedSortedSet.decorate(set, integerType); 63 } 64 65 66 protected Long getNextAsLong() { 68 SortedSet set = (SortedSet ) makeFullSet(); 69 int nextValue = ((Integer )set.last()).intValue() + 1; 70 return new Long (nextValue); 71 } 72 73 protected Integer getNextAsInt() { 74 SortedSet set = (SortedSet ) makeFullSet(); 75 int nextValue = ((Integer )set.last()).intValue() + 1; 76 return new Integer (nextValue); 77 } 78 79 public void testIllegalAdd() { 80 Set set = makeFullSet(); 81 try { 82 set.add(getNextAsLong()); 83 fail("Should fail type test."); 84 } catch (IllegalArgumentException e) { 85 } 87 assertTrue("Collection shouldn't convert long to int", 88 !set.contains(getNextAsInt())); 89 } 90 91 public void testIllegalAddAll() { 92 Set set = makeFullSet(); 93 Set elements = new TreeSet (); 94 elements.add(getNextAsLong()); 95 try { 96 set.addAll(elements); 97 fail("Should fail type test."); 98 } catch (IllegalArgumentException e) { 99 } 101 assertTrue("Collection shouldn't convert long to int", 102 !set.contains(getNextAsInt())); 103 } 104 105 public boolean skipSerializedCanonicalTests() { 106 return true; } 108 109 } 110 | Popular Tags |