1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.shiro.concurrent;
20
21 import org.apache.shiro.subject.support.SubjectRunnable;
22 import org.apache.shiro.test.SecurityManagerTestSupport;
23 import org.junit.Test;
24
25 import java.util.concurrent.*;
26
27 import static org.easymock.EasyMock.*;
28
29
30
31
32 public class SubjectAwareExecutorServiceTest extends SecurityManagerTestSupport {
33
34 @SuppressWarnings({"unchecked"})
35 @Test
36 public void testSubmitRunnable() {
37 ExecutorService mockExecutorService = createNiceMock(ExecutorService.class);
38 expect(mockExecutorService.submit(isA(SubjectRunnable.class))).andReturn(new DummyFuture());
39 replay(mockExecutorService);
40
41 final SubjectAwareExecutorService executor = new SubjectAwareExecutorService(mockExecutorService);
42
43 Runnable testRunnable = new Runnable() {
44 public void run() {
45 System.out.println("Hello World");
46 }
47 };
48
49 executor.submit(testRunnable);
50 verify(mockExecutorService);
51 }
52
53 private class DummyFuture<V> implements Future<V> {
54
55 public boolean cancel(boolean b) {
56 return false;
57 }
58
59 public boolean isCancelled() {
60 return false;
61 }
62
63 public boolean isDone() {
64 return true;
65 }
66
67 public V get() throws InterruptedException, ExecutionException {
68 return null;
69 }
70
71 public V get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
72 return null;
73 }
74 }
75 }