harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r437974 [18/19] - /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/
Date Tue, 29 Aug 2006 05:40:47 GMT
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadLocalTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadLocalTest.java?rev=437974&r1=437973&r2=437974&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadLocalTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadLocalTest.java Mon Aug 28 22:40:44 2006
@@ -1,142 +1,142 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class ThreadLocalTest extends TestCase {
-
-	/**
-     * @tests java.lang.ThreadLocal#ThreadLocal()
-     */
-    public void test_Constructor() {
-        try {
-            new ThreadLocal<Object>();
-        } catch (Exception e) {
-            fail("unexpected exception: " + e.toString());
-        }
-    }
-    
-    /**
-     * @tests java.lang.ThreadLocal#remove()
-     */
-    public void test_remove() {
-        ThreadLocal<String> tl = new ThreadLocal<String>() {
-            @Override
-            protected String initialValue() {
-                return "initial";
-            }
-        };
-        
-        assertEquals("initial", tl.get());
-        tl.set("fixture");
-        assertEquals("fixture", tl.get());
-        tl.remove();
-        assertEquals("initial", tl.get());
-    }
-
-	/**
-	 * @tests java.lang.ThreadLocal#get()
-	 */
-	public void test_get() {
-		// Test for method java.lang.Object java.lang.ThreadLocal.get()
-		ThreadLocal<Object> l = new ThreadLocal<Object>();
-		assertNull("ThreadLocal's initial value is null", l.get());
-
-		// The ThreadLocal has to run once for each thread that touches the
-		// ThreadLocal
-		final Object INITIAL_VALUE = "'foo'";
-		final ThreadLocal<Object> l1 = new ThreadLocal<Object>() {
-			@Override
-            protected Object initialValue() {
-				return INITIAL_VALUE;
-			}
-		};
-
-		assertTrue("ThreadLocal's initial value should be " + INITIAL_VALUE
-				+ " but is " + l1.get(), l1.get() == INITIAL_VALUE);
-
-		// We need this because inner types cannot assign to variables in
-		// container method. But assigning to object slots in the container
-		// method is ok.
-		class ResultSlot {
-			public Object result = null;
-		}
-
-		final ResultSlot THREADVALUE = new ResultSlot();
-		Thread t = new Thread() {
-			@Override
-            public void run() {
-				THREADVALUE.result = l1.get();
-			}
-		};
-
-		// Wait for the other Thread assign what it observes as the value of the
-		// variable
-		t.start();
-		try {
-			t.join();
-		} catch (InterruptedException ie) {
-			fail("Interrupted!!");
-		}
-
-		assertTrue("ThreadLocal's initial value in other Thread should be "
-				+ INITIAL_VALUE, THREADVALUE.result == INITIAL_VALUE);
-
-	}
-
-	/**
-	 * @tests java.lang.ThreadLocal#set(java.lang.Object)
-	 */
-	public void test_setLjava_lang_Object() {
-		// Test for method void java.lang.ThreadLocal.set(java.lang.Object)
-
-		final Object OBJ = new Object();
-		final ThreadLocal<Object> l = new ThreadLocal<Object>();
-		l.set(OBJ);
-		assertTrue("ThreadLocal's initial value is " + OBJ, l.get() == OBJ);
-
-		// We need this because inner types cannot assign to variables in
-		// container method.
-		// But assigning to object slots in the container method is ok.
-		class ResultSlot {
-			public Object result = null;
-		}
-
-		final ResultSlot THREADVALUE = new ResultSlot();
-		Thread t = new Thread() {
-			@Override
-            public void run() {
-				THREADVALUE.result = l.get();
-			}
-		};
-
-		// Wait for the other Thread assign what it observes as the value of the
-		// variable
-		t.start();
-		try {
-			t.join();
-		} catch (InterruptedException ie) {
-			fail("Interrupted!!");
-		}
-
-		// ThreadLocal is not inherited, so the other Thread should see it as
-		// null
-		assertNull("ThreadLocal's value in other Thread should be null",
-				THREADVALUE.result);
-
-	}
-}
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.luni.tests.java.lang;
+
+import junit.framework.TestCase;
+
+public class ThreadLocalTest extends TestCase {
+
+	/**
+     * @tests java.lang.ThreadLocal#ThreadLocal()
+     */
+    public void test_Constructor() {
+        try {
+            new ThreadLocal<Object>();
+        } catch (Exception e) {
+            fail("unexpected exception: " + e.toString());
+        }
+    }
+    
+    /**
+     * @tests java.lang.ThreadLocal#remove()
+     */
+    public void test_remove() {
+        ThreadLocal<String> tl = new ThreadLocal<String>() {
+            @Override
+            protected String initialValue() {
+                return "initial";
+            }
+        };
+        
+        assertEquals("initial", tl.get());
+        tl.set("fixture");
+        assertEquals("fixture", tl.get());
+        tl.remove();
+        assertEquals("initial", tl.get());
+    }
+
+	/**
+	 * @tests java.lang.ThreadLocal#get()
+	 */
+	public void test_get() {
+		// Test for method java.lang.Object java.lang.ThreadLocal.get()
+		ThreadLocal<Object> l = new ThreadLocal<Object>();
+		assertNull("ThreadLocal's initial value is null", l.get());
+
+		// The ThreadLocal has to run once for each thread that touches the
+		// ThreadLocal
+		final Object INITIAL_VALUE = "'foo'";
+		final ThreadLocal<Object> l1 = new ThreadLocal<Object>() {
+			@Override
+            protected Object initialValue() {
+				return INITIAL_VALUE;
+			}
+		};
+
+		assertTrue("ThreadLocal's initial value should be " + INITIAL_VALUE
+				+ " but is " + l1.get(), l1.get() == INITIAL_VALUE);
+
+		// We need this because inner types cannot assign to variables in
+		// container method. But assigning to object slots in the container
+		// method is ok.
+		class ResultSlot {
+			public Object result = null;
+		}
+
+		final ResultSlot THREADVALUE = new ResultSlot();
+		Thread t = new Thread() {
+			@Override
+            public void run() {
+				THREADVALUE.result = l1.get();
+			}
+		};
+
+		// Wait for the other Thread assign what it observes as the value of the
+		// variable
+		t.start();
+		try {
+			t.join();
+		} catch (InterruptedException ie) {
+			fail("Interrupted!!");
+		}
+
+		assertTrue("ThreadLocal's initial value in other Thread should be "
+				+ INITIAL_VALUE, THREADVALUE.result == INITIAL_VALUE);
+
+	}
+
+	/**
+	 * @tests java.lang.ThreadLocal#set(java.lang.Object)
+	 */
+	public void test_setLjava_lang_Object() {
+		// Test for method void java.lang.ThreadLocal.set(java.lang.Object)
+
+		final Object OBJ = new Object();
+		final ThreadLocal<Object> l = new ThreadLocal<Object>();
+		l.set(OBJ);
+		assertTrue("ThreadLocal's initial value is " + OBJ, l.get() == OBJ);
+
+		// We need this because inner types cannot assign to variables in
+		// container method.
+		// But assigning to object slots in the container method is ok.
+		class ResultSlot {
+			public Object result = null;
+		}
+
+		final ResultSlot THREADVALUE = new ResultSlot();
+		Thread t = new Thread() {
+			@Override
+            public void run() {
+				THREADVALUE.result = l.get();
+			}
+		};
+
+		// Wait for the other Thread assign what it observes as the value of the
+		// variable
+		t.start();
+		try {
+			t.join();
+		} catch (InterruptedException ie) {
+			fail("Interrupted!!");
+		}
+
+		// ThreadLocal is not inherited, so the other Thread should see it as
+		// null
+		assertNull("ThreadLocal's value in other Thread should be null",
+				THREADVALUE.result);
+
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadLocalTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadTest.java?rev=437974&r1=437973&r2=437974&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadTest.java Mon Aug 28 22:40:44 2006
@@ -1,1272 +1,1272 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import java.lang.Thread.UncaughtExceptionHandler;
-import java.security.Permission;
-import java.util.Map;
-
-public class ThreadTest extends junit.framework.TestCase {
-
-	static class SimpleThread implements Runnable {
-		int delay;
-
-		public void run() {
-			try {
-				synchronized (this) {
-					this.notify();
-					this.wait(delay);
-				}
-			} catch (InterruptedException e) {
-				return;
-			}
-
-		}
-
-		public SimpleThread(int d) {
-			if (d >= 0)
-				delay = d;
-		}
-	}
-
-	static class YieldThread implements Runnable {
-		volatile int delay;
-
-		public void run() {
-			int x = 0;
-			while (true) {
-				++x;
-			}
-		}
-
-		public YieldThread(int d) {
-			if (d >= 0)
-				delay = d;
-		}
-	}
-
-	static class ResSupThread implements Runnable {
-		Thread parent;
-
-		volatile int checkVal = -1;
-
-		public void run() {
-			try {
-				synchronized (this) {
-					this.notify();
-				}
-				while (true) {
-					checkVal++;
-					zz();
-					Thread.sleep(100);
-				}
-			} catch (InterruptedException e) {
-				return;
-			} catch (BogusException e) {
-				try {
-					// Give parent a chance to sleep
-					Thread.sleep(500);
-				} catch (InterruptedException x) {
-				}
-				parent.interrupt();
-				while (!Thread.currentThread().isInterrupted()) {
-					// Don't hog the CPU
-					try {
-						Thread.sleep(50);
-					} catch (InterruptedException x) {
-						// This is what we've been waiting for...don't throw it
-						// away!
-						break;
-					}
-				}
-			}
-		}
-
-		public void zz() throws BogusException {
-		}
-
-		public ResSupThread(Thread t) {
-			parent = t;
-		}
-
-		public synchronized int getCheckVal() {
-			return checkVal;
-		}
-	}
-
-	static class BogusException extends Throwable {
-
-        private static final long serialVersionUID = 1L;
-
-        public BogusException(String s) {
-			super(s);
-		}
-	}
-
-	Thread st, ct, spinner;
-
-	static boolean calledMySecurityManager = false;
-
-	/**
-	 * @tests java.lang.Thread#Thread()
-	 */
-	public void test_Constructor() {
-		// Test for method java.lang.Thread()
-
-		Thread t;
-		SecurityManager m = new SecurityManager() {
-			@Override
-            public ThreadGroup getThreadGroup() {
-				calledMySecurityManager = true;
-				return Thread.currentThread().getThreadGroup();
-			}
-            
-            @Override
-            public void checkPermission(Permission permission) {
-                if (permission.getName().equals("setSecurityManager")) {
-                    return;
-                }
-                super.checkPermission(permission);
-            }
-		};
-		try {
-			// To see if it checks Thread creation with our SecurityManager
-			System.setSecurityManager(m);
-			t = new Thread();
-		} finally {
-			// restore original, no side-effects
-			System.setSecurityManager(null);
-		}
-		assertTrue("Did not call SecurityManager.getThreadGroup ()",
-				calledMySecurityManager);
-		t.start();
-	}
-
-	/**
-	 * @tests java.lang.Thread#Thread(java.lang.Runnable)
-	 */
-	public void test_ConstructorLjava_lang_Runnable() {
-		// Test for method java.lang.Thread(java.lang.Runnable)
-		try {
-			ct = new Thread(new SimpleThread(10));
-			ct.start();
-		} catch (Exception e) {
-			fail("Failed to create subthread : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.lang.Thread#Thread(java.lang.Runnable, java.lang.String)
-	 */
-	public void test_ConstructorLjava_lang_RunnableLjava_lang_String() {
-		// Test for method java.lang.Thread(java.lang.Runnable,
-		// java.lang.String)
-		Thread st1 = new Thread(new SimpleThread(1), "SimpleThread1");
-		assertEquals("Constructed thread with incorrect thread name", "SimpleThread1", st1
-				.getName());
-		st1.start();
-	}
-
-	/**
-	 * @tests java.lang.Thread#Thread(java.lang.String)
-	 */
-	public void test_ConstructorLjava_lang_String() {
-		// Test for method java.lang.Thread(java.lang.String)
-		Thread t = new Thread("Testing");
-		assertEquals("Created tread with incorrect name", 
-				"Testing", t.getName());
-		t.start();
-	}
-
-	/**
-	 * @tests java.lang.Thread#Thread(java.lang.ThreadGroup, java.lang.Runnable)
-	 */
-	public void test_ConstructorLjava_lang_ThreadGroupLjava_lang_Runnable() {
-		// Test for method java.lang.Thread(java.lang.ThreadGroup,
-		// java.lang.Runnable)
-		ThreadGroup tg = new ThreadGroup("Test Group1");
-		st = new Thread(tg, new SimpleThread(1), "SimpleThread2");
-		assertTrue("Returned incorrect thread group", st.getThreadGroup() == tg);
-		st.start();
-		try {
-			st.join();
-		} catch (InterruptedException e) {
-		}
-		tg.destroy();
-	}
-
-	/**
-	 * @tests java.lang.Thread#Thread(java.lang.ThreadGroup, java.lang.Runnable,
-	 *        java.lang.String)
-	 */
-	public void test_ConstructorLjava_lang_ThreadGroupLjava_lang_RunnableLjava_lang_String() {
-		// Test for method java.lang.Thread(java.lang.ThreadGroup,
-		// java.lang.Runnable, java.lang.String)
-		ThreadGroup tg = new ThreadGroup("Test Group2");
-		st = new Thread(tg, new SimpleThread(1), "SimpleThread3");
-		assertTrue("Constructed incorrect thread", (st.getThreadGroup() == tg)
-				&& st.getName().equals("SimpleThread3"));
-		st.start();
-		try {
-			st.join();
-		} catch (InterruptedException e) {
-		}
-		tg.destroy();
-
-		Runnable r = new Runnable() {
-			public void run() {
-			}
-		};
-
-		ThreadGroup foo = null;
-		try {
-			new Thread(foo = new ThreadGroup("foo"), r, null);
-			// Should not get here
-			fail("Null cannot be accepted as Thread name");
-		} catch (NullPointerException npe) {
-			assertTrue("Null cannot be accepted as Thread name", true);
-			foo.destroy();
-		}
-
-	}
-
-	/**
-	 * @tests java.lang.Thread#Thread(java.lang.ThreadGroup, java.lang.String)
-	 */
-	public void test_ConstructorLjava_lang_ThreadGroupLjava_lang_String() {
-		// Test for method java.lang.Thread(java.lang.ThreadGroup,
-		// java.lang.String)
-		st = new Thread(new SimpleThread(1), "SimpleThread4");
-		assertEquals("Returned incorrect thread name", 
-				"SimpleThread4", st.getName());
-		st.start();
-	}
-
-	/**
-	 * @tests java.lang.Thread#activeCount()
-	 */
-	public void test_activeCount() {
-		// Test for method int java.lang.Thread.activeCount()
-		Thread t = new Thread(new SimpleThread(1));
-		int active = Thread.activeCount();
-		assertTrue("Incorrect read made: " + active, active > 0);
-		t.start();
-		try {
-			t.join();
-		} catch (InterruptedException e) {
-		}
-	}
-
-	/**
-	 * @tests java.lang.Thread#checkAccess()
-	 */
-	public void test_checkAccess() {
-		// Test for method void java.lang.Thread.checkAccess()
-		ThreadGroup tg = new ThreadGroup("Test Group3");
-		try {
-			st = new Thread(tg, new SimpleThread(1), "SimpleThread5");
-			st.checkAccess();
-			assertTrue("CheckAccess passed", true);
-		} catch (SecurityException e) {
-			fail("CheckAccess failed : " + e.getMessage());
-		}
-		st.start();
-		try {
-			st.join();
-		} catch (InterruptedException e) {
-		}
-		tg.destroy();
-	}
-
-	/**
-     * @tests java.lang.Thread#countStackFrames()
-     */
-    @SuppressWarnings("deprecation")
-    public void test_countStackFrames() {
-        /*
-         * Thread.countStackFrames() is unpredictable, so we just test that it
-         * doesn't throw an exception.
-         */
-        try {
-            Thread.currentThread().countStackFrames();
-        } catch (Throwable t) {
-            fail("unexpected throwable: " + t.toString());
-        }
-    }
-
-	/**
-	 * @tests java.lang.Thread#currentThread()
-	 */
-	public void test_currentThread() {
-	    assertNotNull(Thread.currentThread());
-	}
-
-	/**
-	 * @tests java.lang.Thread#destroy()
-	 */
-	@SuppressWarnings("deprecation")
-    public void test_destroy() {
-	    try {
-	        new Thread().destroy();
-            // FIXME uncomment when IBM VME is updated
-            //fail("NoSuchMethodError was not thrown");
-        } catch (NoSuchMethodError e) {
-        }
-	}
-
-	/**
-	 * @tests java.lang.Thread#enumerate(java.lang.Thread[])
-	 */
-	public void test_enumerate$Ljava_lang_Thread() {
-		// Test for method int java.lang.Thread.enumerate(java.lang.Thread [])
-		Thread[] tarray = new Thread[10];
-		int initialCount = Thread.enumerate(tarray);
-		ThreadGroup mytg = new ThreadGroup("jp");
-		SimpleThread st1 = new SimpleThread(-1);
-		SimpleThread st2 = new SimpleThread(-1);
-		Thread firstOne = new Thread(mytg, st1, "firstOne2");
-		Thread secondOne = new Thread(mytg, st2, "secondOne1");
-		assertTrue("Incorrect value returned1",
-				Thread.enumerate(tarray) == initialCount);
-		synchronized (st1) {
-			firstOne.start();
-			try {
-				st1.wait();
-			} catch (InterruptedException e) {
-			}
-		}
-		assertTrue("Incorrect value returned2",
-				Thread.enumerate(tarray) == (initialCount + 1));
-
-		synchronized (st2) {
-			secondOne.start();
-			try {
-				st2.wait();
-			} catch (InterruptedException e) {
-			}
-		}
-		assertTrue("Incorrect value returned3",
-				Thread.enumerate(tarray) == (initialCount + 2));
-
-		synchronized (st1) {
-			firstOne.interrupt();
-		}
-		synchronized (st2) {
-			secondOne.interrupt();
-		}
-		try {
-			firstOne.join();
-			secondOne.join();
-		} catch (InterruptedException e) {
-		}
-		mytg.destroy();
-	}
-
-	/**
-	 * @tests java.lang.Thread#getContextClassLoader()
-	 */
-	public void test_getContextClassLoader() {
-		// Test for method java.lang.ClassLoader
-		// java.lang.Thread.getContextClassLoader()
-		Thread t = new Thread();
-		assertTrue("Incorrect class loader returned",
-				t.getContextClassLoader() == Thread.currentThread()
-						.getContextClassLoader());
-		t.start();
-
-	}
-
-	/**
-	 * @tests java.lang.Thread#getName()
-	 */
-	public void test_getName() {
-		// Test for method java.lang.String java.lang.Thread.getName()
-		st = new Thread(new SimpleThread(1), "SimpleThread6");
-		assertEquals("Returned incorrect thread name", 
-				"SimpleThread6", st.getName());
-		st.start();
-	}
-
-	/**
-	 * @tests java.lang.Thread#getPriority()
-	 */
-	public void test_getPriority() {
-		// Test for method int java.lang.Thread.getPriority()
-		st = new Thread(new SimpleThread(1));
-		st.setPriority(Thread.MAX_PRIORITY);
-		assertTrue("Returned incorrect thread priority",
-				st.getPriority() == Thread.MAX_PRIORITY);
-		st.start();
-	}
-
-	/**
-	 * @tests java.lang.Thread#getThreadGroup()
-	 */
-	public void test_getThreadGroup() {
-		// Test for method java.lang.ThreadGroup
-		// java.lang.Thread.getThreadGroup()
-		ThreadGroup tg = new ThreadGroup("Test Group4");
-		st = new Thread(tg, new SimpleThread(1), "SimpleThread8");
-		assertTrue("Returned incorrect thread group", st.getThreadGroup() == tg);
-		st.start();
-		try {
-			st.join();
-		} catch (InterruptedException e) {
-		}
-		assertNull("group should be null", st.getThreadGroup());
-		assertNotNull("toString() should not be null", st.toString());
-		tg.destroy();
-
-		final Object lock = new Object();
-		Thread t = new Thread() {
-			@Override
-            public void run() {
-				synchronized (lock) {
-					lock.notifyAll();
-				}
-			}
-		};
-		synchronized (lock) {
-			t.start();
-			try {
-				lock.wait();
-			} catch (InterruptedException e) {
-			}
-		}
-		int running = 0;
-		while (t.isAlive())
-			running++;
-		ThreadGroup group = t.getThreadGroup();
-		assertNull("ThreadGroup is not null", group);
-	}
-
-	/**
-	 * @tests java.lang.Thread#interrupt()
-	 */
-	public void test_interrupt() {
-		// Test for method void java.lang.Thread.interrupt()
-		final Object lock = new Object();
-		class ChildThread1 extends Thread {
-			Thread parent;
-
-			boolean sync;
-
-			@Override
-            public void run() {
-				if (sync) {
-					synchronized (lock) {
-						lock.notify();
-						try {
-							lock.wait();
-						} catch (InterruptedException e) {
-						}
-					}
-				}
-				parent.interrupt();
-			}
-
-			public ChildThread1(Thread p, String name, boolean sync) {
-				super(name);
-				parent = p;
-				this.sync = sync;
-			}
-		}
-		boolean interrupted = false;
-		try {
-			ct = new ChildThread1(Thread.currentThread(), "Interrupt Test1",
-					false);
-			synchronized (lock) {
-				ct.start();
-				lock.wait();
-			}
-		} catch (InterruptedException e) {
-			interrupted = true;
-		}
-		assertTrue("Failed to Interrupt thread1", interrupted);
-
-		interrupted = false;
-		try {
-			ct = new ChildThread1(Thread.currentThread(), "Interrupt Test2",
-					true);
-			synchronized (lock) {
-				ct.start();
-				lock.wait();
-				lock.notify();
-			}
-			Thread.sleep(20000);
-		} catch (InterruptedException e) {
-			interrupted = true;
-		}
-		assertTrue("Failed to Interrupt thread2", interrupted);
-
-	}
-
-	/**
-	 * @tests java.lang.Thread#interrupted()
-	 */
-	public void test_interrupted() {
-        assertFalse("Interrupted returned true for non-interrupted thread", Thread
-                .interrupted());
-        Thread.currentThread().interrupt();
-        assertTrue("Interrupted returned true for non-interrupted thread", Thread.interrupted());
-        assertFalse("Failed to clear interrupted flag", Thread.interrupted());
-    }
-
-	/**
-	 * @tests java.lang.Thread#isAlive()
-	 */
-	public void test_isAlive() {
-		// Test for method boolean java.lang.Thread.isAlive()
-		SimpleThread simple;
-		st = new Thread(simple = new SimpleThread(500));
-		assertFalse("A thread that wasn't started is alive.", st.isAlive());
-		synchronized (simple) {
-			st.start();
-			try {
-				simple.wait();
-			} catch (InterruptedException e) {
-			}
-		}
-		assertTrue("Started thread returned false", st.isAlive());
-		try {
-			st.join();
-		} catch (InterruptedException e) {
-			fail("Thread did not die");
-		}
-		assertTrue("Stopped thread returned true", !st.isAlive());
-	}
-
-	/**
-	 * @tests java.lang.Thread#isDaemon()
-	 */
-	public void test_isDaemon() {
-		// Test for method boolean java.lang.Thread.isDaemon()
-		st = new Thread(new SimpleThread(1), "SimpleThread10");
-		assertTrue("Non-Daemon thread returned true", !st.isDaemon());
-		st.setDaemon(true);
-		assertTrue("Daemon thread returned false", st.isDaemon());
-		st.start();
-	}
-
-	/**
-	 * @tests java.lang.Thread#isInterrupted()
-	 */
-	public void test_isInterrupted() {
-		// Test for method boolean java.lang.Thread.isInterrupted()
-		class SpinThread implements Runnable {
-			public volatile boolean done = false;
-
-			public void run() {
-				while (!Thread.currentThread().isInterrupted())
-					;
-				while (!done)
-					;
-			}
-		}
-
-		SpinThread spin = new SpinThread();
-		spinner = new Thread(spin);
-		spinner.start();
-		Thread.yield();
-		try {
-			assertTrue("Non-Interrupted thread returned true", !spinner
-					.isInterrupted());
-			spinner.interrupt();
-			assertTrue("Interrupted thread returned false", spinner
-					.isInterrupted());
-			spin.done = true;
-		} finally {
-			spinner.interrupt();
-			spin.done = true;
-		}
-	}
-
-	/**
-	 * @tests java.lang.Thread#join()
-	 */
-	public void test_join() {
-		// Test for method void java.lang.Thread.join()
-		SimpleThread simple;
-		try {
-			st = new Thread(simple = new SimpleThread(100));
-			// cause isAlive() to be compiled by the JIT, as it must be called
-			// within 100ms below.
-			assertTrue("Thread is alive", !st.isAlive());
-			synchronized (simple) {
-				st.start();
-				simple.wait();
-			}
-			st.join();
-		} catch (InterruptedException e) {
-			fail("Join failed ");
-		}
-		assertTrue("Joined thread is still alive", !st.isAlive());
-		boolean result = true;
-		Thread th = new Thread("test");
-		try {
-			th.join();
-		} catch (InterruptedException e) {
-			result = false;
-		}
-		assertTrue("Hung joining a non-started thread", result);
-		th.start();
-	}
-
-	/**
-	 * @tests java.lang.Thread#join(long)
-	 */
-	public void test_joinJ() {
-		// Test for method void java.lang.Thread.join(long)
-		SimpleThread simple;
-		try {
-			st = new Thread(simple = new SimpleThread(1000), "SimpleThread12");
-			// cause isAlive() to be compiled by the JIT, as it must be called
-			// within 100ms below.
-			assertTrue("Thread is alive", !st.isAlive());
-			synchronized (simple) {
-				st.start();
-				simple.wait();
-			}
-			st.join(10);
-		} catch (InterruptedException e) {
-			fail("Join failed ");
-		}
-		assertTrue("Join failed to timeout", st.isAlive());
-
-		st.interrupt();
-		try {
-			st = new Thread(simple = new SimpleThread(100), "SimpleThread13");
-			synchronized (simple) {
-				st.start();
-				simple.wait();
-			}
-			st.join(1000);
-		} catch (InterruptedException e) {
-			fail("Join failed : " + e.getMessage());
-			return;
-		}
-		assertTrue("Joined thread is still alive", !st.isAlive());
-
-		final Object lock = new Object();
-		final Thread main = Thread.currentThread();
-		Thread killer = new Thread(new Runnable() {
-			public void run() {
-				try {
-					synchronized (lock) {
-						lock.notify();
-					}
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-					return;
-				}
-				main.interrupt();
-			}
-		});
-		boolean result = true;
-		Thread th = new Thread("test");
-		try {
-			synchronized (lock) {
-				killer.start();
-				lock.wait();
-			}
-			th.join(200);
-		} catch (InterruptedException e) {
-			result = false;
-		}
-		killer.interrupt();
-		assertTrue("Hung joining a non-started thread", result);
-		th.start();
-	}
-
-	/**
-	 * @tests java.lang.Thread#join(long, int)
-	 */
-	public void test_joinJI() {
-		// Test for method void java.lang.Thread.join(long, int)
-		SimpleThread simple;
-		try {
-			st = new Thread(simple = new SimpleThread(1000), "Squawk1");
-			assertTrue("Thread is alive", !st.isAlive());
-			synchronized (simple) {
-				st.start();
-				simple.wait();
-			}
-			
-			long firstRead = System.currentTimeMillis();
-			st.join(100, 999999);
-			long secondRead = System.currentTimeMillis();
-			assertTrue("Did not join by appropriate time: " + secondRead + "-"
-					+ firstRead + "=" + (secondRead - firstRead), secondRead
-					- firstRead <= 300);
-			assertTrue("Joined thread is not alive", st.isAlive());
-			st.interrupt();  
-		} catch (Exception e) {
-			fail("Exception during test : " + e.getMessage());
-		}
-
-		final Object lock = new Object();
-		final Thread main = Thread.currentThread();
-		Thread killer = new Thread(new Runnable() {
-			public void run() {
-				try {
-					synchronized (lock) {
-						lock.notify();
-					}
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-					return;
-				}
-				main.interrupt();
-			}
-		});
-		boolean result = true;
-		Thread th = new Thread("test");
-		try {
-			synchronized (lock) {
-				killer.start();
-				lock.wait();
-			}
-			th.join(200, 20);
-		} catch (InterruptedException e) {
-			result = false;
-		}
-		killer.interrupt();
-		assertTrue("Hung joining a non-started thread", result);
-		th.start();
-	}
-
-	/**
-	 * @tests java.lang.Thread#resume()
-	 */
-	@SuppressWarnings("deprecation")
-    public void test_resume() {
-		// Test for method void java.lang.Thread.resume()
-		int orgval;
-		ResSupThread t;
-		try {
-			t = new ResSupThread(Thread.currentThread());
-			synchronized (t) {
-				ct = new Thread(t, "Interrupt Test2");
-				ct.start();
-				t.wait();
-			}
-			ct.suspend();
-			// Wait to be sure the suspend has occurred
-			Thread.sleep(500);
-			orgval = t.getCheckVal();
-			// Wait to be sure the thread is suspended
-			Thread.sleep(500);
-			assertTrue("Failed to suspend thread", orgval == t.getCheckVal());
-			ct.resume();
-			// Wait to be sure the resume has occurred.
-			Thread.sleep(500);
-			assertTrue("Failed to resume thread", orgval != t.getCheckVal());
-			ct.interrupt();
-		} catch (InterruptedException e) {
-			fail("Unexpected interrupt occurred : " + e.getMessage());
-		}
-	}
-
-	/**
-	 * @tests java.lang.Thread#run()
-	 */
-	public void test_run() {
-		// Test for method void java.lang.Thread.run()
-		class RunThread implements Runnable {
-			boolean didThreadRun = false;
-
-			public void run() {
-				didThreadRun = true;
-			}
-		}
-		RunThread rt = new RunThread();
-		Thread t = new Thread(rt);
-		try {
-			t.start();
-			int count = 0;
-			while (!rt.didThreadRun && count < 20) {
-				Thread.sleep(100);
-				count++;
-			}
-			assertTrue("Thread did not run", rt.didThreadRun);
-			t.join();
-		} catch (InterruptedException e) {
-			assertTrue("Joined thread was interrupted", true);
-		}
-		assertTrue("Joined thread is still alive", !t.isAlive());
-	}
-
-	/**
-	 * @tests java.lang.Thread#setDaemon(boolean)
-	 */
-	public void test_setDaemonZ() {
-		// Test for method void java.lang.Thread.setDaemon(boolean)
-		st = new Thread(new SimpleThread(1), "SimpleThread14");
-		st.setDaemon(true);
-		assertTrue("Failed to set thread as daemon thread", st.isDaemon());
-		st.start();
-	}
-
-	/**
-	 * @tests java.lang.Thread#setName(java.lang.String)
-	 */
-	public void test_setNameLjava_lang_String() {
-		// Test for method void java.lang.Thread.setName(java.lang.String)
-		st = new Thread(new SimpleThread(1), "SimpleThread15");
-		st.setName("Bogus Name");
-		assertEquals("Failed to set thread name", 
-				"Bogus Name", st.getName());
-		try {
-			st.setName(null);
-			fail("Null should not be accepted as a valid name");
-		} catch (NullPointerException e) {
-			// success
-			assertTrue("Null should not be accepted as a valid name", true);
-		}
-		st.start();
-	}
-
-	/**
-	 * @tests java.lang.Thread#setPriority(int)
-	 */
-	public void test_setPriorityI() {
-		// Test for method void java.lang.Thread.setPriority(int)
-		st = new Thread(new SimpleThread(1));
-		st.setPriority(Thread.MAX_PRIORITY);
-		assertTrue("Failed to set priority",
-				st.getPriority() == Thread.MAX_PRIORITY);
-		st.start();
-	}
-
-	/**
-	 * @tests java.lang.Thread#sleep(long)
-	 */
-	public void test_sleepJ() {
-		// Test for method void java.lang.Thread.sleep(long)
-
-		// TODO : Test needs enhancing.
-		long stime = 0, ftime = 0;
-		try {
-			stime = System.currentTimeMillis();
-			Thread.sleep(1000);
-			ftime = System.currentTimeMillis();
-		} catch (InterruptedException e) {
-			fail("Unexpected interrupt received");
-		}
-		assertTrue("Failed to sleep long enough", (ftime - stime) >= 800);
-	}
-
-	/**
-	 * @tests java.lang.Thread#sleep(long, int)
-	 */
-	public void test_sleepJI() {
-		// Test for method void java.lang.Thread.sleep(long, int)
-
-		// TODO : Test needs revisiting.
-		long stime = 0, ftime = 0;
-		try {
-			stime = System.currentTimeMillis();
-			Thread.sleep(1000, 999999);
-			ftime = System.currentTimeMillis();
-		} catch (InterruptedException e) {
-			fail("Unexpected interrupt received");
-		}
-		long result = ftime - stime;
-		assertTrue("Failed to sleep long enough: " + result, result >= 900
-				&& result <= 1100);
-	}
-
-	/**
-	 * @tests java.lang.Thread#start()
-	 */
-	public void test_start() {
-		// Test for method void java.lang.Thread.start()
-		try {
-			ResSupThread t = new ResSupThread(Thread.currentThread());
-			synchronized (t) {
-				ct = new Thread(t, "Interrupt Test4");
-				ct.start();
-				t.wait();
-			}
-			assertTrue("Thread is not running1", ct.isAlive());
-			// Let the child thread get going.
-			int orgval = t.getCheckVal();
-			Thread.sleep(150);
-			assertTrue("Thread is not running2", orgval != t.getCheckVal());
-			ct.interrupt();
-		} catch (InterruptedException e) {
-			fail("Unexpected interrupt occurred");
-		}
-	}
-
-	/**
-	 * @tests java.lang.Thread#stop()
-	 */
-	@SuppressWarnings("deprecation")
-    public void test_stop() {
-		// Test for method void java.lang.Thread.stop()
-		try {
-			Runnable r = new ResSupThread(null);
-			synchronized (r) {
-				st = new Thread(r, "Interupt Test5");
-				st.start();
-				r.wait();
-			}
-
-		} catch (InterruptedException e) {
-			fail("Unexpected interrupt received");
-		}
-		st.stop();
-
-		try {
-			st.join(10000);
-		} catch (InterruptedException e1) {
-			st.interrupt();
-			fail("Failed to stopThread before 10000 timeout");
-		}
-		assertTrue("Failed to stopThread", !st.isAlive());
-	}
-
-	/**
-	 * @tests java.lang.Thread#stop()
-	 */
-	@SuppressWarnings("deprecation")
-    public void test_stop_subtest0() {
-		Thread t = new Thread("t");
-		class MySecurityManager extends SecurityManager {
-			public boolean intest = false;
-
-			@Override
-            public void checkAccess(Thread t) {
-				if (intest) {
-					fail("checkAccess called");
-				}
-			}
-            @Override
-            public void checkPermission(Permission permission) {
-                if (permission.getName().equals("setSecurityManager")) {
-                    return;
-                }
-                super.checkPermission(permission);
-            }
-		}
-		MySecurityManager sm = new MySecurityManager();
-		System.setSecurityManager(sm);
-		try {
-			sm.intest = true;
-			try {
-				t.stop();
-				// Ignore any SecurityExceptions, may not have stopThread
-				// permission
-			} catch (SecurityException e) {
-			}
-			sm.intest = false;
-			t.start();
-			try {
-				t.join(2000);
-			} catch (InterruptedException e) {
-			}
-			sm.intest = true;
-			try {
-				t.stop();
-				// Ignore any SecurityExceptions, may not have stopThread
-				// permission
-			} catch (SecurityException e) {
-			}
-			sm.intest = false;
-		} finally {
-			System.setSecurityManager(null);
-		}
-	}
-
-	/**
-	 * @tests java.lang.Thread#stop(java.lang.Throwable)
-	 */
-	@SuppressWarnings("deprecation")
-    public void test_stopLjava_lang_Throwable_subtest0() {
-		Thread t = new Thread("t");
-		class MySecurityManager extends SecurityManager {
-			public boolean intest = false;
-
-			public boolean checkAccess = false;
-
-			@Override
-            public void checkAccess(Thread t) {
-				if (intest) {
-					checkAccess = true;
-				}
-			}
-            @Override
-            public void checkPermission(Permission permission) {
-                if (permission.getName().equals("setSecurityManager")) {
-                    return;
-                }
-                super.checkPermission(permission);
-            }
-		}
-		MySecurityManager sm = new MySecurityManager();
-		System.setSecurityManager(sm);
-		try {
-			sm.intest = true;
-			try {
-				t.stop(new ThreadDeath());
-				// Ignore any SecurityExceptions, may not have stopThread
-				// permission
-			} catch (SecurityException e) {
-			}
-			sm.intest = false;
-			assertTrue("no checkAccess 1", sm.checkAccess);
-			t.start();
-			try {
-				t.join(2000);
-			} catch (InterruptedException e) {
-			}
-			sm.intest = true;
-			sm.checkAccess = false;
-			try {
-				t.stop(new ThreadDeath());
-				// Ignore any SecurityExceptions, may not have stopThread
-				// permission
-			} catch (SecurityException e) {
-			}
-			assertTrue("no checkAccess 2", sm.checkAccess);
-			sm.intest = false;
-		} finally {
-			System.setSecurityManager(null);
-		}
-	}
-
-	/**
-	 * @tests java.lang.Thread#stop(java.lang.Throwable)
-	 */
-	@SuppressWarnings("deprecation")
-    public void test_stopLjava_lang_Throwable() {
-		// Test for method void java.lang.Thread.stop(java.lang.Throwable)
-		ResSupThread t = new ResSupThread(Thread.currentThread());
-		synchronized (t) {
-			st = new Thread(t, "StopThread");
-			st.setPriority(Thread.MAX_PRIORITY);
-			st.start();
-			try {
-				t.wait();
-			} catch (InterruptedException e) {
-			}
-		}
-		try {
-			st.stop(new BogusException("Bogus"));
-			Thread.sleep(20000);
-		} catch (InterruptedException e) {
-			assertTrue("Stopped child with exception not alive", st.isAlive());
-			st.interrupt();
-			return;
-		}
-		st.interrupt();
-		fail("Stopped child did not throw exception");
-	}
-
-	/**
-	 * @tests java.lang.Thread#suspend()
-	 */
-	@SuppressWarnings("deprecation")
-    public void test_suspend() {
-		// Test for method void java.lang.Thread.suspend()
-		int orgval;
-		ResSupThread t = new ResSupThread(Thread.currentThread());
-		try {
-			synchronized (t) {
-				ct = new Thread(t, "Interupt Test6");
-				ct.start();
-				t.wait();
-			}
-			ct.suspend();
-			// Wait to be sure the suspend has occurred
-			Thread.sleep(500);
-			orgval = t.getCheckVal();
-			// Wait to be sure the thread is suspended
-			Thread.sleep(500);
-			assertTrue("Failed to suspend thread", orgval == t.getCheckVal());
-			ct.resume();
-			// Wait to be sure the resume has occurred.
-			Thread.sleep(500);
-			assertTrue("Failed to resume thread", orgval != t.getCheckVal());
-			ct.interrupt();
-		} catch (InterruptedException e) {
-			fail("Unexpected interrupt occurred");
-		}
-
-		final Object notify = new Object();
-		Thread t1 = new Thread(new Runnable() {
-			public void run() {
-				synchronized (notify) {
-					notify.notify();
-				}
-				Thread.currentThread().suspend();
-			}
-		});
-		try {
-			synchronized (notify) {
-				t1.start();
-				notify.wait();
-			}
-			// wait for Thread to suspend
-			Thread.sleep(500);
-			assertTrue("Thread should be alive", t1.isAlive());
-			t1.resume();
-			t1.join();
-		} catch (InterruptedException e) {
-		}
-	}
-
-	/**
-	 * @tests java.lang.Thread#toString()
-	 */
-	public void test_toString() {
-		// Test for method java.lang.String java.lang.Thread.toString()
-		ThreadGroup tg = new ThreadGroup("Test Group5");
-		st = new Thread(tg, new SimpleThread(1), "SimpleThread17");
-		final String stString = st.toString();
-		final String expected = "Thread[SimpleThread17,5,Test Group5]";
-		assertTrue("Returned incorrect string: " + stString + "\t(expecting :"
-				+ expected + ")", stString.equals(expected));
-		st.start();
-		try {
-			st.join();
-		} catch (InterruptedException e) {
-		}
-		tg.destroy();
-	}
-    
-    /**
-     * @tests java.lang.Thread#getAllStackTraces()
-     */
-    public void test_getAllStackTraces() {
-        Map<Thread, StackTraceElement[]> stMap = Thread.getAllStackTraces();
-        assertNotNull(stMap);
-        //TODO add security-based tests
-    }
-    
-    /**
-     * @tests java.lang.Thread#getDefaultUncaughtExceptionHandler
-     * @tests java.lang.Thread#setDefaultUncaughtExceptionHandler
-     */
-    public void test_get_setDefaultUncaughtExceptionHandler() {
-        class Handler implements UncaughtExceptionHandler {
-            public void uncaughtException(Thread thread, Throwable ex) {
-            }
-        }
-        
-        final Handler handler = new Handler();
-        Thread.setDefaultUncaughtExceptionHandler(handler);
-        assertSame(handler, Thread.getDefaultUncaughtExceptionHandler());
-        
-        Thread.setDefaultUncaughtExceptionHandler(null);
-        assertNull(Thread.getDefaultUncaughtExceptionHandler());
-        //TODO add security-based tests
-    }
-    
-    /**
-     * @tests java.lang.Thread#getStackTrace()
-     */
-    public void test_getStackTrace() {
-        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
-        
-        assertNotNull(stackTrace);
-
-        stack_trace_loop: {
-            for (int i = 0; i < stackTrace.length; i++) {
-                StackTraceElement e = stackTrace[i];
-                if (getClass().getName().equals(e.getClassName())) {
-                    if ("test_getStackTrace".equals(e.getMethodName())) {
-                        break stack_trace_loop;
-                    }
-                }
-            }
-            fail("class and method not found in stack trace");
-        }
-        
-        //TODO add security-based tests
-    }
-    
-    /**
-     * @tests java.lang.Thread#getState()
-     */
-    public void test_getState() {
-        Thread.State state = Thread.currentThread().getState();
-        assertNotNull(state);
-        assertEquals(Thread.State.RUNNABLE, state);
-        //TODO add additional state tests
-    }
-    
-    /**
-     * @tests java.lang.Thread#getUncaughtExceptionHandler
-     * @tests java.lang.Thread#setUncaughtExceptionHandler
-     */
-    public void test_get_setUncaughtExceptionHandler() {
-        class Handler implements UncaughtExceptionHandler {
-            public void uncaughtException(Thread thread, Throwable ex) {
-            }
-        }
-        
-        final Handler handler = new Handler();
-        Thread.currentThread().setUncaughtExceptionHandler(handler);
-        assertSame(handler, Thread.currentThread().getUncaughtExceptionHandler());
-        
-        Thread.currentThread().setUncaughtExceptionHandler(null);
-
-        //TODO add security-based tests
-    }
-    
-    /**
-     * @tests java.lang.Thread#getId()
-     */
-    public void test_getId() {
-        assertTrue("current thread's ID is not positive", Thread.currentThread().getId() > 0);
-        
-        //check all the current threads for positive IDs
-        Map<Thread, StackTraceElement[]> stMap = Thread.getAllStackTraces();
-        for (Thread thread : stMap.keySet()) {
-            assertTrue("thread's ID is not positive: " + thread.getName(), thread.getId() > 0);
-        }
-    }
-
-
-	@Override
-    protected void tearDown() {
-		try {
-			if (st != null)
-				st.interrupt();
-		} catch (Exception e) {
-		}
-		try {
-			if (spinner != null)
-				spinner.interrupt();
-		} catch (Exception e) {
-		}
-		try {
-			if (ct != null)
-				ct.interrupt();
-		} catch (Exception e) {
-		}
-
-		try {
-			spinner = null;
-			st = null;
-			ct = null;
-			System.runFinalization();
-		} catch (Exception e) {
-		}
-	}
-}
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.luni.tests.java.lang;
+
+import java.lang.Thread.UncaughtExceptionHandler;
+import java.security.Permission;
+import java.util.Map;
+
+public class ThreadTest extends junit.framework.TestCase {
+
+	static class SimpleThread implements Runnable {
+		int delay;
+
+		public void run() {
+			try {
+				synchronized (this) {
+					this.notify();
+					this.wait(delay);
+				}
+			} catch (InterruptedException e) {
+				return;
+			}
+
+		}
+
+		public SimpleThread(int d) {
+			if (d >= 0)
+				delay = d;
+		}
+	}
+
+	static class YieldThread implements Runnable {
+		volatile int delay;
+
+		public void run() {
+			int x = 0;
+			while (true) {
+				++x;
+			}
+		}
+
+		public YieldThread(int d) {
+			if (d >= 0)
+				delay = d;
+		}
+	}
+
+	static class ResSupThread implements Runnable {
+		Thread parent;
+
+		volatile int checkVal = -1;
+
+		public void run() {
+			try {
+				synchronized (this) {
+					this.notify();
+				}
+				while (true) {
+					checkVal++;
+					zz();
+					Thread.sleep(100);
+				}
+			} catch (InterruptedException e) {
+				return;
+			} catch (BogusException e) {
+				try {
+					// Give parent a chance to sleep
+					Thread.sleep(500);
+				} catch (InterruptedException x) {
+				}
+				parent.interrupt();
+				while (!Thread.currentThread().isInterrupted()) {
+					// Don't hog the CPU
+					try {
+						Thread.sleep(50);
+					} catch (InterruptedException x) {
+						// This is what we've been waiting for...don't throw it
+						// away!
+						break;
+					}
+				}
+			}
+		}
+
+		public void zz() throws BogusException {
+		}
+
+		public ResSupThread(Thread t) {
+			parent = t;
+		}
+
+		public synchronized int getCheckVal() {
+			return checkVal;
+		}
+	}
+
+	static class BogusException extends Throwable {
+
+        private static final long serialVersionUID = 1L;
+
+        public BogusException(String s) {
+			super(s);
+		}
+	}
+
+	Thread st, ct, spinner;
+
+	static boolean calledMySecurityManager = false;
+
+	/**
+	 * @tests java.lang.Thread#Thread()
+	 */
+	public void test_Constructor() {
+		// Test for method java.lang.Thread()
+
+		Thread t;
+		SecurityManager m = new SecurityManager() {
+			@Override
+            public ThreadGroup getThreadGroup() {
+				calledMySecurityManager = true;
+				return Thread.currentThread().getThreadGroup();
+			}
+            
+            @Override
+            public void checkPermission(Permission permission) {
+                if (permission.getName().equals("setSecurityManager")) {
+                    return;
+                }
+                super.checkPermission(permission);
+            }
+		};
+		try {
+			// To see if it checks Thread creation with our SecurityManager
+			System.setSecurityManager(m);
+			t = new Thread();
+		} finally {
+			// restore original, no side-effects
+			System.setSecurityManager(null);
+		}
+		assertTrue("Did not call SecurityManager.getThreadGroup ()",
+				calledMySecurityManager);
+		t.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#Thread(java.lang.Runnable)
+	 */
+	public void test_ConstructorLjava_lang_Runnable() {
+		// Test for method java.lang.Thread(java.lang.Runnable)
+		try {
+			ct = new Thread(new SimpleThread(10));
+			ct.start();
+		} catch (Exception e) {
+			fail("Failed to create subthread : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.lang.Thread#Thread(java.lang.Runnable, java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_RunnableLjava_lang_String() {
+		// Test for method java.lang.Thread(java.lang.Runnable,
+		// java.lang.String)
+		Thread st1 = new Thread(new SimpleThread(1), "SimpleThread1");
+		assertEquals("Constructed thread with incorrect thread name", "SimpleThread1", st1
+				.getName());
+		st1.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#Thread(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method java.lang.Thread(java.lang.String)
+		Thread t = new Thread("Testing");
+		assertEquals("Created tread with incorrect name", 
+				"Testing", t.getName());
+		t.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#Thread(java.lang.ThreadGroup, java.lang.Runnable)
+	 */
+	public void test_ConstructorLjava_lang_ThreadGroupLjava_lang_Runnable() {
+		// Test for method java.lang.Thread(java.lang.ThreadGroup,
+		// java.lang.Runnable)
+		ThreadGroup tg = new ThreadGroup("Test Group1");
+		st = new Thread(tg, new SimpleThread(1), "SimpleThread2");
+		assertTrue("Returned incorrect thread group", st.getThreadGroup() == tg);
+		st.start();
+		try {
+			st.join();
+		} catch (InterruptedException e) {
+		}
+		tg.destroy();
+	}
+
+	/**
+	 * @tests java.lang.Thread#Thread(java.lang.ThreadGroup, java.lang.Runnable,
+	 *        java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_ThreadGroupLjava_lang_RunnableLjava_lang_String() {
+		// Test for method java.lang.Thread(java.lang.ThreadGroup,
+		// java.lang.Runnable, java.lang.String)
+		ThreadGroup tg = new ThreadGroup("Test Group2");
+		st = new Thread(tg, new SimpleThread(1), "SimpleThread3");
+		assertTrue("Constructed incorrect thread", (st.getThreadGroup() == tg)
+				&& st.getName().equals("SimpleThread3"));
+		st.start();
+		try {
+			st.join();
+		} catch (InterruptedException e) {
+		}
+		tg.destroy();
+
+		Runnable r = new Runnable() {
+			public void run() {
+			}
+		};
+
+		ThreadGroup foo = null;
+		try {
+			new Thread(foo = new ThreadGroup("foo"), r, null);
+			// Should not get here
+			fail("Null cannot be accepted as Thread name");
+		} catch (NullPointerException npe) {
+			assertTrue("Null cannot be accepted as Thread name", true);
+			foo.destroy();
+		}
+
+	}
+
+	/**
+	 * @tests java.lang.Thread#Thread(java.lang.ThreadGroup, java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_ThreadGroupLjava_lang_String() {
+		// Test for method java.lang.Thread(java.lang.ThreadGroup,
+		// java.lang.String)
+		st = new Thread(new SimpleThread(1), "SimpleThread4");
+		assertEquals("Returned incorrect thread name", 
+				"SimpleThread4", st.getName());
+		st.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#activeCount()
+	 */
+	public void test_activeCount() {
+		// Test for method int java.lang.Thread.activeCount()
+		Thread t = new Thread(new SimpleThread(1));
+		int active = Thread.activeCount();
+		assertTrue("Incorrect read made: " + active, active > 0);
+		t.start();
+		try {
+			t.join();
+		} catch (InterruptedException e) {
+		}
+	}
+
+	/**
+	 * @tests java.lang.Thread#checkAccess()
+	 */
+	public void test_checkAccess() {
+		// Test for method void java.lang.Thread.checkAccess()
+		ThreadGroup tg = new ThreadGroup("Test Group3");
+		try {
+			st = new Thread(tg, new SimpleThread(1), "SimpleThread5");
+			st.checkAccess();
+			assertTrue("CheckAccess passed", true);
+		} catch (SecurityException e) {
+			fail("CheckAccess failed : " + e.getMessage());
+		}
+		st.start();
+		try {
+			st.join();
+		} catch (InterruptedException e) {
+		}
+		tg.destroy();
+	}
+
+	/**
+     * @tests java.lang.Thread#countStackFrames()
+     */
+    @SuppressWarnings("deprecation")
+    public void test_countStackFrames() {
+        /*
+         * Thread.countStackFrames() is unpredictable, so we just test that it
+         * doesn't throw an exception.
+         */
+        try {
+            Thread.currentThread().countStackFrames();
+        } catch (Throwable t) {
+            fail("unexpected throwable: " + t.toString());
+        }
+    }
+
+	/**
+	 * @tests java.lang.Thread#currentThread()
+	 */
+	public void test_currentThread() {
+	    assertNotNull(Thread.currentThread());
+	}
+
+	/**
+	 * @tests java.lang.Thread#destroy()
+	 */
+	@SuppressWarnings("deprecation")
+    public void test_destroy() {
+	    try {
+	        new Thread().destroy();
+            // FIXME uncomment when IBM VME is updated
+            //fail("NoSuchMethodError was not thrown");
+        } catch (NoSuchMethodError e) {
+        }
+	}
+
+	/**
+	 * @tests java.lang.Thread#enumerate(java.lang.Thread[])
+	 */
+	public void test_enumerate$Ljava_lang_Thread() {
+		// Test for method int java.lang.Thread.enumerate(java.lang.Thread [])
+		Thread[] tarray = new Thread[10];
+		int initialCount = Thread.enumerate(tarray);
+		ThreadGroup mytg = new ThreadGroup("jp");
+		SimpleThread st1 = new SimpleThread(-1);
+		SimpleThread st2 = new SimpleThread(-1);
+		Thread firstOne = new Thread(mytg, st1, "firstOne2");
+		Thread secondOne = new Thread(mytg, st2, "secondOne1");
+		assertTrue("Incorrect value returned1",
+				Thread.enumerate(tarray) == initialCount);
+		synchronized (st1) {
+			firstOne.start();
+			try {
+				st1.wait();
+			} catch (InterruptedException e) {
+			}
+		}
+		assertTrue("Incorrect value returned2",
+				Thread.enumerate(tarray) == (initialCount + 1));
+
+		synchronized (st2) {
+			secondOne.start();
+			try {
+				st2.wait();
+			} catch (InterruptedException e) {
+			}
+		}
+		assertTrue("Incorrect value returned3",
+				Thread.enumerate(tarray) == (initialCount + 2));
+
+		synchronized (st1) {
+			firstOne.interrupt();
+		}
+		synchronized (st2) {
+			secondOne.interrupt();
+		}
+		try {
+			firstOne.join();
+			secondOne.join();
+		} catch (InterruptedException e) {
+		}
+		mytg.destroy();
+	}
+
+	/**
+	 * @tests java.lang.Thread#getContextClassLoader()
+	 */
+	public void test_getContextClassLoader() {
+		// Test for method java.lang.ClassLoader
+		// java.lang.Thread.getContextClassLoader()
+		Thread t = new Thread();
+		assertTrue("Incorrect class loader returned",
+				t.getContextClassLoader() == Thread.currentThread()
+						.getContextClassLoader());
+		t.start();
+
+	}
+
+	/**
+	 * @tests java.lang.Thread#getName()
+	 */
+	public void test_getName() {
+		// Test for method java.lang.String java.lang.Thread.getName()
+		st = new Thread(new SimpleThread(1), "SimpleThread6");
+		assertEquals("Returned incorrect thread name", 
+				"SimpleThread6", st.getName());
+		st.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#getPriority()
+	 */
+	public void test_getPriority() {
+		// Test for method int java.lang.Thread.getPriority()
+		st = new Thread(new SimpleThread(1));
+		st.setPriority(Thread.MAX_PRIORITY);
+		assertTrue("Returned incorrect thread priority",
+				st.getPriority() == Thread.MAX_PRIORITY);
+		st.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#getThreadGroup()
+	 */
+	public void test_getThreadGroup() {
+		// Test for method java.lang.ThreadGroup
+		// java.lang.Thread.getThreadGroup()
+		ThreadGroup tg = new ThreadGroup("Test Group4");
+		st = new Thread(tg, new SimpleThread(1), "SimpleThread8");
+		assertTrue("Returned incorrect thread group", st.getThreadGroup() == tg);
+		st.start();
+		try {
+			st.join();
+		} catch (InterruptedException e) {
+		}
+		assertNull("group should be null", st.getThreadGroup());
+		assertNotNull("toString() should not be null", st.toString());
+		tg.destroy();
+
+		final Object lock = new Object();
+		Thread t = new Thread() {
+			@Override
+            public void run() {
+				synchronized (lock) {
+					lock.notifyAll();
+				}
+			}
+		};
+		synchronized (lock) {
+			t.start();
+			try {
+				lock.wait();
+			} catch (InterruptedException e) {
+			}
+		}
+		int running = 0;
+		while (t.isAlive())
+			running++;
+		ThreadGroup group = t.getThreadGroup();
+		assertNull("ThreadGroup is not null", group);
+	}
+
+	/**
+	 * @tests java.lang.Thread#interrupt()
+	 */
+	public void test_interrupt() {
+		// Test for method void java.lang.Thread.interrupt()
+		final Object lock = new Object();
+		class ChildThread1 extends Thread {
+			Thread parent;
+
+			boolean sync;
+
+			@Override
+            public void run() {
+				if (sync) {
+					synchronized (lock) {
+						lock.notify();
+						try {
+							lock.wait();
+						} catch (InterruptedException e) {
+						}
+					}
+				}
+				parent.interrupt();
+			}
+
+			public ChildThread1(Thread p, String name, boolean sync) {
+				super(name);
+				parent = p;
+				this.sync = sync;
+			}
+		}
+		boolean interrupted = false;
+		try {
+			ct = new ChildThread1(Thread.currentThread(), "Interrupt Test1",
+					false);
+			synchronized (lock) {
+				ct.start();
+				lock.wait();
+			}
+		} catch (InterruptedException e) {
+			interrupted = true;
+		}
+		assertTrue("Failed to Interrupt thread1", interrupted);
+
+		interrupted = false;
+		try {
+			ct = new ChildThread1(Thread.currentThread(), "Interrupt Test2",
+					true);
+			synchronized (lock) {
+				ct.start();
+				lock.wait();
+				lock.notify();
+			}
+			Thread.sleep(20000);
+		} catch (InterruptedException e) {
+			interrupted = true;
+		}
+		assertTrue("Failed to Interrupt thread2", interrupted);
+
+	}
+
+	/**
+	 * @tests java.lang.Thread#interrupted()
+	 */
+	public void test_interrupted() {
+        assertFalse("Interrupted returned true for non-interrupted thread", Thread
+                .interrupted());
+        Thread.currentThread().interrupt();
+        assertTrue("Interrupted returned true for non-interrupted thread", Thread.interrupted());
+        assertFalse("Failed to clear interrupted flag", Thread.interrupted());
+    }
+
+	/**
+	 * @tests java.lang.Thread#isAlive()
+	 */
+	public void test_isAlive() {
+		// Test for method boolean java.lang.Thread.isAlive()
+		SimpleThread simple;
+		st = new Thread(simple = new SimpleThread(500));
+		assertFalse("A thread that wasn't started is alive.", st.isAlive());
+		synchronized (simple) {
+			st.start();
+			try {
+				simple.wait();
+			} catch (InterruptedException e) {
+			}
+		}
+		assertTrue("Started thread returned false", st.isAlive());
+		try {
+			st.join();
+		} catch (InterruptedException e) {
+			fail("Thread did not die");
+		}
+		assertTrue("Stopped thread returned true", !st.isAlive());
+	}
+
+	/**
+	 * @tests java.lang.Thread#isDaemon()
+	 */
+	public void test_isDaemon() {
+		// Test for method boolean java.lang.Thread.isDaemon()
+		st = new Thread(new SimpleThread(1), "SimpleThread10");
+		assertTrue("Non-Daemon thread returned true", !st.isDaemon());
+		st.setDaemon(true);
+		assertTrue("Daemon thread returned false", st.isDaemon());
+		st.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#isInterrupted()
+	 */
+	public void test_isInterrupted() {
+		// Test for method boolean java.lang.Thread.isInterrupted()
+		class SpinThread implements Runnable {
+			public volatile boolean done = false;
+
+			public void run() {
+				while (!Thread.currentThread().isInterrupted())
+					;
+				while (!done)
+					;
+			}
+		}
+
+		SpinThread spin = new SpinThread();
+		spinner = new Thread(spin);
+		spinner.start();
+		Thread.yield();
+		try {
+			assertTrue("Non-Interrupted thread returned true", !spinner
+					.isInterrupted());
+			spinner.interrupt();
+			assertTrue("Interrupted thread returned false", spinner
+					.isInterrupted());
+			spin.done = true;
+		} finally {
+			spinner.interrupt();
+			spin.done = true;
+		}
+	}
+
+	/**
+	 * @tests java.lang.Thread#join()
+	 */
+	public void test_join() {
+		// Test for method void java.lang.Thread.join()
+		SimpleThread simple;
+		try {
+			st = new Thread(simple = new SimpleThread(100));
+			// cause isAlive() to be compiled by the JIT, as it must be called
+			// within 100ms below.
+			assertTrue("Thread is alive", !st.isAlive());
+			synchronized (simple) {
+				st.start();
+				simple.wait();
+			}
+			st.join();
+		} catch (InterruptedException e) {
+			fail("Join failed ");
+		}
+		assertTrue("Joined thread is still alive", !st.isAlive());
+		boolean result = true;
+		Thread th = new Thread("test");
+		try {
+			th.join();
+		} catch (InterruptedException e) {
+			result = false;
+		}
+		assertTrue("Hung joining a non-started thread", result);
+		th.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#join(long)
+	 */
+	public void test_joinJ() {
+		// Test for method void java.lang.Thread.join(long)
+		SimpleThread simple;
+		try {
+			st = new Thread(simple = new SimpleThread(1000), "SimpleThread12");
+			// cause isAlive() to be compiled by the JIT, as it must be called
+			// within 100ms below.
+			assertTrue("Thread is alive", !st.isAlive());
+			synchronized (simple) {
+				st.start();
+				simple.wait();
+			}
+			st.join(10);
+		} catch (InterruptedException e) {
+			fail("Join failed ");
+		}
+		assertTrue("Join failed to timeout", st.isAlive());
+
+		st.interrupt();
+		try {
+			st = new Thread(simple = new SimpleThread(100), "SimpleThread13");
+			synchronized (simple) {
+				st.start();
+				simple.wait();
+			}
+			st.join(1000);
+		} catch (InterruptedException e) {
+			fail("Join failed : " + e.getMessage());
+			return;
+		}
+		assertTrue("Joined thread is still alive", !st.isAlive());
+
+		final Object lock = new Object();
+		final Thread main = Thread.currentThread();
+		Thread killer = new Thread(new Runnable() {
+			public void run() {
+				try {
+					synchronized (lock) {
+						lock.notify();
+					}
+					Thread.sleep(100);
+				} catch (InterruptedException e) {
+					return;
+				}
+				main.interrupt();
+			}
+		});
+		boolean result = true;
+		Thread th = new Thread("test");
+		try {
+			synchronized (lock) {
+				killer.start();
+				lock.wait();
+			}
+			th.join(200);
+		} catch (InterruptedException e) {
+			result = false;
+		}
+		killer.interrupt();
+		assertTrue("Hung joining a non-started thread", result);
+		th.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#join(long, int)
+	 */
+	public void test_joinJI() {
+		// Test for method void java.lang.Thread.join(long, int)
+		SimpleThread simple;
+		try {
+			st = new Thread(simple = new SimpleThread(1000), "Squawk1");
+			assertTrue("Thread is alive", !st.isAlive());
+			synchronized (simple) {
+				st.start();
+				simple.wait();
+			}
+			
+			long firstRead = System.currentTimeMillis();
+			st.join(100, 999999);
+			long secondRead = System.currentTimeMillis();
+			assertTrue("Did not join by appropriate time: " + secondRead + "-"
+					+ firstRead + "=" + (secondRead - firstRead), secondRead
+					- firstRead <= 300);
+			assertTrue("Joined thread is not alive", st.isAlive());
+			st.interrupt();  
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+
+		final Object lock = new Object();
+		final Thread main = Thread.currentThread();
+		Thread killer = new Thread(new Runnable() {
+			public void run() {
+				try {
+					synchronized (lock) {
+						lock.notify();
+					}
+					Thread.sleep(100);
+				} catch (InterruptedException e) {
+					return;
+				}
+				main.interrupt();
+			}
+		});
+		boolean result = true;
+		Thread th = new Thread("test");
+		try {
+			synchronized (lock) {
+				killer.start();
+				lock.wait();
+			}
+			th.join(200, 20);
+		} catch (InterruptedException e) {
+			result = false;
+		}
+		killer.interrupt();
+		assertTrue("Hung joining a non-started thread", result);
+		th.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#resume()
+	 */
+	@SuppressWarnings("deprecation")
+    public void test_resume() {
+		// Test for method void java.lang.Thread.resume()
+		int orgval;
+		ResSupThread t;
+		try {
+			t = new ResSupThread(Thread.currentThread());
+			synchronized (t) {
+				ct = new Thread(t, "Interrupt Test2");
+				ct.start();
+				t.wait();
+			}
+			ct.suspend();
+			// Wait to be sure the suspend has occurred
+			Thread.sleep(500);
+			orgval = t.getCheckVal();
+			// Wait to be sure the thread is suspended
+			Thread.sleep(500);
+			assertTrue("Failed to suspend thread", orgval == t.getCheckVal());
+			ct.resume();
+			// Wait to be sure the resume has occurred.
+			Thread.sleep(500);
+			assertTrue("Failed to resume thread", orgval != t.getCheckVal());
+			ct.interrupt();
+		} catch (InterruptedException e) {
+			fail("Unexpected interrupt occurred : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.lang.Thread#run()
+	 */
+	public void test_run() {
+		// Test for method void java.lang.Thread.run()
+		class RunThread implements Runnable {
+			boolean didThreadRun = false;
+
+			public void run() {
+				didThreadRun = true;
+			}
+		}
+		RunThread rt = new RunThread();
+		Thread t = new Thread(rt);
+		try {
+			t.start();
+			int count = 0;
+			while (!rt.didThreadRun && count < 20) {
+				Thread.sleep(100);
+				count++;
+			}
+			assertTrue("Thread did not run", rt.didThreadRun);
+			t.join();
+		} catch (InterruptedException e) {
+			assertTrue("Joined thread was interrupted", true);
+		}
+		assertTrue("Joined thread is still alive", !t.isAlive());
+	}
+
+	/**
+	 * @tests java.lang.Thread#setDaemon(boolean)
+	 */
+	public void test_setDaemonZ() {
+		// Test for method void java.lang.Thread.setDaemon(boolean)
+		st = new Thread(new SimpleThread(1), "SimpleThread14");
+		st.setDaemon(true);
+		assertTrue("Failed to set thread as daemon thread", st.isDaemon());
+		st.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#setName(java.lang.String)
+	 */
+	public void test_setNameLjava_lang_String() {
+		// Test for method void java.lang.Thread.setName(java.lang.String)
+		st = new Thread(new SimpleThread(1), "SimpleThread15");
+		st.setName("Bogus Name");
+		assertEquals("Failed to set thread name", 
+				"Bogus Name", st.getName());
+		try {
+			st.setName(null);
+			fail("Null should not be accepted as a valid name");
+		} catch (NullPointerException e) {
+			// success
+			assertTrue("Null should not be accepted as a valid name", true);
+		}
+		st.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#setPriority(int)
+	 */
+	public void test_setPriorityI() {
+		// Test for method void java.lang.Thread.setPriority(int)
+		st = new Thread(new SimpleThread(1));
+		st.setPriority(Thread.MAX_PRIORITY);
+		assertTrue("Failed to set priority",
+				st.getPriority() == Thread.MAX_PRIORITY);
+		st.start();
+	}
+
+	/**
+	 * @tests java.lang.Thread#sleep(long)
+	 */
+	public void test_sleepJ() {
+		// Test for method void java.lang.Thread.sleep(long)
+
+		// TODO : Test needs enhancing.
+		long stime = 0, ftime = 0;
+		try {
+			stime = System.currentTimeMillis();
+			Thread.sleep(1000);
+			ftime = System.currentTimeMillis();
+		} catch (InterruptedException e) {
+			fail("Unexpected interrupt received");
+		}
+		assertTrue("Failed to sleep long enough", (ftime - stime) >= 800);
+	}
+
+	/**
+	 * @tests java.lang.Thread#sleep(long, int)
+	 */
+	public void test_sleepJI() {
+		// Test for method void java.lang.Thread.sleep(long, int)
+
+		// TODO : Test needs revisiting.
+		long stime = 0, ftime = 0;
+		try {
+			stime = System.currentTimeMillis();
+			Thread.sleep(1000, 999999);
+			ftime = System.currentTimeMillis();
+		} catch (InterruptedException e) {
+			fail("Unexpected interrupt received");
+		}
+		long result = ftime - stime;
+		assertTrue("Failed to sleep long enough: " + result, result >= 900
+				&& result <= 1100);
+	}
+
+	/**
+	 * @tests java.lang.Thread#start()
+	 */
+	public void test_start() {
+		// Test for method void java.lang.Thread.start()
+		try {
+			ResSupThread t = new ResSupThread(Thread.currentThread());
+			synchronized (t) {
+				ct = new Thread(t, "Interrupt Test4");
+				ct.start();
+				t.wait();
+			}
+			assertTrue("Thread is not running1", ct.isAlive());
+			// Let the child thread get going.
+			int orgval = t.getCheckVal();
+			Thread.sleep(150);
+			assertTrue("Thread is not running2", orgval != t.getCheckVal());
+			ct.interrupt();
+		} catch (InterruptedException e) {
+			fail("Unexpected interrupt occurred");
+		}
+	}
+
+	/**
+	 * @tests java.lang.Thread#stop()
+	 */
+	@SuppressWarnings("deprecation")
+    public void test_stop() {
+		// Test for method void java.lang.Thread.stop()
+		try {
+			Runnable r = new ResSupThread(null);
+			synchronized (r) {
+				st = new Thread(r, "Interupt Test5");
+				st.start();
+				r.wait();
+			}
+
+		} catch (InterruptedException e) {
+			fail("Unexpected interrupt received");
+		}
+		st.stop();
+
+		try {
+			st.join(10000);
+		} catch (InterruptedException e1) {
+			st.interrupt();
+			fail("Failed to stopThread before 10000 timeout");
+		}
+		assertTrue("Failed to stopThread", !st.isAlive());
+	}
+
+	/**
+	 * @tests java.lang.Thread#stop()
+	 */
+	@SuppressWarnings("deprecation")
+    public void test_stop_subtest0() {
+		Thread t = new Thread("t");
+		class MySecurityManager extends SecurityManager {
+			public boolean intest = false;
+
+			@Override
+            public void checkAccess(Thread t) {
+				if (intest) {
+					fail("checkAccess called");
+				}
+			}
+            @Override
+            public void checkPermission(Permission permission) {
+                if (permission.getName().equals("setSecurityManager")) {
+                    return;
+                }
+                super.checkPermission(permission);
+            }
+		}
+		MySecurityManager sm = new MySecurityManager();
+		System.setSecurityManager(sm);
+		try {
+			sm.intest = true;
+			try {
+				t.stop();
+				// Ignore any SecurityExceptions, may not have stopThread
+				// permission
+			} catch (SecurityException e) {
+			}
+			sm.intest = false;
+			t.start();
+			try {
+				t.join(2000);
+			} catch (InterruptedException e) {
+			}
+			sm.intest = true;
+			try {
+				t.stop();
+				// Ignore any SecurityExceptions, may not have stopThread
+				// permission
+			} catch (SecurityException e) {
+			}
+			sm.intest = false;
+		} finally {
+			System.setSecurityManager(null);
+		}
+	}
+
+	/**
+	 * @tests java.lang.Thread#stop(java.lang.Throwable)
+	 */
+	@SuppressWarnings("deprecation")
+    public void test_stopLjava_lang_Throwable_subtest0() {
+		Thread t = new Thread("t");
+		class MySecurityManager extends SecurityManager {
+			public boolean intest = false;
+
+			public boolean checkAccess = false;
+
+			@Override
+            public void checkAccess(Thread t) {
+				if (intest) {
+					checkAccess = true;
+				}
+			}
+            @Override
+            public void checkPermission(Permission permission) {
+                if (permission.getName().equals("setSecurityManager")) {
+                    return;
+                }
+                super.checkPermission(permission);
+            }
+		}
+		MySecurityManager sm = new MySecurityManager();
+		System.setSecurityManager(sm);
+		try {
+			sm.intest = true;
+			try {
+				t.stop(new ThreadDeath());
+				// Ignore any SecurityExceptions, may not have stopThread
+				// permission
+			} catch (SecurityException e) {
+			}
+			sm.intest = false;
+			assertTrue("no checkAccess 1", sm.checkAccess);
+			t.start();
+			try {
+				t.join(2000);
+			} catch (InterruptedException e) {
+			}
+			sm.intest = true;
+			sm.checkAccess = false;
+			try {
+				t.stop(new ThreadDeath());
+				// Ignore any SecurityExceptions, may not have stopThread
+				// permission
+			} catch (SecurityException e) {
+			}
+			assertTrue("no checkAccess 2", sm.checkAccess);
+			sm.intest = false;
+		} finally {
+			System.setSecurityManager(null);
+		}
+	}
+
+	/**
+	 * @tests java.lang.Thread#stop(java.lang.Throwable)
+	 */
+	@SuppressWarnings("deprecation")
+    public void test_stopLjava_lang_Throwable() {
+		// Test for method void java.lang.Thread.stop(java.lang.Throwable)
+		ResSupThread t = new ResSupThread(Thread.currentThread());
+		synchronized (t) {
+			st = new Thread(t, "StopThread");
+			st.setPriority(Thread.MAX_PRIORITY);
+			st.start();
+			try {
+				t.wait();
+			} catch (InterruptedException e) {
+			}
+		}
+		try {
+			st.stop(new BogusException("Bogus"));
+			Thread.sleep(20000);
+		} catch (InterruptedException e) {
+			assertTrue("Stopped child with exception not alive", st.isAlive());
+			st.interrupt();
+			return;
+		}
+		st.interrupt();
+		fail("Stopped child did not throw exception");
+	}
+
+	/**
+	 * @tests java.lang.Thread#suspend()
+	 */
+	@SuppressWarnings("deprecation")
+    public void test_suspend() {
+		// Test for method void java.lang.Thread.suspend()
+		int orgval;
+		ResSupThread t = new ResSupThread(Thread.currentThread());
+		try {
+			synchronized (t) {
+				ct = new Thread(t, "Interupt Test6");
+				ct.start();
+				t.wait();
+			}
+			ct.suspend();
+			// Wait to be sure the suspend has occurred
+			Thread.sleep(500);
+			orgval = t.getCheckVal();
+			// Wait to be sure the thread is suspended
+			Thread.sleep(500);
+			assertTrue("Failed to suspend thread", orgval == t.getCheckVal());
+			ct.resume();
+			// Wait to be sure the resume has occurred.
+			Thread.sleep(500);
+			assertTrue("Failed to resume thread", orgval != t.getCheckVal());
+			ct.interrupt();
+		} catch (InterruptedException e) {
+			fail("Unexpected interrupt occurred");
+		}
+
+		final Object notify = new Object();
+		Thread t1 = new Thread(new Runnable() {
+			public void run() {
+				synchronized (notify) {
+					notify.notify();
+				}
+				Thread.currentThread().suspend();
+			}
+		});
+		try {
+			synchronized (notify) {
+				t1.start();
+				notify.wait();
+			}
+			// wait for Thread to suspend
+			Thread.sleep(500);
+			assertTrue("Thread should be alive", t1.isAlive());
+			t1.resume();
+			t1.join();
+		} catch (InterruptedException e) {
+		}
+	}
+
+	/**
+	 * @tests java.lang.Thread#toString()
+	 */
+	public void test_toString() {
+		// Test for method java.lang.String java.lang.Thread.toString()
+		ThreadGroup tg = new ThreadGroup("Test Group5");
+		st = new Thread(tg, new SimpleThread(1), "SimpleThread17");
+		final String stString = st.toString();
+		final String expected = "Thread[SimpleThread17,5,Test Group5]";
+		assertTrue("Returned incorrect string: " + stString + "\t(expecting :"
+				+ expected + ")", stString.equals(expected));
+		st.start();
+		try {
+			st.join();
+		} catch (InterruptedException e) {
+		}
+		tg.destroy();
+	}
+    
+    /**
+     * @tests java.lang.Thread#getAllStackTraces()
+     */
+    public void test_getAllStackTraces() {
+        Map<Thread, StackTraceElement[]> stMap = Thread.getAllStackTraces();
+        assertNotNull(stMap);
+        //TODO add security-based tests
+    }
+    
+    /**
+     * @tests java.lang.Thread#getDefaultUncaughtExceptionHandler
+     * @tests java.lang.Thread#setDefaultUncaughtExceptionHandler
+     */
+    public void test_get_setDefaultUncaughtExceptionHandler() {
+        class Handler implements UncaughtExceptionHandler {
+            public void uncaughtException(Thread thread, Throwable ex) {
+            }
+        }
+        
+        final Handler handler = new Handler();
+        Thread.setDefaultUncaughtExceptionHandler(handler);
+        assertSame(handler, Thread.getDefaultUncaughtExceptionHandler());
+        
+        Thread.setDefaultUncaughtExceptionHandler(null);
+        assertNull(Thread.getDefaultUncaughtExceptionHandler());
+        //TODO add security-based tests
+    }
+    
+    /**
+     * @tests java.lang.Thread#getStackTrace()
+     */
+    public void test_getStackTrace() {
+        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+        
+        assertNotNull(stackTrace);
+
+        stack_trace_loop: {
+            for (int i = 0; i < stackTrace.length; i++) {
+                StackTraceElement e = stackTrace[i];
+                if (getClass().getName().equals(e.getClassName())) {
+                    if ("test_getStackTrace".equals(e.getMethodName())) {
+                        break stack_trace_loop;
+                    }
+                }
+            }
+            fail("class and method not found in stack trace");
+        }
+        
+        //TODO add security-based tests
+    }
+    
+    /**
+     * @tests java.lang.Thread#getState()
+     */
+    public void test_getState() {
+        Thread.State state = Thread.currentThread().getState();
+        assertNotNull(state);
+        assertEquals(Thread.State.RUNNABLE, state);
+        //TODO add additional state tests
+    }
+    
+    /**
+     * @tests java.lang.Thread#getUncaughtExceptionHandler
+     * @tests java.lang.Thread#setUncaughtExceptionHandler
+     */
+    public void test_get_setUncaughtExceptionHandler() {
+        class Handler implements UncaughtExceptionHandler {
+            public void uncaughtException(Thread thread, Throwable ex) {
+            }
+        }
+        
+        final Handler handler = new Handler();
+        Thread.currentThread().setUncaughtExceptionHandler(handler);
+        assertSame(handler, Thread.currentThread().getUncaughtExceptionHandler());
+        
+        Thread.currentThread().setUncaughtExceptionHandler(null);
+
+        //TODO add security-based tests
+    }
+    
+    /**
+     * @tests java.lang.Thread#getId()
+     */
+    public void test_getId() {
+        assertTrue("current thread's ID is not positive", Thread.currentThread().getId() > 0);
+        
+        //check all the current threads for positive IDs
+        Map<Thread, StackTraceElement[]> stMap = Thread.getAllStackTraces();
+        for (Thread thread : stMap.keySet()) {
+            assertTrue("thread's ID is not positive: " + thread.getName(), thread.getId() > 0);
+        }
+    }
+
+
+	@Override
+    protected void tearDown() {
+		try {
+			if (st != null)
+				st.interrupt();
+		} catch (Exception e) {
+		}
+		try {
+			if (spinner != null)
+				spinner.interrupt();
+		} catch (Exception e) {
+		}
+		try {
+			if (ct != null)
+				ct.interrupt();
+		} catch (Exception e) {
+		}
+
+		try {
+			spinner = null;
+			st = null;
+			ct = null;
+			System.runFinalization();
+		} catch (Exception e) {
+		}
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message