commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ki...@apache.org
Subject svn commit: r1364767 - in /commons/proper/functor/trunk/src: main/java/org/apache/commons/functor/core/ test/java/org/apache/commons/functor/core/
Date Mon, 23 Jul 2012 19:36:08 GMT
Author: kinow
Date: Mon Jul 23 19:36:08 2012
New Revision: 1364767

URL: http://svn.apache.org/viewvc?rev=1364767&view=rev
Log:
[FUNCTOR-12] Tests for functor core. RightIdentity wasn't using the prodedure() method, but
duplicating the code for this method in two places. This commit fixes it too. LeftIdentity
had the right code, so no change was necessary.

Tests using try/catch + fail() were updated to use @Test(expected=SomeException.class).

Modified:
    commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/RightIdentity.java
    commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestConstant.java
    commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsEqual.java
    commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsNotEqual.java
    commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java
    commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsSame.java
    commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java
    commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLimit.java
    commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestNoOp.java
    commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestOffset.java
    commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java

Modified: commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/RightIdentity.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/RightIdentity.java?rev=1364767&r1=1364766&r2=1364767&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/RightIdentity.java
(original)
+++ commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/RightIdentity.java
Mon Jul 23 19:36:08 2012
@@ -39,8 +39,7 @@ public final class RightIdentity {
     /**
      * Right-identity predicate.
      */
-    public static final BinaryPredicate<Object, Boolean> PREDICATE =
-        BinaryFunctionBinaryPredicate.adapt(IgnoreLeftFunction.adapt(new Identity<Boolean>()));
+    public static final BinaryPredicate<Object, Boolean> PREDICATE = RightIdentity.<Object>predicate();
 
     // constructor
     // ------------------------------------------------------------------------

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestConstant.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestConstant.java?rev=1364767&r1=1364766&r2=1364767&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestConstant.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestConstant.java
Mon Jul 23 19:36:08 2012
@@ -94,6 +94,8 @@ public class TestConstant extends BaseFu
         assertObjectsAreEqual(f,new Constant<Object>("xyzzy"));
         assertObjectsAreNotEqual(f,new Constant<Object>("abcde"));
         assertObjectsAreNotEqual(f,new Constant<Object>(null));
+        assertObjectsAreEqual(new Constant<Object>(null),new Constant<Object>(null));
+        assertTrue(!f.equals(null));
     }
 
     @Test

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsEqual.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsEqual.java?rev=1364767&r1=1364766&r2=1364767&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsEqual.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsEqual.java
Mon Jul 23 19:36:08 2012
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTru
 
 import org.apache.commons.functor.BaseFunctorTest;
 import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.functor.UnaryPredicate;
 import org.junit.Test;
 
 /**
@@ -75,4 +76,11 @@ public class TestIsEqual extends BaseFun
         assertNotSame(IsEqual.instance(), IsEqual.instance());
         assertSame(IsEqual.INSTANCE, IsEqual.INSTANCE);
     }
+
+    @Test
+    public void testToUnaryPredicate() {
+       UnaryPredicate<Integer> isEqual = IsEqual.to(new Integer(1));
+       assertTrue(isEqual.test(new Integer(1)));
+       assertFalse(isEqual.test(new Integer(2)));
+    }
 }

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsNotEqual.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsNotEqual.java?rev=1364767&r1=1364766&r2=1364767&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsNotEqual.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsNotEqual.java
Mon Jul 23 19:36:08 2012
@@ -17,10 +17,12 @@
 package org.apache.commons.functor.core;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import org.apache.commons.functor.BaseFunctorTest;
 import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.functor.UnaryPredicate;
 import org.junit.Test;
 
 /**
@@ -69,4 +71,11 @@ public class TestIsNotEqual extends Base
     public void testConstant() throws Exception {
         assertEquals(IsNotEqual.instance(),IsNotEqual.instance());
     }
+
+    @Test
+    public void testToUnaryPredicate() {
+        UnaryPredicate<Integer> isNotEqual = IsNotEqual.to(new Integer(1));
+        assertTrue(isNotEqual.test(new Integer(2)));
+        assertFalse(isNotEqual.test(new Integer(1)));
+    }
 }

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java?rev=1364767&r1=1364766&r2=1364767&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java
Mon Jul 23 19:36:08 2012
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTru
 
 import org.apache.commons.functor.BaseFunctorTest;
 import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.functor.UnaryPredicate;
 import org.junit.Test;
 
 /**
@@ -75,4 +76,12 @@ public class TestIsNotSame extends BaseF
         assertNotSame(IsNotSame.instance(), IsNotSame.instance());
         assertSame(IsNotSame.INSTANCE, IsNotSame.INSTANCE);
     }
+
+    @Test
+    public void testAsUnaryPredicate() {
+        Integer one = new Integer(1);
+        UnaryPredicate<Integer> isNotSame = IsNotSame.as(one);
+        assertTrue(isNotSame.test(new Integer(2)));
+        assertFalse(isNotSame.test(one));
+    }
 }

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsSame.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsSame.java?rev=1364767&r1=1364766&r2=1364767&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsSame.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsSame.java
Mon Jul 23 19:36:08 2012
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTru
 
 import org.apache.commons.functor.BaseFunctorTest;
 import org.apache.commons.functor.BinaryPredicate;
+import org.apache.commons.functor.UnaryPredicate;
 import org.junit.Test;
 
 /**
@@ -75,4 +76,12 @@ public class TestIsSame extends BaseFunc
         assertNotSame(IsSame.instance(), IsSame.instance());
         assertSame(IsSame.INSTANCE, IsSame.INSTANCE);
     }
+
+    @Test
+    public void testAsUnaryPredicate() {
+        Integer one = new Integer(1);
+        UnaryPredicate<Integer> isSame = IsSame.as(one);
+        assertTrue(isSame.test(one));
+        assertFalse(isSame.test(new Integer(2)));
+    }
 }

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java?rev=1364767&r1=1364766&r2=1364767&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java
Mon Jul 23 19:36:08 2012
@@ -20,7 +20,6 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import org.apache.commons.functor.BaseFunctorTest;
 import org.apache.commons.functor.BinaryFunction;
@@ -56,16 +55,12 @@ public class TestLeftIdentity extends Ba
         assertSame(obj,f.evaluate(obj,obj));
     }
 
-    @Test
+    @Test(expected=NullPointerException.class)
     public void testTest() throws Exception {
         BinaryPredicate<Boolean, Object> p = LeftIdentity.PREDICATE;
         assertTrue(p.test(Boolean.TRUE,null));
         assertTrue(!p.test(Boolean.FALSE,null));
-        try {
-            p.test(null, null);
-            fail("Expected NullPointerException");
-        } catch (NullPointerException npe) {
-        }
+        p.test(null, null);
     }
 
     @Test

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLimit.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLimit.java?rev=1364767&r1=1364766&r2=1364767&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLimit.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLimit.java
Mon Jul 23 19:36:08 2012
@@ -86,4 +86,12 @@ public class TestLimit extends BaseFunct
         assertTrue(p.test(null,null));
         assertTrue(! p.test(null,null));
     }
+
+    @Test
+    public void testEquals() {
+        Limit limit = new Limit(1);
+        assertObjectsAreEqual(new Limit(1), limit);
+        assertObjectsAreNotEqual(new Limit(2), limit);
+        assertTrue(!limit.equals(null));
+    }
 }

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestNoOp.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestNoOp.java?rev=1364767&r1=1364766&r2=1364767&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestNoOp.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestNoOp.java
Mon Jul 23 19:36:08 2012
@@ -68,5 +68,9 @@ public class TestNoOp extends BaseFuncto
     public void testConstant() throws Exception {
         assertEquals(NoOp.instance(),NoOp.instance());
         assertSame(NoOp.instance(),NoOp.instance());
+        assertEquals(NoOp.unaryInstance(),NoOp.unaryInstance());
+        assertSame(NoOp.unaryInstance(),NoOp.unaryInstance());
+        assertEquals(NoOp.binaryInstance(),NoOp.binaryInstance());
+        assertSame(NoOp.binaryInstance(),NoOp.binaryInstance());
     }
 }

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestOffset.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestOffset.java?rev=1364767&r1=1364766&r2=1364767&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestOffset.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestOffset.java
Mon Jul 23 19:36:08 2012
@@ -88,4 +88,12 @@ public class TestOffset extends BaseFunc
         assertTrue(!p.test(null,null));
         assertTrue(p.test(null,null));
     }
+
+    @Test
+    public void testEquals() {
+        Offset offset = new Offset(1);
+        assertObjectsAreEqual(new Offset(1), offset);
+        assertObjectsAreNotEqual(new Offset(2), offset);
+        assertTrue(!offset.equals(null));
+    }
 }

Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java?rev=1364767&r1=1364766&r2=1364767&view=diff
==============================================================================
--- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java
(original)
+++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java
Mon Jul 23 19:36:08 2012
@@ -20,7 +20,6 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import org.apache.commons.functor.BaseFunctorTest;
 import org.apache.commons.functor.BinaryFunction;
@@ -56,17 +55,12 @@ public class TestRightIdentity extends B
         assertSame(obj,f.evaluate(obj,obj));
     }
 
-    @Test
+    @Test(expected=NullPointerException.class)
     public void testTest() throws Exception {
         BinaryPredicate<Object, Boolean> p = RightIdentity.PREDICATE;
         assertTrue(p.test(null,Boolean.TRUE));
         assertTrue(!p.test(null,Boolean.FALSE));
-        try {
-            p.test(null,null);
-            fail("Expected NullPointerException");
-        } catch(NullPointerException e) {
-            // expected
-        }
+        p.test(null,null);
     }
 
     @Test



Mime
View raw message