| Method from org.apache.commons.collections.set.TestUnmodifiableSortedSet Detail: |
public String getCompatibilityVersion() {
return "3.1";
}
|
public boolean isAddSupported() {
return false;
}
|
public boolean isRemoveSupported() {
return false;
}
|
public static void main(String[] args) {
String[] testCaseName = { TestUnmodifiableSortedSet.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
|
public Set makeEmptySet() {
return UnmodifiableSortedSet.decorate(new TreeSet());
}
|
public Set makeFullSet() {
TreeSet set = new TreeSet();
set.addAll(Arrays.asList(getFullElements()));
return UnmodifiableSortedSet.decorate(set);
}
|
protected void setupSet() {
set = (UnmodifiableSortedSet) makeFullSet();
array = new ArrayList();
array.add(new Integer(1));
}
|
public static Test suite() {
return BulkTest.makeSuite(TestUnmodifiableSortedSet.class);
}
|
public void testComparator() {
setupSet();
Comparator c = set.comparator();
assertTrue("natural order, so comparator should be null", c == null);
}
|
public void testUnmodifiable() {
setupSet();
verifyUnmodifiable(set);
verifyUnmodifiable(set.headSet(new Integer(1)));
verifyUnmodifiable(set.tailSet(new Integer(1)));
verifyUnmodifiable(set.subSet(new Integer(1), new Integer(3)));
}
Verify that base set and subsets are not modifiable |
public void verifyUnmodifiable(Set set) {
try {
set.add("value");
fail("Expecting UnsupportedOperationException.");
} catch (UnsupportedOperationException e) {
// expected
}
try {
set.addAll(new TreeSet());
fail("Expecting UnsupportedOperationException.");
} catch (UnsupportedOperationException e) {
// expected
}
try {
set.clear();
fail("Expecting UnsupportedOperationException.");
} catch (UnsupportedOperationException e) {
// expected
}
try {
set.remove("x");
fail("Expecting UnsupportedOperationException.");
} catch (UnsupportedOperationException e) {
// expected
}
try {
set.removeAll(array);
fail("Expecting UnsupportedOperationException.");
} catch (UnsupportedOperationException e) {
// expected
}
try {
set.retainAll(array);
fail("Expecting UnsupportedOperationException.");
} catch (UnsupportedOperationException e) {
// expected
}
}
Verifies that a set is not modifiable |