Merging from -r468106:814127 of collections_jdk5_branch - namely where this code was generified; mostly in r738956.
Also see the following revisions: ------------------------------------------------------------------------ r471202 | scolebourne | 2006-11-04 06:21:44 -0800 (Sat, 04 Nov 2006) | 1 line Remove getCollection() - use covariant decorated() ------------------------------------------------------------------------ git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@815140 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
403f770bf1
commit
ed32276f0d
|
@ -26,11 +26,11 @@ import junit.framework.Test;
|
||||||
|
|
||||||
import org.apache.commons.collections.BulkTest;
|
import org.apache.commons.collections.BulkTest;
|
||||||
import org.apache.commons.collections.Predicate;
|
import org.apache.commons.collections.Predicate;
|
||||||
import org.apache.commons.collections.PredicateUtils;
|
import org.apache.commons.collections.functors.TruePredicate;
|
||||||
import org.apache.commons.collections.map.TestPredicatedSortedMap;
|
import org.apache.commons.collections.map.TestPredicatedSortedMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension of {@link AbstractTestSortedSet} for exercising the
|
* Extension of {@link AbstractTestSortedSet} for exercising the
|
||||||
* {@link PredicatedSortedSet} implementation.
|
* {@link PredicatedSortedSet} implementation.
|
||||||
*
|
*
|
||||||
* @since Commons Collections 3.0
|
* @since Commons Collections 3.0
|
||||||
|
@ -38,94 +38,89 @@ import org.apache.commons.collections.map.TestPredicatedSortedMap;
|
||||||
*
|
*
|
||||||
* @author Phil Steitz
|
* @author Phil Steitz
|
||||||
*/
|
*/
|
||||||
public class TestPredicatedSortedSet extends AbstractTestSortedSet{
|
public class TestPredicatedSortedSet<E> extends AbstractTestSortedSet<E> {
|
||||||
|
|
||||||
public TestPredicatedSortedSet(String testName) {
|
public TestPredicatedSortedSet(String testName) {
|
||||||
super(testName);
|
super(testName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
return BulkTest.makeSuite(TestPredicatedSortedSet.class);
|
return BulkTest.makeSuite(TestPredicatedSortedSet.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
String[] testCaseName = { TestPredicatedSortedMap.class.getName()};
|
String[] testCaseName = { TestPredicatedSortedMap.class.getName()};
|
||||||
junit.textui.TestRunner.main(testCaseName);
|
junit.textui.TestRunner.main(testCaseName);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
|
|
||||||
protected Predicate truePredicate = PredicateUtils.truePredicate();
|
protected Predicate<E> truePredicate = TruePredicate.<E>truePredicate();
|
||||||
|
|
||||||
public Set makeEmptySet() {
|
public SortedSet<E> makeObject() {
|
||||||
return PredicatedSortedSet.decorate(new TreeSet(), truePredicate);
|
return PredicatedSortedSet.decorate(new TreeSet<E>(), truePredicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set makeFullSet() {
|
public SortedSet<E> makeFullCollection() {
|
||||||
TreeSet set = new TreeSet();
|
TreeSet<E> set = new TreeSet<E>();
|
||||||
set.addAll(Arrays.asList(getFullElements()));
|
set.addAll(Arrays.asList(getFullElements()));
|
||||||
return PredicatedSortedSet.decorate(set, truePredicate);
|
return PredicatedSortedSet.decorate(set, truePredicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
//--------------------------------------------------------------------
|
protected Predicate<E> testPredicate =
|
||||||
protected Predicate testPredicate =
|
new Predicate<E>() {
|
||||||
new Predicate() {
|
public boolean evaluate(E o) {
|
||||||
public boolean evaluate(Object o) {
|
|
||||||
return (o instanceof String) && (((String) o).startsWith("A"));
|
return (o instanceof String) && (((String) o).startsWith("A"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
protected PredicatedSortedSet<E> makeTestSet() {
|
||||||
protected SortedSet makeTestSet() {
|
return (PredicatedSortedSet<E>) PredicatedSortedSet.decorate(new TreeSet<E>(), testPredicate);
|
||||||
return PredicatedSortedSet.decorate(new TreeSet(), testPredicate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetSet() {
|
public void testGetSet() {
|
||||||
SortedSet set = makeTestSet();
|
PredicatedSortedSet<E> set = makeTestSet();
|
||||||
assertTrue("returned set should not be null",
|
assertTrue("returned set should not be null", set.decorated() != null);
|
||||||
((PredicatedSortedSet) set).getSet() != null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void testIllegalAdd() {
|
public void testIllegalAdd() {
|
||||||
SortedSet set = makeTestSet();
|
SortedSet<E> set = makeTestSet();
|
||||||
String testString = "B";
|
String testString = "B";
|
||||||
try {
|
try {
|
||||||
set.add(testString);
|
set.add((E) testString);
|
||||||
fail("Should fail string predicate.");
|
fail("Should fail string predicate.");
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
assertTrue("Collection shouldn't contain illegal element",
|
assertTrue("Collection shouldn't contain illegal element",
|
||||||
!set.contains(testString));
|
!set.contains(testString));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void testIllegalAddAll() {
|
public void testIllegalAddAll() {
|
||||||
SortedSet set = makeTestSet();
|
SortedSet<E> set = makeTestSet();
|
||||||
Set elements = new TreeSet();
|
Set<E> elements = new TreeSet<E>();
|
||||||
elements.add("Aone");
|
elements.add((E) "Aone");
|
||||||
elements.add("Atwo");
|
elements.add((E) "Atwo");
|
||||||
elements.add("Bthree");
|
elements.add((E) "Bthree");
|
||||||
elements.add("Afour");
|
elements.add((E) "Afour");
|
||||||
try {
|
try {
|
||||||
set.addAll(elements);
|
set.addAll(elements);
|
||||||
fail("Should fail string predicate.");
|
fail("Should fail string predicate.");
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
assertTrue("Set shouldn't contain illegal element",
|
assertTrue("Set shouldn't contain illegal element", !set.contains("Aone"));
|
||||||
!set.contains("Aone"));
|
assertTrue("Set shouldn't contain illegal element", !set.contains("Atwo"));
|
||||||
assertTrue("Set shouldn't contain illegal element",
|
assertTrue("Set shouldn't contain illegal element", !set.contains("Bthree"));
|
||||||
!set.contains("Atwo"));
|
assertTrue("Set shouldn't contain illegal element", !set.contains("Afour"));
|
||||||
assertTrue("Set shouldn't contain illegal element",
|
|
||||||
!set.contains("Bthree"));
|
|
||||||
assertTrue("Set shouldn't contain illegal element",
|
|
||||||
!set.contains("Afour"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testComparator() {
|
public void testComparator() {
|
||||||
SortedSet set = makeTestSet();
|
SortedSet<E> set = makeTestSet();
|
||||||
Comparator c = set.comparator();
|
Comparator<? super E> c = set.comparator();
|
||||||
assertTrue("natural order, so comparator should be null", c == null);
|
assertTrue("natural order, so comparator should be null", c == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue