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