You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by lh...@apache.org on 2010/05/11 20:33:57 UTC

svn commit: r943220 - in /incubator/shiro/trunk/core/src: main/java/org/apache/shiro/concurrent/SubjectAwareExecutorService.java test/java/org/apache/shiro/concurrent/SubjectAwareExecutorServiceTest.java

Author: lhazlewood
Date: Tue May 11 18:33:56 2010
New Revision: 943220

URL: http://svn.apache.org/viewvc?rev=943220&view=rev
Log:
SHIRO-140 - added a few sanity tests

Modified:
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/concurrent/SubjectAwareExecutorService.java
    incubator/shiro/trunk/core/src/test/java/org/apache/shiro/concurrent/SubjectAwareExecutorServiceTest.java

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/concurrent/SubjectAwareExecutorService.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/concurrent/SubjectAwareExecutorService.java?rev=943220&r1=943219&r2=943220&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/concurrent/SubjectAwareExecutorService.java (original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/concurrent/SubjectAwareExecutorService.java Tue May 11 18:33:56 2010
@@ -27,8 +27,7 @@ import java.util.concurrent.*;
 
 /**
  * {@code ExecutorService} implementation that will automatically first associate any argument
- * {@link Runnable} or {@link Callable} instances with the currently available
- * {@link org.apache.shiro.subject.Subject Subject} and then
+ * {@link Runnable} or {@link Callable} instances with the {@link #getSubject currently available subject} and then
  * dispatch the Subject-enabled runnable or callable to an underlying delegate
  * {@link java.util.concurrent.ExecutorService ExecutorService} instance.  The principle is the same as the
  * parent {@link SubjectAwareExecutor} class, but enables the richer {@link ExecutorService} API.

Modified: incubator/shiro/trunk/core/src/test/java/org/apache/shiro/concurrent/SubjectAwareExecutorServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/test/java/org/apache/shiro/concurrent/SubjectAwareExecutorServiceTest.java?rev=943220&r1=943219&r2=943220&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/test/java/org/apache/shiro/concurrent/SubjectAwareExecutorServiceTest.java (original)
+++ incubator/shiro/trunk/core/src/test/java/org/apache/shiro/concurrent/SubjectAwareExecutorServiceTest.java Tue May 11 18:33:56 2010
@@ -18,19 +18,24 @@
  */
 package org.apache.shiro.concurrent;
 
+import org.apache.shiro.subject.support.SubjectRunnable;
 import org.apache.shiro.test.SecurityManagerTestSupport;
 import org.junit.Test;
 
+import java.util.concurrent.*;
+
+import static org.easymock.EasyMock.*;
+
 /**
  * Test cases for the {@link SubjectAwareExecutorService} implementation.
  */
 public class SubjectAwareExecutorServiceTest extends SecurityManagerTestSupport {
 
+    @SuppressWarnings({"unchecked"})
     @Test
     public void testSubmitRunnable() {
-        //commenting out for now - the expect call is failing and I don't know why yet - Les
-        /*ExecutorService mockExecutorService = createNiceMock(ExecutorService.class);
-        expect(mockExecutorService.submit(isA(SubjectRunnable.class))).andReturn(isA(Future.class));
+        ExecutorService mockExecutorService = createNiceMock(ExecutorService.class);
+        expect(mockExecutorService.submit(isA(SubjectRunnable.class))).andReturn(new DummyFuture());
         replay(mockExecutorService);
 
         final SubjectAwareExecutorService executor = new SubjectAwareExecutorService(mockExecutorService);
@@ -42,6 +47,29 @@ public class SubjectAwareExecutorService
         };
 
         executor.submit(testRunnable);
-        verify(mockExecutorService);*/
+        verify(mockExecutorService);
+    }
+
+    private class DummyFuture<V> implements Future<V> {
+
+        public boolean cancel(boolean b) {
+            return false;
+        }
+
+        public boolean isCancelled() {
+            return false;
+        }
+
+        public boolean isDone() {
+            return true;
+        }
+
+        public V get() throws InterruptedException, ExecutionException {
+            return null;
+        }
+
+        public V get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
+            return null;
+        }
     }
 }