2
* Copyright 1999-2004 The Apache Software Foundation
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
16
package org.apache.commons.collections;
18
import java.util.ArrayList;
19
import java.util.Collection;
20
import java.util.List;
23
public abstract class TestPredicatedCollection extends BulkTest {
25
public TestPredicatedCollection(String name) {
30
protected abstract Collection predicatedCollection();
32
protected Predicate getPredicate() {
33
return new Predicate() {
34
public boolean evaluate(Object o) {
35
return o instanceof String;
41
public void testIllegalAdd() {
42
Collection c = predicatedCollection();
43
Integer i = new Integer(3);
46
fail("Integer should fail string predicate.");
47
} catch (IllegalArgumentException e) {
50
assertTrue("Collection shouldn't contain illegal element",
55
public void testIllegalAddAll() {
56
Collection c = predicatedCollection();
57
List elements = new ArrayList();
60
elements.add(new Integer(3));
64
fail("Integer should fail string predicate.");
65
} catch (IllegalArgumentException e) {
68
assertTrue("Collection shouldn't contain illegal element",
70
assertTrue("Collection shouldn't contain illegal element",
72
assertTrue("Collection shouldn't contain illegal element",
73
!c.contains(new Integer(3)));
74
assertTrue("Collection shouldn't contain illegal element",