6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
< |
import junit.framework.*; |
9 |
> |
import junit.framework.Test; |
10 |
> |
import junit.framework.TestSuite; |
11 |
|
|
12 |
|
public class ThreadTest extends JSR166TestCase { |
13 |
|
public static void main(String[] args) { |
34 |
|
Thread current = Thread.currentThread(); |
35 |
|
ThreadGroup tg = current.getThreadGroup(); |
36 |
|
MyHandler eh = new MyHandler(); |
37 |
< |
assertEquals(tg, current.getUncaughtExceptionHandler()); |
37 |
> |
assertSame(tg, current.getUncaughtExceptionHandler()); |
38 |
|
current.setUncaughtExceptionHandler(eh); |
39 |
< |
assertEquals(eh, current.getUncaughtExceptionHandler()); |
40 |
< |
current.setUncaughtExceptionHandler(null); |
41 |
< |
assertEquals(tg, current.getUncaughtExceptionHandler()); |
39 |
> |
try { |
40 |
> |
assertSame(eh, current.getUncaughtExceptionHandler()); |
41 |
> |
} finally { |
42 |
> |
current.setUncaughtExceptionHandler(null); |
43 |
> |
} |
44 |
> |
assertSame(tg, current.getUncaughtExceptionHandler()); |
45 |
|
} |
46 |
|
|
47 |
|
/** |
52 |
|
assertEquals(null, Thread.getDefaultUncaughtExceptionHandler()); |
53 |
|
// failure due to securityException is OK. |
54 |
|
// Would be nice to explicitly test both ways, but cannot yet. |
55 |
+ |
Thread.UncaughtExceptionHandler defaultHandler |
56 |
+ |
= Thread.getDefaultUncaughtExceptionHandler(); |
57 |
+ |
Thread current = Thread.currentThread(); |
58 |
+ |
MyHandler eh = new MyHandler(); |
59 |
|
try { |
52 |
– |
Thread current = Thread.currentThread(); |
53 |
– |
ThreadGroup tg = current.getThreadGroup(); |
54 |
– |
MyHandler eh = new MyHandler(); |
60 |
|
Thread.setDefaultUncaughtExceptionHandler(eh); |
61 |
< |
assertEquals(eh, Thread.getDefaultUncaughtExceptionHandler()); |
62 |
< |
Thread.setDefaultUncaughtExceptionHandler(null); |
61 |
> |
try { |
62 |
> |
assertSame(eh, Thread.getDefaultUncaughtExceptionHandler()); |
63 |
> |
} finally { |
64 |
> |
Thread.setDefaultUncaughtExceptionHandler(defaultHandler); |
65 |
> |
} |
66 |
> |
} catch (SecurityException ok) { |
67 |
> |
assertNotNull(System.getSecurityManager()); |
68 |
|
} |
69 |
< |
catch (SecurityException ok) { |
60 |
< |
} |
61 |
< |
assertEquals(null, Thread.getDefaultUncaughtExceptionHandler()); |
69 |
> |
assertSame(defaultHandler, Thread.getDefaultUncaughtExceptionHandler()); |
70 |
|
} |
71 |
|
|
64 |
– |
|
72 |
|
// How to test actually using UEH within junit? |
73 |
|
|
74 |
|
} |