ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ThreadTest.java
Revision: 1.1
Committed: Sun Aug 31 19:24:56 2003 UTC (20 years, 8 months ago) by dl
Branch: MAIN
Log Message:
First check-in of tests to be in tck

File Contents

# Content
1 /*
2 * Written by members of JCP JSR-166 Expert Group and released to the
3 * public domain. Use, modify, and redistribute this code in any way
4 * without acknowledgement. Other contributors include Andrew Wright,
5 * Jeffrey Hayes, Pat Fischer, Mike Judd.
6 */
7
8 import junit.framework.*;
9 import java.util.concurrent.Semaphore;
10
11 /**
12 * Test java.lang.Thread
13 *
14 */
15
16 public class ThreadTest extends TestCase {
17 public static void main(String[] args) {
18 junit.textui.TestRunner.run(suite());
19 }
20
21 public static Test suite() {
22 return new TestSuite(ThreadTest.class);
23 }
24
25 static class MyHandler implements Thread.UncaughtExceptionHandler {
26 public void uncaughtException(Thread t, Throwable e) {
27 e.printStackTrace();
28 }
29 }
30
31 public void testGetAndSetUncaughtExceptionHandler() {
32 // these must be done all at once to avoid state
33 // dependencies across tests
34 Thread current = Thread.currentThread();
35 ThreadGroup tg = current.getThreadGroup();
36 assertNull(Thread.getDefaultUncaughtExceptionHandler());
37 assertEquals(tg, current.getUncaughtExceptionHandler());
38 MyHandler eh = new MyHandler();
39 Thread.setDefaultUncaughtExceptionHandler(eh);
40 assertEquals(eh, current.getUncaughtExceptionHandler());
41 assertEquals(eh, Thread.getDefaultUncaughtExceptionHandler());
42 Thread.setDefaultUncaughtExceptionHandler(null);
43 assertNull(Thread.getDefaultUncaughtExceptionHandler());
44 assertEquals(tg, current.getUncaughtExceptionHandler());
45 current.setUncaughtExceptionHandler(eh);
46 assertEquals(eh, current.getUncaughtExceptionHandler());
47 current.setUncaughtExceptionHandler(null);
48 assertEquals(tg, current.getUncaughtExceptionHandler());
49 }
50
51 // How to test actually using UEH within junit?
52
53 }
54