1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.beanutils;
19
20 import junit.framework.TestCase;
21
22 import org.apache.commons.collections.functors.EqualPredicate;
23 import org.apache.commons.collections.functors.InstanceofPredicate;
24 import org.apache.commons.collections.functors.NotPredicate;
25 import org.apache.commons.collections.functors.NullPredicate;
26
27
28
29
30 public class BeanPredicateTestCase extends TestCase {
31
32 public BeanPredicateTestCase(final String name) {
33 super(name);
34 }
35
36 public void testEqual() {
37 final BeanPredicate predicate =
38 new BeanPredicate("stringProperty",new EqualPredicate("foo"));
39 assertTrue(predicate.evaluate(new TestBean("foo")));
40 assertTrue(!predicate.evaluate(new TestBean("bar")));
41 }
42
43 public void testNotEqual() {
44 final BeanPredicate predicate =
45 new BeanPredicate("stringProperty",new NotPredicate( new EqualPredicate("foo")));
46 assertTrue(!predicate.evaluate(new TestBean("foo")));
47 assertTrue(predicate.evaluate(new TestBean("bar")));
48 }
49
50 public void testInstanceOf() {
51 final BeanPredicate predicate =
52 new BeanPredicate("stringProperty",new InstanceofPredicate( String.class ));
53 assertTrue(predicate.evaluate(new TestBean("foo")));
54 assertTrue(predicate.evaluate(new TestBean("bar")));
55 }
56
57 public void testNull() {
58 final BeanPredicate predicate =
59 new BeanPredicate("stringProperty", NullPredicate.INSTANCE);
60 final String nullString = null;
61 assertTrue(predicate.evaluate(new TestBean(nullString)));
62 assertTrue(!predicate.evaluate(new TestBean("bar")));
63 }
64
65 }