3333
3434import static org .junit .Assert .assertSame ;
3535
36+ import java .util .concurrent .Callable ;
37+
3638import org .junit .After ;
3739import org .junit .Before ;
3840import org .junit .Test ;
@@ -64,18 +66,41 @@ public void tearDown() {
6466 * {@link ThreadService#invoke(Runnable)}.
6567 */
6668 @ 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 );
6971 threadService .invoke (ask );
7072 assertSame (Thread .currentThread (), ask .parent );
7173 }
7274
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+
7499 private final ThreadService threadService ;
75100
76101 private Thread parent ;
77102
78- public AskForParent (final ThreadService threadService ) {
103+ public AskForParentR (final ThreadService threadService ) {
79104 this .threadService = threadService ;
80105 }
81106
@@ -85,4 +110,18 @@ public void run() {
85110 }
86111 }
87112
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+
88127}
0 commit comments