1 16 package org.apache.commons.collections.set; 17 18 import java.util.ArrayList ; 19 import java.util.Arrays ; 20 import java.util.Comparator ; 21 import java.util.Set ; 22 import java.util.TreeSet ; 23 24 import junit.framework.Test; 25 26 import org.apache.commons.collections.BulkTest; 27 28 37 public class TestUnmodifiableSortedSet extends AbstractTestSortedSet{ 38 39 public TestUnmodifiableSortedSet(String testName) { 40 super(testName); 41 } 42 43 public static Test suite() { 44 return BulkTest.makeSuite(TestUnmodifiableSortedSet.class); 45 } 46 47 public static void main(String args[]) { 48 String [] testCaseName = { TestUnmodifiableSortedSet.class.getName()}; 49 junit.textui.TestRunner.main(testCaseName); 50 } 51 52 public Set makeEmptySet() { 54 return UnmodifiableSortedSet.decorate(new TreeSet ()); 55 } 56 57 public Set makeFullSet() { 58 TreeSet set = new TreeSet (); 59 set.addAll(Arrays.asList(getFullElements())); 60 return UnmodifiableSortedSet.decorate(set); 61 } 62 63 public boolean isAddSupported() { 64 return false; 65 } 66 67 public boolean isRemoveSupported() { 68 return false; 69 } 70 71 protected UnmodifiableSortedSet set = null; 73 protected ArrayList array = null; 74 75 protected void setupSet() { 76 set = (UnmodifiableSortedSet) makeFullSet(); 77 array = new ArrayList (); 78 array.add(new Integer (1)); 79 } 80 81 84 public void testUnmodifiable() { 85 setupSet(); 86 verifyUnmodifiable(set); 87 verifyUnmodifiable(set.headSet(new Integer (1))); 88 verifyUnmodifiable(set.tailSet(new Integer (1))); 89 verifyUnmodifiable(set.subSet(new Integer (1), new Integer (3))); 90 } 91 92 95 public void verifyUnmodifiable(Set set) { 96 try { 97 set.add("value"); 98 fail("Expecting UnsupportedOperationException."); 99 } catch (UnsupportedOperationException e) { 100 } 102 try { 103 set.addAll(new TreeSet ()); 104 fail("Expecting UnsupportedOperationException."); 105 } catch (UnsupportedOperationException e) { 106 } 108 try { 109 set.clear(); 110 fail("Expecting UnsupportedOperationException."); 111 } catch (UnsupportedOperationException e) { 112 } 114 try { 115 set.remove("x"); 116 fail("Expecting UnsupportedOperationException."); 117 } catch (UnsupportedOperationException e) { 118 } 120 try { 121 set.removeAll(array); 122 fail("Expecting UnsupportedOperationException."); 123 } catch (UnsupportedOperationException e) { 124 } 126 try { 127 set.retainAll(array); 128 fail("Expecting UnsupportedOperationException."); 129 } catch (UnsupportedOperationException e) { 130 } 132 } 133 134 public void testComparator() { 135 setupSet(); 136 Comparator c = set.comparator(); 137 assertTrue("natural order, so comparator should be null", c == null); 138 } 139 140 public String getCompatibilityVersion() { 141 return "3.1"; 142 } 143 144 151 } 152 | Popular Tags |