commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r666231 - in /commons/sandbox/functor/trunk/src: main/java/org/apache/commons/functor/adapter/ test/java/org/apache/commons/functor/adapter/
Date Tue, 10 Jun 2008 17:43:21 GMT
Author: mbenson
Date: Tue Jun 10 10:43:20 2008
New Revision: 666231

URL: http://svn.apache.org/viewvc?rev=666231&view=rev
Log:
unchecked warnings; IllegalArgumentExceptions on null constructor args

Modified:
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FunctionProcedure.java
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FunctionUnaryFunction.java
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFunctionProcedure.java
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFunctionUnaryFunction.java

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FunctionProcedure.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FunctionProcedure.java?rev=666231&r1=666230&r2=666231&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FunctionProcedure.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FunctionProcedure.java
Tue Jun 10 10:43:20 2008
@@ -47,6 +47,9 @@
      * @param function the {@link Function Function} to wrap
      */
     public FunctionProcedure(Function<?> function) {
+        if (function == null) {
+            throw new IllegalArgumentException("Function argument was null");
+        }
         this.function = function;
     }
 

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FunctionUnaryFunction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FunctionUnaryFunction.java?rev=666231&r1=666230&r2=666231&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FunctionUnaryFunction.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/adapter/FunctionUnaryFunction.java
Tue Jun 10 10:43:20 2008
@@ -47,6 +47,9 @@
      * @param function to adapt
      */
     public FunctionUnaryFunction(Function<? extends T> function) {
+        if (function == null) {
+            throw new IllegalArgumentException("Function argument was null");
+        }
         this.function = function;
     }
 

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFunctionProcedure.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFunctionProcedure.java?rev=666231&r1=666230&r2=666231&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFunctionProcedure.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFunctionProcedure.java
Tue Jun 10 10:43:20 2008
@@ -46,7 +46,7 @@
     // ------------------------------------------------------------------------
 
     protected Object makeFunctor() {
-        return new FunctionProcedure(new Constant("K"));
+        return new FunctionProcedure(Constant.of("K"));
     }
 
     // Lifecycle
@@ -64,9 +64,9 @@
     // ------------------------------------------------------------------------
 
     public void testRun() throws Exception {
-        class EvaluateCounter implements Function {
+        class EvaluateCounter implements Function<Integer> {
             int count = 0;
-            public Object evaluate() { return new Integer(count++); }
+            public Integer evaluate() { return count++; }
         }
         EvaluateCounter counter = new EvaluateCounter();
         Procedure p = new FunctionProcedure(counter);
@@ -78,13 +78,11 @@
     }
 
     public void testEquals() throws Exception {
-        Procedure p = new FunctionProcedure(new Constant("K"));
+        Procedure p = new FunctionProcedure(Constant.of("K"));
         assertEquals(p,p);
-        assertObjectsAreEqual(p,new FunctionProcedure(new Constant("K")));
-        assertObjectsAreNotEqual(p,new NoOp());
-        assertObjectsAreNotEqual(p,new FunctionProcedure(null));
-        assertObjectsAreNotEqual(p,new FunctionProcedure(new Constant("J")));
-        assertObjectsAreEqual(new FunctionProcedure(null),new FunctionProcedure(null));
+        assertObjectsAreEqual(p,new FunctionProcedure(Constant.of("K")));
+        assertObjectsAreNotEqual(p,NoOp.INSTANCE);
+        assertObjectsAreNotEqual(p,new FunctionProcedure(Constant.of("J")));
     }
 
     public void testAdaptNull() throws Exception {
@@ -92,6 +90,6 @@
     }
 
     public void testAdapt() throws Exception {
-        assertNotNull(FunctionProcedure.adapt(new Constant("K")));
+        assertNotNull(FunctionProcedure.adapt(Constant.of("K")));
     }
 }

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFunctionUnaryFunction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFunctionUnaryFunction.java?rev=666231&r1=666230&r2=666231&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFunctionUnaryFunction.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestFunctionUnaryFunction.java
Tue Jun 10 10:43:20 2008
@@ -44,7 +44,7 @@
     // ------------------------------------------------------------------------
 
     protected Object makeFunctor() {
-        return new FunctionUnaryFunction(new Constant("xyzzy"));
+        return new FunctionUnaryFunction<Object, Object>(Constant.of("xyzzy"));
     }
 
     // Lifecycle
@@ -62,20 +62,18 @@
     // ------------------------------------------------------------------------
 
     public void testEvaluate() throws Exception {
-        UnaryFunction f = new FunctionUnaryFunction(new Constant("xyzzy"));
+        UnaryFunction<Object, Object> f = new FunctionUnaryFunction<Object, Object>(Constant.of("xyzzy"));
         assertEquals("xyzzy",f.evaluate(null));
         assertEquals("xyzzy",f.evaluate("abc"));
     }
 
     public void testEquals() throws Exception {
-        UnaryFunction f = new FunctionUnaryFunction(new Constant("xyzzy"));
+        UnaryFunction<Object, Object> f = new FunctionUnaryFunction<Object, Object>(Constant.of("xyzzy"));
         assertEquals(f,f);
-        assertObjectsAreEqual(f,new FunctionUnaryFunction(new Constant("xyzzy")));
-        assertObjectsAreNotEqual(f,new Constant("x"));
-        assertObjectsAreNotEqual(f,new FunctionUnaryFunction(new Constant(null)));
-        assertObjectsAreNotEqual(f,new Constant(null));
-        assertObjectsAreNotEqual(f,new FunctionUnaryFunction(null));
-        assertObjectsAreEqual(new FunctionUnaryFunction(null),new FunctionUnaryFunction(null));
+        assertObjectsAreEqual(f,new FunctionUnaryFunction<Object, Object>(Constant.of("xyzzy")));
+        assertObjectsAreNotEqual(f,Constant.of("x"));
+        assertObjectsAreNotEqual(f,new FunctionUnaryFunction<Object, Object>(Constant.of(null)));
+        assertObjectsAreNotEqual(f,Constant.of(null));
     }
 
     public void testAdaptNull() throws Exception {
@@ -83,6 +81,6 @@
     }
 
     public void testAdapt() throws Exception {
-        assertNotNull(FunctionUnaryFunction.adapt(new Constant("xyzzy")));
+        assertNotNull(FunctionUnaryFunction.adapt(Constant.of("xyzzy")));
     }
 }



Mime
View raw message