Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/commons/beanutils/BeanPredicateTestCase.java


1   /*
2    * Copyright 2004 The Apache Software Foundation.
3    * 
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
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
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.
15   */ 
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  }