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/11/12 01:06:28 UTC
cvs commit: jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/composite TestAbstractLoopProcedure.java TestAll.java
rwaldhoff 2003/11/11 16:06:28
Modified: functor/src/java/org/apache/commons/functor/core/composite
AbstractLoopProcedure.java
functor/src/test/org/apache/commons/functor/core/composite
TestAll.java
Added: functor/src/test/org/apache/commons/functor/core/composite
TestAbstractLoopProcedure.java
Log:
* add tests to restore 100% coverage
* prevent NPE on hashCode() when children are null, add tests for that
Revision Changes Path
1.2 +120 -109 jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/composite/AbstractLoopProcedure.java
Index: AbstractLoopProcedure.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/java/org/apache/commons/functor/core/composite/AbstractLoopProcedure.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractLoopProcedure.java 11 Nov 2003 23:36:00 -0000 1.1
+++ AbstractLoopProcedure.java 12 Nov 2003 00:06:28 -0000 1.2
@@ -1,109 +1,120 @@
-/*
- * $Header$
- * ====================================================================
- * 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.composite;
-
-import org.apache.commons.functor.Predicate;
-import org.apache.commons.functor.Procedure;
-
-import java.io.Serializable;
-
-
-/**
- * Abstract base class for {@link WhileDoProcedure} and {@link DoWhileProcedure}
- * used to implement loop procedures.
- * <p>
- * @version $Revision$ $Date$
- * @author Herve Quiroz
- * @author Rodney Waldhoff
- */
-public abstract class AbstractLoopProcedure implements Procedure, Serializable {
- protected AbstractLoopProcedure(Predicate condition, Procedure action) {
- this.condition=condition;
- this.action=action;
- }
-
- public boolean equals(Object object) {
- if (object instanceof AbstractLoopProcedure) {
- AbstractLoopProcedure that = (AbstractLoopProcedure)object;
- return (null == getCondition() ? null == that.getCondition() : getCondition().equals(that.getCondition())) &&
- (null == getAction() ? null == that.getAction() : getAction().equals(that.getAction()));
- } else {
- return false;
- }
- }
-
- protected int hashCode(int hash) {
- hash <<= 4;
- hash ^= action.hashCode();
- hash <<= 4;
- hash ^= condition.hashCode();
- return hash;
- }
-
-
- protected Predicate getCondition() {
- return condition;
- }
-
- protected Procedure getAction() {
- return action;
- }
-
- private Predicate condition;
- private Procedure action;
-
-}
+/*
+ * $Header$
+ * ====================================================================
+ * 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.composite;
+
+import org.apache.commons.functor.Predicate;
+import org.apache.commons.functor.Procedure;
+
+import java.io.Serializable;
+
+
+/**
+ * Abstract base class for {@link WhileDoProcedure} and {@link DoWhileProcedure}
+ * used to implement loop procedures.
+ * <p>
+ * @version $Revision$ $Date$
+ * @author Herve Quiroz
+ * @author Rodney Waldhoff
+ */
+public abstract class AbstractLoopProcedure implements Procedure, Serializable {
+ protected AbstractLoopProcedure(Predicate condition, Procedure action) {
+ this.condition=condition;
+ this.action=action;
+ }
+
+ public boolean equals(Object object) {
+ if (object instanceof AbstractLoopProcedure) {
+ AbstractLoopProcedure that = (AbstractLoopProcedure)object;
+ return (null == getCondition() ? null == that.getCondition() : getCondition().equals(that.getCondition())) &&
+ (null == getAction() ? null == that.getAction() : getAction().equals(that.getAction()));
+ } else {
+ return false;
+ }
+ }
+
+ public int hashCode() {
+ return hashCode("AbstractLoopProcedure".hashCode());
+ }
+
+ public String toString() {
+ return getClass().getName() + "<" + getCondition() + "," + getAction() + ">";
+ }
+ protected int hashCode(int hash) {
+ hash <<= 4;
+ if(null != getAction()) {
+ hash ^= getAction().hashCode();
+ }
+ hash <<= 4;
+ if(null != getCondition()) {
+ hash ^= getCondition().hashCode();
+ }
+ return hash;
+ }
+
+
+ protected Predicate getCondition() {
+ return condition;
+ }
+
+ protected Procedure getAction() {
+ return action;
+ }
+
+ private Predicate condition;
+ private Procedure action;
+
+}
1.7 +3 -2 jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/composite/TestAll.java
Index: TestAll.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/composite/TestAll.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TestAll.java 11 Nov 2003 23:36:00 -0000 1.6
+++ TestAll.java 12 Nov 2003 00:06:28 -0000 1.7
@@ -108,6 +108,7 @@
suite.addTest(TestConditionalUnaryProcedure.suite());
suite.addTest(TestConditionalBinaryProcedure.suite());
+ suite.addTest(TestAbstractLoopProcedure.suite());
suite.addTest(TestWhileDoProcedure.suite());
suite.addTest(TestDoWhileProcedure.suite());
1.1 jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/composite/TestAbstractLoopProcedure.java
Index: TestAbstractLoopProcedure.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/functor/src/test/org/apache/commons/functor/core/composite/TestAbstractLoopProcedure.java,v 1.1 2003/11/12 00:06:28 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.composite;
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.Procedure;
import org.apache.commons.functor.core.ConstantPredicate;
import org.apache.commons.functor.core.NoOp;
/**
* @version $Revision: 1.1 $ $Date: 2003/11/12 00:06:28 $
* @author Rodney Waldhoff
*/
public class TestAbstractLoopProcedure extends BaseFunctorTest {
// Conventional
// ------------------------------------------------------------------------
public TestAbstractLoopProcedure(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestAbstractLoopProcedure.class);
}
// Functor Testing Framework
// ------------------------------------------------------------------------
protected Object makeFunctor() {
return new MockLoopProcedure(new ConstantPredicate(false), new NoOp());
}
// tests
// ------------------------------------------------------------------------
public void testEqualsAndHashCodeWithNullArgs() {
Procedure p = new MockLoopProcedure(null,null);
assertNotNull(p.toString());
assertFalse(p.equals(null));
assertTrue(p.equals(p));
assertEquals(p.hashCode(),p.hashCode());
}
}
class MockLoopProcedure extends AbstractLoopProcedure {
public MockLoopProcedure(Predicate condition, Procedure action) {
super(condition,action);
}
public void run() {
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org