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:
Henri Yandell 2009-09-15 06:06:13 +00:00
parent 403f770bf1
commit ed32276f0d
1 changed files with 48 additions and 53 deletions

View File

@ -26,7 +26,7 @@ import junit.framework.Test;
import org.apache.commons.collections.BulkTest;
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;
/**
@ -38,7 +38,7 @@ import org.apache.commons.collections.map.TestPredicatedSortedMap;
*
* @author Phil Steitz
*/
public class TestPredicatedSortedSet extends AbstractTestSortedSet{
public class TestPredicatedSortedSet<E> extends AbstractTestSortedSet<E> {
public TestPredicatedSortedSet(String testName) {
super(testName);
@ -55,43 +55,41 @@ public class TestPredicatedSortedSet extends AbstractTestSortedSet{
//-------------------------------------------------------------------
protected Predicate truePredicate = PredicateUtils.truePredicate();
protected Predicate<E> truePredicate = TruePredicate.<E>truePredicate();
public Set makeEmptySet() {
return PredicatedSortedSet.decorate(new TreeSet(), truePredicate);
public SortedSet<E> makeObject() {
return PredicatedSortedSet.decorate(new TreeSet<E>(), truePredicate);
}
public Set makeFullSet() {
TreeSet set = new TreeSet();
public SortedSet<E> makeFullCollection() {
TreeSet<E> set = new TreeSet<E>();
set.addAll(Arrays.asList(getFullElements()));
return PredicatedSortedSet.decorate(set, truePredicate);
}
//--------------------------------------------------------------------
protected Predicate testPredicate =
new Predicate() {
public boolean evaluate(Object o) {
protected Predicate<E> testPredicate =
new Predicate<E>() {
public boolean evaluate(E o) {
return (o instanceof String) && (((String) o).startsWith("A"));
}
};
protected SortedSet makeTestSet() {
return PredicatedSortedSet.decorate(new TreeSet(), testPredicate);
protected PredicatedSortedSet<E> makeTestSet() {
return (PredicatedSortedSet<E>) PredicatedSortedSet.decorate(new TreeSet<E>(), testPredicate);
}
public void testGetSet() {
SortedSet set = makeTestSet();
assertTrue("returned set should not be null",
((PredicatedSortedSet) set).getSet() != null);
PredicatedSortedSet<E> set = makeTestSet();
assertTrue("returned set should not be null", set.decorated() != null);
}
@SuppressWarnings("unchecked")
public void testIllegalAdd() {
SortedSet set = makeTestSet();
SortedSet<E> set = makeTestSet();
String testString = "B";
try {
set.add(testString);
set.add((E) testString);
fail("Should fail string predicate.");
} catch (IllegalArgumentException e) {
// expected
@ -100,32 +98,29 @@ public class TestPredicatedSortedSet extends AbstractTestSortedSet{
!set.contains(testString));
}
@SuppressWarnings("unchecked")
public void testIllegalAddAll() {
SortedSet set = makeTestSet();
Set elements = new TreeSet();
elements.add("Aone");
elements.add("Atwo");
elements.add("Bthree");
elements.add("Afour");
SortedSet<E> set = makeTestSet();
Set<E> elements = new TreeSet<E>();
elements.add((E) "Aone");
elements.add((E) "Atwo");
elements.add((E) "Bthree");
elements.add((E) "Afour");
try {
set.addAll(elements);
fail("Should fail string predicate.");
} catch (IllegalArgumentException e) {
// expected
}
assertTrue("Set shouldn't contain illegal element",
!set.contains("Aone"));
assertTrue("Set shouldn't contain illegal element",
!set.contains("Atwo"));
assertTrue("Set shouldn't contain illegal element",
!set.contains("Bthree"));
assertTrue("Set shouldn't contain illegal element",
!set.contains("Afour"));
assertTrue("Set shouldn't contain illegal element", !set.contains("Aone"));
assertTrue("Set shouldn't contain illegal element", !set.contains("Atwo"));
assertTrue("Set shouldn't contain illegal element", !set.contains("Bthree"));
assertTrue("Set shouldn't contain illegal element", !set.contains("Afour"));
}
public void testComparator() {
SortedSet set = makeTestSet();
Comparator c = set.comparator();
SortedSet<E> set = makeTestSet();
Comparator<? super E> c = set.comparator();
assertTrue("natural order, so comparator should be null", c == null);
}