Skip to content

Commit 901154b

Browse files
committed
ThreadServiceTest: test more getParent cases
1 parent 1fa908c commit 901154b

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

src/test/java/org/scijava/thread/ThreadServiceTest.java

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
import static org.junit.Assert.assertSame;
3535

36+
import java.util.concurrent.Callable;
37+
3638
import org.junit.After;
3739
import org.junit.Before;
3840
import 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

Comments
 (0)