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.15 by jsr166, Wed Dec 31 19:05:43 2014 UTC vs.
Revision 1.20 by jsr166, Sat Mar 18 20:42:20 2017 UTC

# Line 11 | Line 11 | import junit.framework.TestSuite;
11  
12   public class ThreadTest extends JSR166TestCase {
13      public static void main(String[] args) {
14 <        junit.textui.TestRunner.run(suite());
14 >        main(suite(), args);
15      }
16  
17      public static Test suite() {
# Line 34 | Line 34 | public class ThreadTest extends JSR166Te
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      /**
# Line 46 | Line 49 | public class ThreadTest extends JSR166Te
49       * setDefaultUncaughtExceptionHandler.
50       */
51      public void testGetAndSetDefaultUncaughtExceptionHandler() {
52 <        assertEquals(null, Thread.getDefaultUncaughtExceptionHandler());
53 <        // failure due to securityException is OK.
52 >        assertNull(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 +        MyHandler eh = new MyHandler();
58          try {
53            Thread current = Thread.currentThread();
54            ThreadGroup tg = current.getThreadGroup();
55            MyHandler eh = new MyHandler();
59              Thread.setDefaultUncaughtExceptionHandler(eh);
60 <            assertEquals(eh, Thread.getDefaultUncaughtExceptionHandler());
61 <            Thread.setDefaultUncaughtExceptionHandler(null);
62 <        }
63 <        catch (SecurityException ok) {
60 >            try {
61 >                assertSame(eh, Thread.getDefaultUncaughtExceptionHandler());
62 >            } finally {
63 >                Thread.setDefaultUncaughtExceptionHandler(defaultHandler);
64 >            }
65 >        } catch (SecurityException ok) {
66 >            assertNotNull(System.getSecurityManager());
67          }
68 <        assertEquals(null, Thread.getDefaultUncaughtExceptionHandler());
68 >        assertSame(defaultHandler, Thread.getDefaultUncaughtExceptionHandler());
69      }
70  
71      // How to test actually using UEH within junit?

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines