33
33
34
34
import static org .junit .Assert .assertSame ;
35
35
36
+ import java .util .concurrent .Callable ;
37
+
36
38
import org .junit .After ;
37
39
import org .junit .Before ;
38
40
import org .junit .Test ;
@@ -64,18 +66,41 @@ public void tearDown() {
64
66
* {@link ThreadService#invoke(Runnable)}.
65
67
*/
66
68
@ Test
67
- public void testGetParent () throws Exception {
68
- final AskForParent ask = new AskForParent (threadService );
69
+ public void testGetParentInvoke () throws Exception {
70
+ final AskForParentR ask = new AskForParentR (threadService );
69
71
threadService .invoke (ask );
70
72
assertSame (Thread .currentThread (), ask .parent );
71
73
}
72
74
73
- private static class AskForParent implements Runnable {
75
+ /**
76
+ * Tests {@link ThreadService#getParent(Thread)} when called after
77
+ * {@link ThreadService#run(Callable)}.
78
+ */
79
+ @ Test
80
+ public void testGetParentRunCallable () throws Exception {
81
+ final AskForParentC ask = new AskForParentC (threadService );
82
+ final Thread parent = threadService .run (ask ).get ();
83
+ assertSame (Thread .currentThread (), parent );
84
+ }
85
+
86
+ /**
87
+ * Tests {@link ThreadService#getParent(Thread)} when called after
88
+ * {@link ThreadService#run(Runnable)}.
89
+ */
90
+ @ Test
91
+ public void testGetParentRunRunnable () throws Exception {
92
+ final AskForParentR ask = new AskForParentR (threadService );
93
+ threadService .run (ask ).get ();
94
+ assertSame (Thread .currentThread (), ask .parent );
95
+ }
96
+
97
+ private static class AskForParentR implements Runnable {
98
+
74
99
private final ThreadService threadService ;
75
100
76
101
private Thread parent ;
77
102
78
- public AskForParent (final ThreadService threadService ) {
103
+ public AskForParentR (final ThreadService threadService ) {
79
104
this .threadService = threadService ;
80
105
}
81
106
@@ -85,4 +110,18 @@ public void run() {
85
110
}
86
111
}
87
112
113
+ private static class AskForParentC implements Callable <Thread > {
114
+
115
+ private final ThreadService threadService ;
116
+
117
+ public AskForParentC (final ThreadService threadService ) {
118
+ this .threadService = threadService ;
119
+ }
120
+
121
+ @ Override
122
+ public Thread call () {
123
+ return threadService .getParent (null );
124
+ }
125
+ }
126
+
88
127
}
0 commit comments