commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r665771 - in /commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core: TestIsInstance.java TestIsInstanceOf.java
Date Mon, 09 Jun 2008 17:00:12 GMT
Author: mbenson
Date: Mon Jun  9 10:00:12 2008
New Revision: 665771

URL: http://svn.apache.org/viewvc?rev=665771&view=rev
Log:
generify; rename IsInstanceOf to IsInstance and change to a BinaryPredicate instead of a UnaryPredicate

Added:
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsInstance.java
      - copied, changed from r661495, commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsInstanceOf.java
Removed:
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsInstanceOf.java

Copied: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsInstance.java
(from r661495, commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsInstanceOf.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsInstance.java?p2=commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsInstance.java&p1=commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsInstanceOf.java&r1=661495&r2=665771&rev=665771&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsInstanceOf.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/TestIsInstance.java
Mon Jun  9 10:00:12 2008
@@ -20,30 +20,31 @@
 import junit.framework.TestSuite;
 
 import org.apache.commons.functor.BaseFunctorTest;
+import org.apache.commons.functor.BinaryPredicate;
 import org.apache.commons.functor.UnaryPredicate;
 
 /**
  * @version $Revision$ $Date$
  * @author Rodney Waldhoff
  */
-public class TestIsInstanceOf extends BaseFunctorTest {
+public class TestIsInstance extends BaseFunctorTest {
 
     // Conventional
     // ------------------------------------------------------------------------
 
-    public TestIsInstanceOf(String testName) {
+    public TestIsInstance(String testName) {
         super(testName);
     }
 
     public static Test suite() {
-        return new TestSuite(TestIsInstanceOf.class);
+        return new TestSuite(TestIsInstance.class);
     }
 
     // Functor Testing Framework
     // ------------------------------------------------------------------------
 
     protected Object makeFunctor() {
-        return new IsInstanceOf(String.class);
+        return IsInstance.of(String.class);
     }
 
     // Lifecycle
@@ -61,18 +62,25 @@
     // ------------------------------------------------------------------------
 
     public void testTest() throws Exception {
-        UnaryPredicate p = new IsInstanceOf(Number.class);
-        assertTrue(!p.test(null));
-        assertTrue(!p.test("foo"));
-        assertTrue(p.test(new Integer(3)));
-        assertTrue(p.test(new Integer(3)));
-        assertTrue(p.test((new Long(3L))));
+        BinaryPredicate p = IsInstance.INSTANCE;
+        assertFalse(p.test(null, Number.class));
+        assertFalse(p.test("foo", Number.class));
+        assertTrue(p.test(3, Number.class));
+        assertTrue(p.test(3L, Number.class));
+    }
+
+    public void testBoundTest() throws Exception {
+        UnaryPredicate p = IsInstance.of(Number.class);
+        assertFalse(p.test(null));
+        assertFalse(p.test("foo"));
+        assertTrue(p.test(3));
+        assertTrue(p.test(3L));
     }
 
     public void testInstanceOfNull() throws Exception {
-        UnaryPredicate p = new IsInstanceOf(null);
+        BinaryPredicate p = new IsInstance();
         try {
-            p.test("foo");
+            p.test("foo", null);
             fail("Expected NullPointerException");
         } catch(NullPointerException e) {
             // expected
@@ -80,11 +88,18 @@
     }
 
     public void testEquals() throws Exception {
-        UnaryPredicate p = new IsInstanceOf(Object.class);
+        BinaryPredicate p = IsInstance.INSTANCE;
+        assertEquals(p, p);
+        assertObjectsAreEqual(p, IsInstance.instance());
+        assertObjectsAreNotEqual(p,Constant.truePredicate());
+    }
+
+    public void testBoundEquals() throws Exception {
+        UnaryPredicate p = IsInstance.of(Object.class);
         assertEquals(p,p);
-        assertObjectsAreEqual(p,new IsInstanceOf(Object.class));
+        assertObjectsAreEqual(p,IsInstance.of(Object.class));
         assertObjectsAreNotEqual(p,Constant.truePredicate());
-        assertObjectsAreNotEqual(p,new IsInstanceOf(null));
-        assertObjectsAreNotEqual(p,new IsInstanceOf(String.class));
+        assertObjectsAreNotEqual(p,IsInstance.of(null));
+        assertObjectsAreNotEqual(p,IsInstance.of(String.class));
     }
 }



Mime
View raw message