svn commit: r904986 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/test/GenericTestCaseBase.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r904986 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/test/GenericTestCaseBase.java

doogie-3
Author: doogie
Date: Sun Jan 31 06:27:41 2010
New Revision: 904986

URL: http://svn.apache.org/viewvc?rev=904986&view=rev
Log:
Add a helper method to test futures.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/test/GenericTestCaseBase.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/test/GenericTestCaseBase.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/test/GenericTestCaseBase.java?rev=904986&r1=904985&r2=904986&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/test/GenericTestCaseBase.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/test/GenericTestCaseBase.java Sun Jan 31 06:27:41 2010
@@ -11,6 +11,8 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
 
 import junit.framework.TestCase;
 
@@ -21,6 +23,22 @@
         super(name);
     }
 
+    public static <V, E extends Exception> void assertFuture(String label, Future<V> future, V wanted, boolean interruptable, Class<E> thrownClass, String thrownMessage) {
+        try {
+            assertEquals(label + ": future return", wanted, future.get());
+        } catch (InterruptedException e) {
+            assertTrue(label + ": expected interruption", interruptable);
+        } catch (ExecutionException e) {
+            assertNotNull(label + ": expecting an exception", thrownClass);
+            Throwable caught = e.getCause();
+            assertNotNull(label + ": captured exception", caught);
+            assertEquals(label + ": correct thrown class", thrownClass, caught.getClass());
+            if (thrownMessage != null) {
+                assertEquals(label + ": exception message", thrownMessage, caught.getMessage());
+            }
+        }
+    }
+
     public static <T> void assertEquals(List<T> wanted, Object got) {
         assertEquals(null, wanted, got);
     }