You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rw...@apache.org on 2003/01/30 00:03:19 UTC

cvs commit: jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core TestIdentityPredicate.java TestLeftIdentityPredicate.java TestRightIdentityPredicate.java TestAll.java

rwaldhoff    2003/01/29 15:03:18

  Modified:    functor/src/test/org/apache/commons/functor/core
                        TestAll.java
  Added:       functor/src/java/org/apache/commons/functor/core
                        IdentityPredicate.java LeftIdentityPredicate.java
                        RightIdentityPredicate.java
               functor/src/test/org/apache/commons/functor/core
                        TestIdentityPredicate.java
                        TestLeftIdentityPredicate.java
                        TestRightIdentityPredicate.java
  Log:
  add identity predicates and tests
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/IdentityPredicate.java
  
  Index: IdentityPredicate.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/IdentityPredicate.java,v 1.1 2003/01/29 23:03:17 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived 
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.functor.core;
  
  import java.io.Serializable;
  
  import org.apache.commons.functor.UnaryPredicate;
  
  /**
   * {@link #test Tests} to the <code>boolean</code>
   * value of the <code>Boolean</code>-valued parameter.
   * Throws an exception if the parameter isn't a 
   * non-<code>null</code> <code>Boolean</code>.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/01/29 23:03:17 $
   * @author Rodney Waldhoff
   */
  public final class IdentityPredicate implements UnaryPredicate, Serializable {
      
      // constructor
      // ------------------------------------------------------------------------
      public IdentityPredicate() {
      }
   
      // functor interface
      // ------------------------------------------------------------------------
  
      public boolean test(Object obj) {
          return test((Boolean)obj);
      }
  
      public boolean test(Boolean bool) {
          return bool.booleanValue();
      }
  
      public boolean equals(Object that) {
          return (that instanceof IdentityPredicate);
      }
      
      public int hashCode() {
          return "IdentityPredicate".hashCode();
      }
      
      public String toString() {
          return "IdentityPredicate";
      }
      
      // static methods
      // ------------------------------------------------------------------------
      public static IdentityPredicate getIdentityPredicate() {
          return INSTANCE;
      }
      
      // static attributes
      // ------------------------------------------------------------------------
      private static final IdentityPredicate INSTANCE = new IdentityPredicate();
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/LeftIdentityPredicate.java
  
  Index: LeftIdentityPredicate.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/LeftIdentityPredicate.java,v 1.1 2003/01/29 23:03:17 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived 
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.functor.core;
  
  import java.io.Serializable;
  
  import org.apache.commons.functor.BinaryPredicate;
  
  /**
   * {@link #test Tests} to the <code>boolean</code>
   * value of the <code>Boolean</code>-valued left
   * hand parameter.
   * Throws an exception if the parameter isn't a 
   * non-<code>null</code> <code>Boolean</code>.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/01/29 23:03:17 $
   * @author Rodney Waldhoff
   */
  public final class LeftIdentityPredicate implements BinaryPredicate, Serializable {
      
      // constructor
      // ------------------------------------------------------------------------
      public LeftIdentityPredicate() {
      }
   
      // functor interface
      // ------------------------------------------------------------------------
  
      public boolean test(Object left, Object right) {
          return test((Boolean)left);
      }
  
      private boolean test(Boolean bool) {
          return bool.booleanValue();
      }
  
      public boolean equals(Object that) {
          return (that instanceof LeftIdentityPredicate);
      }
      
      public int hashCode() {
          return "LeftIdentityPredicate".hashCode();
      }
      
      public String toString() {
          return "LeftIdentityPredicate";
      }
      
      // static methods
      // ------------------------------------------------------------------------
      public static LeftIdentityPredicate getLeftIdentityPredicate() {
          return INSTANCE;
      }
      
      // static attributes
      // ------------------------------------------------------------------------
      private static final LeftIdentityPredicate INSTANCE = new LeftIdentityPredicate();
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/RightIdentityPredicate.java
  
  Index: RightIdentityPredicate.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/RightIdentityPredicate.java,v 1.1 2003/01/29 23:03:18 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived 
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.functor.core;
  
  import java.io.Serializable;
  
  import org.apache.commons.functor.BinaryPredicate;
  
  /**
   * {@link #test Tests} to the <code>boolean</code>
   * value of the <code>Boolean</code>-valued right
   * hand parameter.
   * Throws an exception if the parameter isn't a 
   * non-<code>null</code> <code>Boolean</code>.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/01/29 23:03:18 $
   * @author Rodney Waldhoff
   */
  public final class RightIdentityPredicate implements BinaryPredicate, Serializable {
      
      // constructor
      // ------------------------------------------------------------------------
      public RightIdentityPredicate() {
      }
   
      // functor interface
      // ------------------------------------------------------------------------
  
      public boolean test(Object left, Object right) {
          return test((Boolean)right);
      }
  
      private boolean test(Boolean bool) {
          return bool.booleanValue();
      }
  
      public boolean equals(Object that) {
          return (that instanceof RightIdentityPredicate);
      }
      
      public int hashCode() {
          return "RightIdentityPredicate".hashCode();
      }
      
      public String toString() {
          return "RightIdentityPredicate";
      }
      
      // static methods
      // ------------------------------------------------------------------------
      public static RightIdentityPredicate getRightIdentityPredicate() {
          return INSTANCE;
      }
      
      // static attributes
      // ------------------------------------------------------------------------
      private static final RightIdentityPredicate INSTANCE = new RightIdentityPredicate();
  }
  
  
  
  1.2       +5 -2      jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/TestAll.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestAll.java	27 Jan 2003 19:33:42 -0000	1.1
  +++ TestAll.java	29 Jan 2003 23:03:18 -0000	1.2
  @@ -83,6 +83,9 @@
           suite.addTest(TestIsNotNullPredicate.suite());
           suite.addTest(TestEqualPredicate.suite());
           suite.addTest(TestNotEqualPredicate.suite());
  +        suite.addTest(TestIdentityPredicate.suite());
  +        suite.addTest(TestLeftIdentityPredicate.suite());
  +        suite.addTest(TestRightIdentityPredicate.suite());
   
           suite.addTest(org.apache.commons.functor.core.composite.TestAll.suite());
           
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/TestIdentityPredicate.java
  
  Index: TestIdentityPredicate.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/TestIdentityPredicate.java,v 1.1 2003/01/29 23:03:18 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived 
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.functor.core;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.functor.BaseFunctorTest;
  import org.apache.commons.functor.Predicate;
  import org.apache.commons.functor.UnaryPredicate;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/01/29 23:03:18 $
   * @author Rodney Waldhoff
   */
  public class TestIdentityPredicate extends BaseFunctorTest {
  
      // Conventional
      // ------------------------------------------------------------------------
  
      public TestIdentityPredicate(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestIdentityPredicate.class);
      }
  
      // Functor Testing Framework
      // ------------------------------------------------------------------------
  
      protected Object makeFunctor() {
          return new IdentityPredicate();
      }
      
      // Lifecycle
      // ------------------------------------------------------------------------
  
      public void setUp() throws Exception {
          super.setUp();
      }
  
      public void tearDown() throws Exception {
          super.tearDown();
      }
  
      // Tests
      // ------------------------------------------------------------------------
      
      public void testTest() throws Exception {
          UnaryPredicate p = new IdentityPredicate();
          assertTrue(p.test(Boolean.TRUE));
          assertTrue(!p.test(Boolean.FALSE));
          try {
              p.test("true");
              fail("Expected ClassCastException");
          } catch(ClassCastException e) {
              // expected
          }
          try {
              p.test(null);
              fail("Expected NullPointerException");
          } catch(NullPointerException e) {
              // expected
          }
      }
      
      public void testEquals() throws Exception {
          UnaryPredicate f = new IdentityPredicate();
          assertEquals(f,f);
          assertObjectsAreEqual(f,new IdentityPredicate());
          assertObjectsAreEqual(f,IdentityPredicate.getIdentityPredicate());
          assertObjectsAreNotEqual(f,new ConstantPredicate(true));
      }
      
      public void testConstant() throws Exception {
          assertEquals(IdentityPredicate.getIdentityPredicate(),IdentityPredicate.getIdentityPredicate());
          assertSame(IdentityPredicate.getIdentityPredicate(),IdentityPredicate.getIdentityPredicate());
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/TestLeftIdentityPredicate.java
  
  Index: TestLeftIdentityPredicate.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/TestLeftIdentityPredicate.java,v 1.1 2003/01/29 23:03:18 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived 
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.functor.core;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.functor.BaseFunctorTest;
  import org.apache.commons.functor.BinaryPredicate;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/01/29 23:03:18 $
   * @author Rodney Waldhoff
   */
  public class TestLeftIdentityPredicate extends BaseFunctorTest {
  
      // Conventional
      // ------------------------------------------------------------------------
  
      public TestLeftIdentityPredicate(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestLeftIdentityPredicate.class);
      }
  
      // Functor Testing Framework
      // ------------------------------------------------------------------------
  
      protected Object makeFunctor() {
          return new LeftIdentityPredicate();
      }
      
      // Lifecycle
      // ------------------------------------------------------------------------
  
      public void setUp() throws Exception {
          super.setUp();
      }
  
      public void tearDown() throws Exception {
          super.tearDown();
      }
  
      // Tests
      // ------------------------------------------------------------------------
      
      public void testTest() throws Exception {
          BinaryPredicate p = new LeftIdentityPredicate();
          assertTrue(p.test(Boolean.TRUE,null));
          assertTrue(!p.test(Boolean.FALSE,null));
          try {
              p.test("true",null);
              fail("Expected ClassCastException");
          } catch(ClassCastException e) {
              // expected
          }
          try {
              p.test(null,null);
              fail("Expected NullPointerException");
          } catch(NullPointerException e) {
              // expected
          }
      }
      
      public void testEquals() throws Exception {
          LeftIdentityPredicate p = new LeftIdentityPredicate();
          assertEquals(p,p);
          assertObjectsAreEqual(p,new LeftIdentityPredicate());
          assertObjectsAreEqual(p,LeftIdentityPredicate.getLeftIdentityPredicate());
          assertObjectsAreNotEqual(p,new IdentityPredicate());
          assertObjectsAreNotEqual(p,new ConstantPredicate(true));
      }
      
      public void testConstant() throws Exception {
          assertEquals(LeftIdentityPredicate.getLeftIdentityPredicate(),LeftIdentityPredicate.getLeftIdentityPredicate());
          assertSame(LeftIdentityPredicate.getLeftIdentityPredicate(),LeftIdentityPredicate.getLeftIdentityPredicate());
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/TestRightIdentityPredicate.java
  
  Index: TestRightIdentityPredicate.java
  ===================================================================
  /* 
   * $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/TestRightIdentityPredicate.java,v 1.1 2003/01/29 23:03:18 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived 
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.functor.core;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.functor.BaseFunctorTest;
  import org.apache.commons.functor.BinaryPredicate;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/01/29 23:03:18 $
   * @author Rodney Waldhoff
   */
  public class TestRightIdentityPredicate extends BaseFunctorTest {
  
      // Conventional
      // ------------------------------------------------------------------------
  
      public TestRightIdentityPredicate(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestRightIdentityPredicate.class);
      }
  
      // Functor Testing Framework
      // ------------------------------------------------------------------------
  
      protected Object makeFunctor() {
          return new RightIdentityPredicate();
      }
      
      // Lifecycle
      // ------------------------------------------------------------------------
  
      public void setUp() throws Exception {
          super.setUp();
      }
  
      public void tearDown() throws Exception {
          super.tearDown();
      }
  
      // Tests
      // ------------------------------------------------------------------------
      
      public void testTest() throws Exception {
          BinaryPredicate p = new RightIdentityPredicate();
          assertTrue(p.test(null,Boolean.TRUE));
          assertTrue(!p.test(null,Boolean.FALSE));
          try {
              p.test(null,"true");
              fail("Expected ClassCastException");
          } catch(ClassCastException e) {
              // expected
          }
          try {
              p.test(null,null);
              fail("Expected NullPointerException");
          } catch(NullPointerException e) {
              // expected
          }
      }
      
      public void testEquals() throws Exception {
          RightIdentityPredicate p = new RightIdentityPredicate();
          assertEquals(p,p);
          assertObjectsAreEqual(p,new RightIdentityPredicate());
          assertObjectsAreEqual(p,RightIdentityPredicate.getRightIdentityPredicate());
          assertObjectsAreNotEqual(p,new IdentityPredicate());
          assertObjectsAreNotEqual(p,new ConstantPredicate(true));
      }
      
      public void testConstant() throws Exception {
          assertEquals(RightIdentityPredicate.getRightIdentityPredicate(),RightIdentityPredicate.getRightIdentityPredicate());
          assertSame(RightIdentityPredicate.getRightIdentityPredicate(),RightIdentityPredicate.getRightIdentityPredicate());
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org