ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ThreadTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ThreadTest.java (file contents):
Revision 1.2 by dl, Mon Sep 1 00:17:10 2003 UTC vs.
Revision 1.15 by jsr166, Wed Dec 31 19:05:43 2014 UTC

# Line 1 | Line 1
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.
2 > * Written by Doug Lea with assistance from members of JCP JSR-166
3 > * Expert Group and released to the public domain, as explained at
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9 < import junit.framework.*;
10 < import java.util.concurrent.Semaphore;
9 > import junit.framework.Test;
10 > import junit.framework.TestSuite;
11  
12 < /**
12 < * Test java.lang.Thread
13 < *
14 < */
15 <
16 < public class ThreadTest extends TestCase {
12 > public class ThreadTest extends JSR166TestCase {
13      public static void main(String[] args) {
14 <        junit.textui.TestRunner.run(suite());  
14 >        junit.textui.TestRunner.run(suite());
15      }
16 <    
16 >
17      public static Test suite() {
18 <        return new TestSuite(ThreadTest.class);
18 >        return new TestSuite(ThreadTest.class);
19      }
20  
21      static class MyHandler implements Thread.UncaughtExceptionHandler {
# Line 27 | Line 23 | public class ThreadTest extends TestCase
23              e.printStackTrace();
24          }
25      }
26 <    
26 >
27 >    /**
28 >     * getUncaughtExceptionHandler returns ThreadGroup unless set,
29 >     * otherwise returning value of last setUncaughtExceptionHandler.
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          MyHandler eh = new MyHandler();
37 <        assertEquals(tg, current.getUncaughtExceptionHandler());
37 >        assertEquals(tg, current.getUncaughtExceptionHandler());
38          current.setUncaughtExceptionHandler(eh);
39 <        assertEquals(eh, current.getUncaughtExceptionHandler());
39 >        assertEquals(eh, current.getUncaughtExceptionHandler());
40          current.setUncaughtExceptionHandler(null);
41 <        assertEquals(tg, current.getUncaughtExceptionHandler());
41 >        assertEquals(tg, current.getUncaughtExceptionHandler());
42 >    }
43 >
44 >    /**
45 >     * getDefaultUncaughtExceptionHandler returns value of last
46 >     * setDefaultUncaughtExceptionHandler.
47 >     */
48 >    public void testGetAndSetDefaultUncaughtExceptionHandler() {
49 >        assertEquals(null, Thread.getDefaultUncaughtExceptionHandler());
50 >        // failure due to securityException is OK.
51 >        // Would be nice to explicitly test both ways, but cannot yet.
52 >        try {
53 >            Thread current = Thread.currentThread();
54 >            ThreadGroup tg = current.getThreadGroup();
55 >            MyHandler eh = new MyHandler();
56 >            Thread.setDefaultUncaughtExceptionHandler(eh);
57 >            assertEquals(eh, Thread.getDefaultUncaughtExceptionHandler());
58 >            Thread.setDefaultUncaughtExceptionHandler(null);
59 >        }
60 >        catch (SecurityException ok) {
61 >        }
62 >        assertEquals(null, Thread.getDefaultUncaughtExceptionHandler());
63      }
64 <    
64 >
65      // How to test actually using UEH within junit?
66  
67   }
47

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines