Update JSR166 tck tests.

The following tests have been omitted because they are
unsupported :

- Atomic8Test.java
- CompletableFutureTest.java
- ConcurrentHashMap8Test.java
- DoubleAccumulatorTest.java
- DoubleAdderTest.java
- ForkJoinPool8Test.java
- ForkJoinTask8Test.java
- LongAccumulatorTest.java
- LongAdderTest.java
- SplittableRandomTest.java
- StampedLockTest.java
- ThreadLocalRandom8Test.java
- ThreadPoolExecutor9Test.java

A package declaration has been added to all files (package jsr166;)
and the base-class JSR166Test has been changed not to rely on features
that aren't available on android / junit in the android environment.

We also avoid using junit4 style TestSuite declarations. While the CTS
test runner handles them properly usually, it trips over itself when it
encounters a failure and tries to run each test in an invidual process
and fails each test for no good reason (needs investigation on the CTS
side of things)

bug: 20628776

(cherry picked from commit 5da8b2b3cac51f0f592a5e1941bd84eade9648cd)

Change-Id: If35be0881ad8da4c604ce6683149b15c1a85f289
diff --git a/jsr166-tests/src/test/java/jsr166/ThreadTest.java b/jsr166-tests/src/test/java/jsr166/ThreadTest.java
index 12c2f8a..2652201 100644
--- a/jsr166-tests/src/test/java/jsr166/ThreadTest.java
+++ b/jsr166-tests/src/test/java/jsr166/ThreadTest.java
@@ -8,9 +8,19 @@
 
 package jsr166;
 
-import junit.framework.*;
+import junit.framework.Test;
+import junit.framework.TestSuite;
 
 public class ThreadTest extends JSR166TestCase {
+    // android-note: Removed because the CTS runner does a bad job of
+    // retrying tests that have suite() declarations.
+    //
+    // public static void main(String[] args) {
+    //     main(suite(), args);
+    // }
+    // public static Test suite() {
+    //     return new TestSuite(...);
+    // }
 
     static class MyHandler implements Thread.UncaughtExceptionHandler {
         public void uncaughtException(Thread t, Throwable e) {
@@ -28,11 +38,14 @@
         Thread current = Thread.currentThread();
         ThreadGroup tg = current.getThreadGroup();
         MyHandler eh = new MyHandler();
-        assertEquals(tg, current.getUncaughtExceptionHandler());
+        assertSame(tg, current.getUncaughtExceptionHandler());
         current.setUncaughtExceptionHandler(eh);
-        assertEquals(eh, current.getUncaughtExceptionHandler());
-        current.setUncaughtExceptionHandler(null);
-        assertEquals(tg, current.getUncaughtExceptionHandler());
+        try {
+            assertSame(eh, current.getUncaughtExceptionHandler());
+        } finally {
+            current.setUncaughtExceptionHandler(null);
+        }
+        assertSame(tg, current.getUncaughtExceptionHandler());
     }
 
     /**
@@ -40,24 +53,23 @@
      * setDefaultUncaughtExceptionHandler.
      */
     public void testGetAndSetDefaultUncaughtExceptionHandler() {
-        // BEGIN android-remove (when running as cts the RuntimeInit will 
-        // set a default handler)
-        // assertEquals(null, Thread.getDefaultUncaughtExceptionHandler());
-        // END android-remove
-
+        assertEquals(null, Thread.getDefaultUncaughtExceptionHandler());
         // failure due to securityException is OK.
         // Would be nice to explicitly test both ways, but cannot yet.
+        Thread.UncaughtExceptionHandler defaultHandler
+            = Thread.getDefaultUncaughtExceptionHandler();
+        MyHandler eh = new MyHandler();
         try {
-            Thread current = Thread.currentThread();
-            ThreadGroup tg = current.getThreadGroup();
-            MyHandler eh = new MyHandler();
             Thread.setDefaultUncaughtExceptionHandler(eh);
-            assertEquals(eh, Thread.getDefaultUncaughtExceptionHandler());
-            Thread.setDefaultUncaughtExceptionHandler(null);
+            try {
+                assertSame(eh, Thread.getDefaultUncaughtExceptionHandler());
+            } finally {
+                Thread.setDefaultUncaughtExceptionHandler(defaultHandler);
+            }
+        } catch (SecurityException ok) {
+            assertNotNull(System.getSecurityManager());
         }
-        catch (SecurityException ok) {
-        }
-        assertEquals(null, Thread.getDefaultUncaughtExceptionHandler());
+        assertSame(defaultHandler, Thread.getDefaultUncaughtExceptionHandler());
     }
 
     // How to test actually using UEH within junit?