harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r386058 [39/49] - in /incubator/harmony/enhanced/classlib/trunk: make/ modules/archive/make/common/ modules/archive/src/test/java/tests/ modules/archive/src/test/java/tests/api/ modules/archive/src/test/java/tests/api/java/ modules/archive/...
Date Wed, 15 Mar 2006 11:47:39 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/SimpleTimeZoneTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/SimpleTimeZoneTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/SimpleTimeZoneTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/SimpleTimeZoneTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,459 @@
+/* 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 tests.api.java.util;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.SimpleTimeZone;
+import java.util.TimeZone;
+
+public class SimpleTimeZoneTest extends junit.framework.TestCase {
+
+	SimpleTimeZone st1;
+
+	SimpleTimeZone st2;
+
+	/**
+	 * @tests java.util.SimpleTimeZone#SimpleTimeZone(int, java.lang.String)
+	 */
+	public void test_ConstructorILjava_lang_String() {
+		// Test for method java.util.SimpleTimeZone(int, java.lang.String)
+
+		SimpleTimeZone st = new SimpleTimeZone(1000, "TEST");
+		assertTrue("Incorrect TZ constructed", st.getID().equals("TEST"));
+		assertTrue("Incorrect TZ constructed: " + "returned wrong offset", st
+				.getRawOffset() == 1000);
+		assertTrue("Incorrect TZ constructed" + "using daylight savings", !st
+				.useDaylightTime());
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#SimpleTimeZone(int, java.lang.String,
+	 *        int, int, int, int, int, int, int, int)
+	 */
+	public void test_ConstructorILjava_lang_StringIIIIIIII() {
+		// Test for method java.util.SimpleTimeZone(int, java.lang.String, int,
+		// int, int, int, int, int, int, int)
+		SimpleTimeZone st = new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER,
+				1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY,
+				0);
+		assertTrue("Incorrect TZ constructed", st
+				.inDaylightTime(new GregorianCalendar(1998, Calendar.NOVEMBER,
+						13).getTime()));
+		assertTrue("Incorrect TZ constructed", !(st
+				.inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER,
+						13).getTime())));
+		assertTrue("Incorrect TZ constructed", st.getID().equals("TEST"));
+		assertTrue("Incorrect TZ constructed", st.getRawOffset() == 1000);
+		assertTrue("Incorrect TZ constructed", st.useDaylightTime());
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#SimpleTimeZone(int, java.lang.String,
+	 *        int, int, int, int, int, int, int, int, int)
+	 */
+	public void test_ConstructorILjava_lang_StringIIIIIIIII() {
+		// Test for method java.util.SimpleTimeZone(int, java.lang.String, int,
+		// int, int, int, int, int, int, int, int)
+		SimpleTimeZone st = new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER,
+				1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY,
+				0, 1000 * 60 * 60);
+		assertTrue("Incorrect TZ constructed", st
+				.inDaylightTime(new GregorianCalendar(1998, Calendar.NOVEMBER,
+						13).getTime()));
+		assertTrue("Incorrect TZ constructed", !(st
+				.inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER,
+						13).getTime())));
+		assertTrue("Incorrect TZ constructed", st.getID().equals("TEST"));
+		assertTrue("Incorrect TZ constructed", st.getRawOffset() == 1000);
+		assertTrue("Incorrect TZ constructed", st.useDaylightTime());
+		assertTrue("Incorrect TZ constructed",
+				st.getDSTSavings() == 1000 * 60 * 60);
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#SimpleTimeZone(int, java.lang.String,
+	 *        int, int, int, int, int, int, int, int, int, int, int)
+	 */
+	public void test_ConstructorILjava_lang_StringIIIIIIIIIII() {
+		// Test for method java.util.SimpleTimeZone(int, java.lang.String, int,
+		// int, int, int, int, int, int, int, int, int, int)
+		// TODO : Implement test
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#clone()
+	 */
+	public void test_clone() {
+		// Test for method java.lang.Object java.util.SimpleTimeZone.clone()
+		SimpleTimeZone st1 = new SimpleTimeZone(1000, "TEST",
+				Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER,
+				-1, Calendar.SUNDAY, 0);
+		SimpleTimeZone stA = new SimpleTimeZone(1, "Gah");
+		assertTrue("Clone resulted in same reference", st1.clone() != st1);
+		assertTrue("Clone resulted in unequal object", ((SimpleTimeZone) st1
+				.clone()).equals(st1));
+		assertTrue("Clone resulted in same reference", stA.clone() != stA);
+		assertTrue("Clone resulted in unequal object", ((SimpleTimeZone) stA
+				.clone()).equals(stA));
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#equals(java.lang.Object)
+	 */
+	public void test_equalsLjava_lang_Object() {
+		// Test for method boolean
+		// java.util.SimpleTimeZone.equals(java.lang.Object)
+
+		st1 = new SimpleTimeZone(-5 * 3600000, "EST", Calendar.APRIL, 1,
+				-Calendar.SUNDAY, 2 * 3600000, Calendar.OCTOBER, -1,
+				Calendar.SUNDAY, 2 * 3600000);
+		assertTrue("Equalty test1 failed", TimeZone.getTimeZone("EST").equals(
+				st1));
+		assertTrue("Equalty test2 failed", !(TimeZone.getTimeZone("CST")
+				.equals(st1)));
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#getDSTSavings()
+	 */
+	public void test_getDSTSavings() {
+		// Test for method int java.util.SimpleTimeZone.getDSTSavings()
+		st1 = new SimpleTimeZone(0, "TEST");
+
+		assertTrue("Non-zero default daylight savings",
+				st1.getDSTSavings() == 0);
+		st1.setStartRule(0, 1, 1, 1);
+		st1.setEndRule(11, 1, 1, 1);
+
+		assertTrue("Incorrect default daylight savings",
+				st1.getDSTSavings() == 3600000);
+		st1 = new SimpleTimeZone(-5 * 3600000, "EST", Calendar.APRIL, 1,
+				-Calendar.SUNDAY, 2 * 3600000, Calendar.OCTOBER, -1,
+				Calendar.SUNDAY, 2 * 3600000, 7200000);
+		assertTrue("Incorrect daylight savings from constructor", st1
+				.getDSTSavings() == 7200000);
+
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#getOffset(int, int, int, int, int, int)
+	 */
+	public void test_getOffsetIIIIII() {
+		// Test for method int java.util.SimpleTimeZone.getOffset(int, int, int,
+		// int, int, int)
+		st1 = (SimpleTimeZone) TimeZone.getTimeZone("EST");
+		assertTrue("Incorrect offset returned", st1.getOffset(
+				GregorianCalendar.AD, 1998, Calendar.NOVEMBER, 11,
+				Calendar.WEDNESDAY, 0) == -(5 * 60 * 60 * 1000));
+
+		st1 = (SimpleTimeZone) TimeZone.getTimeZone("EST");
+		assertTrue("Incorrect offset returned", st1.getOffset(
+				GregorianCalendar.AD, 1998, Calendar.JUNE, 11,
+				Calendar.THURSDAY, 0) == -(4 * 60 * 60 * 1000));
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#getRawOffset()
+	 */
+	public void test_getRawOffset() {
+		// Test for method int java.util.SimpleTimeZone.getRawOffset()
+		st1 = (SimpleTimeZone) TimeZone.getTimeZone("EST");
+		assertTrue("Incorrect offset returned",
+				st1.getRawOffset() == -(5 * 60 * 60 * 1000));
+
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#hashCode()
+	 */
+	public void test_hashCode() {
+		// Test for method int java.util.SimpleTimeZone.hashCode()
+		// For lack of a better test.
+		st1 = new SimpleTimeZone(-5 * 3600000, "EST", Calendar.APRIL, 1,
+				-Calendar.SUNDAY, 2 * 3600000, Calendar.OCTOBER, -1,
+				Calendar.SUNDAY, 2 * 3600000);
+		assertTrue("Returned different hashcodes", TimeZone.getTimeZone("EST")
+				.hashCode() == st1.hashCode());
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#hasSameRules(java.util.TimeZone)
+	 */
+	public void test_hasSameRulesLjava_util_TimeZone() {
+		// Test for method boolean
+		// java.util.SimpleTimeZone.hasSameRules(java.util.TimeZone)
+		SimpleTimeZone st = new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER,
+				1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY,
+				0);
+		SimpleTimeZone sameAsSt = new SimpleTimeZone(1000, "REST",
+				Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER,
+				-1, Calendar.SUNDAY, 0);
+		SimpleTimeZone notSameAsSt = new SimpleTimeZone(1000, "PEST",
+				Calendar.NOVEMBER, 2, Calendar.SUNDAY, 0, Calendar.NOVEMBER,
+				-1, Calendar.SUNDAY, 0);
+		assertTrue("Time zones have same rules but return false", st
+				.hasSameRules(sameAsSt));
+		assertTrue("Time zones have different rules but return true", !st
+				.hasSameRules(notSameAsSt));
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#inDaylightTime(java.util.Date)
+	 */
+	public void test_inDaylightTimeLjava_util_Date() {
+		// Test for method boolean
+		// java.util.SimpleTimeZone.inDaylightTime(java.util.Date)
+		SimpleTimeZone zone = (SimpleTimeZone) TimeZone.getTimeZone("EST");
+		GregorianCalendar gc = new GregorianCalendar(1998, Calendar.JUNE, 11);
+		assertTrue("Returned incorrect daylight value1", zone.inDaylightTime(gc
+				.getTime()));
+		gc = new GregorianCalendar(1998, Calendar.NOVEMBER, 11);
+		assertTrue("Returned incorrect daylight value2", !(zone
+				.inDaylightTime(gc.getTime())));
+		gc = new GregorianCalendar(zone);
+		gc.set(1999, Calendar.APRIL, 4, 1, 59, 59);
+		assertTrue("Returned incorrect daylight value3", !(zone
+				.inDaylightTime(gc.getTime())));
+		Date date = new Date(gc.getTime().getTime() + 1000);
+		assertTrue("Returned incorrect daylight value4", zone
+				.inDaylightTime(date));
+		gc.set(1999, Calendar.OCTOBER, 31, 1, 0, 0);
+		assertTrue("Returned incorrect daylight value5", !(zone
+				.inDaylightTime(gc.getTime())));
+		date = new Date(gc.getTime().getTime() - 1000);
+		assertTrue("Returned incorrect daylight value6", zone
+				.inDaylightTime(date));
+
+		assertTrue("Returned incorrect daylight value7", !zone
+				.inDaylightTime(new Date(891752400000L + 7200000 - 1)));
+		assertTrue("Returned incorrect daylight value8", zone
+				.inDaylightTime(new Date(891752400000L + 7200000)));
+		assertTrue("Returned incorrect daylight value9", zone
+				.inDaylightTime(new Date(909288000000L + 7200000 - 1)));
+		assertTrue("Returned incorrect daylight value10", !zone
+				.inDaylightTime(new Date(909288000000L + 7200000)));
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#setDSTSavings(int)
+	 */
+	public void test_setDSTSavingsI() {
+		// Test for method void java.util.SimpleTimeZone.setDSTSavings(int)
+		SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ");
+		st.setStartRule(0, 1, 1, 1);
+		st.setEndRule(11, 1, 1, 1);
+		st.setDSTSavings(1);
+		assertTrue("Daylight savings amount not set", st.getDSTSavings() == 1);
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#setEndRule(int, int, int)
+	 */
+	public void test_setEndRuleIII() {
+		// Test for method void java.util.SimpleTimeZone.setEndRule(int, int,
+		// int)
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#setEndRule(int, int, int, int)
+	 */
+	public void test_setEndRuleIIII() {
+		// Test for method void java.util.SimpleTimeZone.setEndRule(int, int,
+		// int, int)
+		SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ");
+		// Spec indicates that both end and start must be set or result is
+		// undefined
+		st.setStartRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0);
+		st.setEndRule(Calendar.NOVEMBER, -1, Calendar.SUNDAY, 0);
+		assertTrue("StartRule improperly set1", st.useDaylightTime());
+		assertTrue("StartRule improperly set2", st
+				.inDaylightTime(new GregorianCalendar(1998, Calendar.NOVEMBER,
+						13).getTime()));
+		assertTrue("StartRule improperly set3", !(st
+				.inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER,
+						13).getTime())));
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#setEndRule(int, int, int, int, boolean)
+	 */
+	public void test_setEndRuleIIIIZ() {
+		// Test for method void java.util.SimpleTimeZone.setEndRule(int, int,
+		// int, int, boolean)
+		SimpleTimeZone st = (SimpleTimeZone) TimeZone.getDefault().clone();
+		// Spec indicates that both end and start must be set or result is
+		// undefined
+		st.setStartRule(Calendar.NOVEMBER, 8, Calendar.SUNDAY, 1, false);
+		st.setEndRule(Calendar.NOVEMBER, 15, Calendar.SUNDAY, 1, true);
+		assertTrue("StartRule improperly set1", st.useDaylightTime());
+		assertTrue("StartRule improperly set2", st
+				.inDaylightTime((new GregorianCalendar(1999, Calendar.NOVEMBER,
+						7, 12, 0).getTime())));
+		assertTrue("StartRule improperly set3", st
+				.inDaylightTime((new GregorianCalendar(1999, Calendar.NOVEMBER,
+						20, 12, 0).getTime())));
+		assertTrue("StartRule improperly set4", !(st
+				.inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER,
+						6, 12, 0).getTime())));
+		assertTrue("StartRule improperly set5", !(st
+				.inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER,
+						21, 12, 0).getTime())));
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#setRawOffset(int)
+	 */
+	public void test_setRawOffsetI() {
+		// Test for method void java.util.SimpleTimeZone.setRawOffset(int)
+
+		st1 = (SimpleTimeZone) TimeZone.getTimeZone("EST");
+		int off = st1.getRawOffset();
+		st1.setRawOffset(1000);
+		boolean val = st1.getRawOffset() == 1000;
+		st1.setRawOffset(off);
+		assertTrue("Incorrect offset set", val);
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#setStartRule(int, int, int)
+	 */
+	public void test_setStartRuleIII() {
+		// Test for method void java.util.SimpleTimeZone.setStartRule(int, int,
+		// int)
+		SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ");
+		// Spec indicates that both end and start must be set or result is
+		// undefined
+		st.setStartRule(Calendar.NOVEMBER, 1, 1);
+		st.setEndRule(Calendar.DECEMBER, 1, 1);
+		assertTrue("StartRule improperly set", st.useDaylightTime());
+		assertTrue("StartRule improperly set", st
+				.inDaylightTime((new GregorianCalendar(1998, Calendar.NOVEMBER,
+						13).getTime())));
+		assertTrue("StartRule improperly set", !(st
+				.inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER,
+						13).getTime())));
+
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#setStartRule(int, int, int, int)
+	 */
+	public void test_setStartRuleIIII() {
+		// Test for method void java.util.SimpleTimeZone.setStartRule(int, int,
+		// int, int)
+		SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ");
+		// Spec indicates that both end and start must be set or result is
+		// undefined
+		st.setStartRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0);
+		st.setEndRule(Calendar.NOVEMBER, -1, Calendar.SUNDAY, 0);
+		assertTrue("StartRule improperly set1", st.useDaylightTime());
+		assertTrue("StartRule improperly set2", st
+				.inDaylightTime((new GregorianCalendar(1998, Calendar.NOVEMBER,
+						13).getTime())));
+		assertTrue("StartRule improperly set3", !(st
+				.inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER,
+						13).getTime())));
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#setStartRule(int, int, int, int, boolean)
+	 */
+	public void test_setStartRuleIIIIZ() {
+		// Test for method void java.util.SimpleTimeZone.setStartRule(int, int,
+		// int, int, boolean)
+		SimpleTimeZone st = (SimpleTimeZone) TimeZone.getDefault().clone();
+		// Spec indicates that both end and start must be set or result is
+		// undefined
+		st.setStartRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 1, true);
+		st.setEndRule(Calendar.NOVEMBER, 15, Calendar.SUNDAY, 1, false);
+		assertTrue("StartRule improperly set1", st.useDaylightTime());
+		assertTrue("StartRule improperly set2", st
+				.inDaylightTime((new GregorianCalendar(1999, Calendar.NOVEMBER,
+						7, 12, 0).getTime())));
+		assertTrue("StartRule improperly set3", st
+				.inDaylightTime((new GregorianCalendar(1999, Calendar.NOVEMBER,
+						13, 12, 0).getTime())));
+		assertTrue("StartRule improperly set4", !(st
+				.inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER,
+						6, 12, 0).getTime())));
+		assertTrue("StartRule improperly set5", !(st
+				.inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER,
+						14, 12, 0).getTime())));
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#setStartYear(int)
+	 */
+	public void test_setStartYearI() {
+		// Test for method void java.util.SimpleTimeZone.setStartYear(int)
+		SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ");
+		st.setStartRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0);
+		st.setEndRule(Calendar.NOVEMBER, -1, Calendar.SUNDAY, 0);
+		st.setStartYear(1999);
+		assertTrue("set year improperly set1", !(st
+				.inDaylightTime(new GregorianCalendar(1999, Calendar.JULY, 12)
+						.getTime())));
+		assertTrue("set year improperly set2", !(st
+				.inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER,
+						13).getTime())));
+		assertTrue("set year improperly set3", (st
+				.inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER,
+						13).getTime())));
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#toString()
+	 */
+	public void test_toString() {
+		// Test for method java.lang.String java.util.SimpleTimeZone.toString()
+		String string = TimeZone.getTimeZone("EST").toString();
+		assertTrue("toString() returned null", string != null);
+		assertTrue("toString() is empty", string.length() != 0);
+	}
+
+	/**
+	 * @tests java.util.SimpleTimeZone#useDaylightTime()
+	 */
+	public void test_useDaylightTime() {
+		// Test for method boolean java.util.SimpleTimeZone.useDaylightTime()
+		SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ");
+		assertTrue("useDaylightTime returned incorrect value", !st
+				.useDaylightTime());
+		// Spec indicates that both end and start must be set or result is
+		// undefined
+		st.setStartRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0);
+		st.setEndRule(Calendar.NOVEMBER, -1, Calendar.SUNDAY, 0);
+		assertTrue("useDaylightTime returned incorrect value", st
+				.useDaylightTime());
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/StackTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/StackTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/StackTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/StackTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,175 @@
+/* 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 tests.api.java.util;
+
+import java.util.EmptyStackException;
+import java.util.Stack;
+
+public class StackTest extends junit.framework.TestCase {
+
+	Stack s;
+
+	/**
+	 * @tests java.util.Stack#Stack()
+	 */
+	public void test_Constructor() {
+		// Test for method java.util.Stack()
+		assertTrue("Stack creation failed", s.size() == 0);
+	}
+
+	/**
+	 * @tests java.util.Stack#empty()
+	 */
+	public void test_empty() {
+		// Test for method boolean java.util.Stack.empty()
+		assertTrue("New stack answers non-empty", s.empty());
+		s.push("blah");
+		assertTrue("Stack should not be empty but answers empty", !s.empty());
+		s.pop();
+		assertTrue("Stack should be empty but answers non-empty", s.empty());
+		s.push(null);
+		assertTrue("Stack with null should not be empty but answers empty", !s
+				.empty());
+	}
+
+	/**
+	 * @tests java.util.Stack#peek()
+	 */
+	public void test_peek() {
+		// Test for method java.lang.Object java.util.Stack.peek()
+		String item1 = "Ichi";
+		String item2 = "Ni";
+		String item3 = "San";
+		s.push(item1);
+		assertTrue("Peek did not return top item when it was the only item", s
+				.peek() == item1);
+		s.push(item2);
+		s.push(item3);
+		assertTrue("Peek did not return top item amoung many other items", s
+				.peek() == item3);
+		s.pop();
+		assertTrue("Peek did not return top item after a pop", s.pop() == item2);
+		s.push(null);
+		assertTrue("Peek did not return top item (wanted: null)",
+				s.peek() == null);
+	}
+
+	/**
+	 * @tests java.util.Stack#pop()
+	 */
+	public void test_pop() {
+		// Test for method java.lang.Object java.util.Stack.pop()
+		String item1 = "Ichi";
+		String item2 = "Ni";
+		Object lastPopped;
+		s.push(item1);
+		s.push(item2);
+
+		try {
+			lastPopped = s.pop();
+			assertTrue("a) Pop did not return top item", lastPopped == item2);
+		} catch (EmptyStackException e) {
+			fail(
+					"a) Pop threw EmptyStackException when stack should not have been empty");
+		}
+
+		try {
+			lastPopped = s.pop();
+			assertTrue("b) Pop did not return top item", lastPopped == item1);
+		} catch (EmptyStackException e) {
+			fail(
+					"b) Pop threw EmptyStackException when stack should not have been empty");
+		}
+
+		s.push(null);
+		try {
+			lastPopped = s.pop();
+			assertTrue("c) Pop did not return top item", lastPopped == null);
+		} catch (EmptyStackException e) {
+			fail(
+					"c) Pop threw EmptyStackException when stack should not have been empty");
+		}
+
+		try {
+			lastPopped = s.pop();
+			fail(
+					"d) Pop did not throw EmptyStackException when stack should have been empty");
+		} catch (EmptyStackException e) {
+			return;
+		}
+
+	}
+
+	/**
+	 * @tests java.util.Stack#push(java.lang.Object)
+	 */
+	public void test_pushLjava_lang_Object() {
+		// Test for method java.lang.Object
+		// java.util.Stack.push(java.lang.Object)
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * @tests java.util.Stack#search(java.lang.Object)
+	 */
+	public void test_searchLjava_lang_Object() {
+		// Test for method int java.util.Stack.search(java.lang.Object)
+		String item1 = "Ichi";
+		String item2 = "Ni";
+		String item3 = "San";
+		s.push(item1);
+		s.push(item2);
+		s.push(item3);
+		assertTrue("Search returned incorrect value for equivalent object", s
+				.search(item1) == 3);
+		assertTrue("Search returned incorrect value for equal object", s
+				.search("Ichi") == 3);
+		s.pop();
+		assertTrue(
+				"Search returned incorrect value for equivalent object at top of stack",
+				s.search(item2) == 1);
+		assertTrue(
+				"Search returned incorrect value for equal object at top of stack",
+				s.search("Ni") == 1);
+		s.push(null);
+		assertTrue(
+				"Search returned incorrect value for search for null at top of stack",
+				s.search(null) == 1);
+		s.push("Shi");
+		assertTrue("Search returned incorrect value for search for null", s
+				.search(null) == 2);
+		s.pop();
+		s.pop();
+		assertTrue(
+				"Search returned incorrect value for search for null--wanted -1",
+				s.search(null) == -1);
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+		s = new Stack();
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/StringTokenizerTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/StringTokenizerTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/StringTokenizerTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/StringTokenizerTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,184 @@
+/* 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 tests.api.java.util;
+
+import java.util.NoSuchElementException;
+import java.util.StringTokenizer;
+
+public class StringTokenizerTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.util.StringTokenizer#StringTokenizer(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method java.util.StringTokenizer(java.lang.String)
+		assertTrue("Used in tests", true);
+	}
+
+	/**
+	 * @tests java.util.StringTokenizer#StringTokenizer(java.lang.String,
+	 *        java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_StringLjava_lang_String() {
+		// Test for method java.util.StringTokenizer(java.lang.String,
+		// java.lang.String)
+		StringTokenizer st = new StringTokenizer("This:is:a:test:String", ":");
+		assertTrue("Created incorrect tokenizer", st.countTokens() == 5
+				&& (st.nextElement().equals("This")));
+	}
+
+	/**
+	 * @tests java.util.StringTokenizer#StringTokenizer(java.lang.String,
+	 *        java.lang.String, boolean)
+	 */
+	public void test_ConstructorLjava_lang_StringLjava_lang_StringZ() {
+		// Test for method java.util.StringTokenizer(java.lang.String,
+		// java.lang.String, boolean)
+		StringTokenizer st = new StringTokenizer("This:is:a:test:String", ":",
+				true);
+		st.nextElement();
+		assertTrue("Created incorrect tokenizer", st.countTokens() == 8
+				&& (st.nextElement().equals(":")));
+	}
+
+	/**
+	 * @tests java.util.StringTokenizer#countTokens()
+	 */
+	public void test_countTokens() {
+		// Test for method int java.util.StringTokenizer.countTokens()
+		StringTokenizer st = new StringTokenizer("This is a test String");
+
+		assertTrue("Incorrect token count returned", st.countTokens() == 5);
+	}
+
+	/**
+	 * @tests java.util.StringTokenizer#hasMoreElements()
+	 */
+	public void test_hasMoreElements() {
+		// Test for method boolean java.util.StringTokenizer.hasMoreElements()
+
+		StringTokenizer st = new StringTokenizer("This is a test String");
+		st.nextElement();
+		assertTrue("hasMoreElements returned incorrect value", st
+				.hasMoreElements());
+		st.nextElement();
+		st.nextElement();
+		st.nextElement();
+		st.nextElement();
+		assertTrue("hasMoreElements returned incorrect value", !st
+				.hasMoreElements());
+	}
+
+	/**
+	 * @tests java.util.StringTokenizer#hasMoreTokens()
+	 */
+	public void test_hasMoreTokens() {
+		// Test for method boolean java.util.StringTokenizer.hasMoreTokens()
+		StringTokenizer st = new StringTokenizer("This is a test String");
+		for (int counter = 0; counter < 5; counter++) {
+			assertTrue(
+					"StringTokenizer incorrectly reports it has no more tokens",
+					st.hasMoreTokens());
+			st.nextToken();
+		}
+		assertTrue("StringTokenizer incorrectly reports it has more tokens",
+				!st.hasMoreTokens());
+	}
+
+	/**
+	 * @tests java.util.StringTokenizer#nextElement()
+	 */
+	public void test_nextElement() {
+		// Test for method java.lang.Object
+		// java.util.StringTokenizer.nextElement()
+		StringTokenizer st = new StringTokenizer("This is a test String");
+		assertTrue("nextElement returned incorrect value", ((String) st
+				.nextElement()).equals("This"));
+		assertTrue("nextElement returned incorrect value", ((String) st
+				.nextElement()).equals("is"));
+		assertTrue("nextElement returned incorrect value", ((String) st
+				.nextElement()).equals("a"));
+		assertTrue("nextElement returned incorrect value", ((String) st
+				.nextElement()).equals("test"));
+		assertTrue("nextElement returned incorrect value", ((String) st
+				.nextElement()).equals("String"));
+		try {
+			st.nextElement();
+			fail(
+					"nextElement failed to throw a NoSuchElementException when it should have been out of elements");
+		} catch (NoSuchElementException e) {
+			return;
+		}
+	}
+
+	/**
+	 * @tests java.util.StringTokenizer#nextToken()
+	 */
+	public void test_nextToken() {
+		// Test for method java.lang.String
+		// java.util.StringTokenizer.nextToken()
+		StringTokenizer st = new StringTokenizer("This is a test String");
+		assertTrue("nextToken returned incorrect value", st.nextToken().equals(
+				"This"));
+		assertTrue("nextToken returned incorrect value", st.nextToken().equals(
+				"is"));
+		assertTrue("nextToken returned incorrect value", st.nextToken().equals(
+				"a"));
+		assertTrue("nextToken returned incorrect value", st.nextToken().equals(
+				"test"));
+		assertTrue("nextToken returned incorrect value", st.nextToken().equals(
+				"String"));
+		try {
+			st.nextToken();
+			fail(
+					"nextToken failed to throw a NoSuchElementException when it should have been out of elements");
+		} catch (NoSuchElementException e) {
+			return;
+		}
+	}
+
+	/**
+	 * @tests java.util.StringTokenizer#nextToken(java.lang.String)
+	 */
+	public void test_nextTokenLjava_lang_String() {
+		// Test for method java.lang.String
+		// java.util.StringTokenizer.nextToken(java.lang.String)
+		StringTokenizer st = new StringTokenizer("This is a test String");
+		assertTrue(
+				"nextToken(String) returned incorrect value with normal token String",
+				st.nextToken(" ").equals("This"));
+		assertTrue(
+				"nextToken(String) returned incorrect value with custom token String",
+				st.nextToken("tr").equals(" is a "));
+		assertTrue(
+				"calling nextToken() did not use the new default delimiter list",
+				st.nextToken().equals("es"));
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TimeZoneTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TimeZoneTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TimeZoneTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TimeZoneTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,188 @@
+/* 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 tests.api.java.util;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.SimpleTimeZone;
+import java.util.TimeZone;
+
+import tests.support.Support_TimeZone;
+
+public class TimeZoneTest extends junit.framework.TestCase {
+
+	private static final int ONE_HOUR = 3600000;
+
+	/**
+	 * @tests java.util.TimeZone#getDefault()
+	 */
+	public void test_getDefault() {
+		assertTrue("returns identical", TimeZone.getDefault() != TimeZone
+				.getDefault());
+	}
+
+	/**
+	 * @tests java.util.TimeZone#getDSTSavings()
+	 */
+	public void test_getDSTSavings() {
+		// Test for method int java.util.TimeZone.getDSTSavings()
+
+		// test on subclass SimpleTimeZone
+		TimeZone st1 = TimeZone.getTimeZone("EST");
+		assertEquals("T1A. Incorrect daylight savings returned, ", ONE_HOUR,
+				st1.getDSTSavings());
+
+		// a SimpleTimeZone with daylight savings different then 1 hour
+		st1 = TimeZone.getTimeZone("Australia/Lord_Howe");
+		assertEquals("T1B. Incorrect daylight savings returned, ", 1800000, st1
+				.getDSTSavings());
+
+		// test on subclass Support_TimeZone, an instance with daylight savings
+		TimeZone tz1 = new Support_TimeZone(-5 * ONE_HOUR, true);
+		assertEquals("T2. Incorrect daylight savings returned, ", ONE_HOUR, tz1
+				.getDSTSavings());
+
+		// an instance without daylight savings
+		tz1 = new Support_TimeZone(3 * ONE_HOUR, false);
+		assertEquals("T3. Incorrect daylight savings returned, ", 0, tz1
+				.getDSTSavings());
+	}
+
+	/**
+	 * @tests java.util.TimeZone#getOffset(long)
+	 */
+	public void test_getOffset_long() {
+		// Test for method int java.util.TimeZone.getOffset(long time)
+
+		// test on subclass SimpleTimeZone
+		TimeZone st1 = TimeZone.getTimeZone("EST");
+		long time1 = new GregorianCalendar(1998, Calendar.NOVEMBER, 11)
+				.getTimeInMillis();
+		assertEquals("T1. Incorrect offset returned, ", -(5 * ONE_HOUR), st1
+				.getOffset(time1));
+
+		long time2 = new GregorianCalendar(1998, Calendar.JUNE, 11)
+				.getTimeInMillis();
+		st1 = TimeZone.getTimeZone("EST");
+		assertEquals("T2. Incorrect offset returned, ", -(4 * ONE_HOUR), st1
+				.getOffset(time2));
+
+		// test on subclass Support_TimeZone, an instance with daylight savings
+		TimeZone tz1 = new Support_TimeZone(-5 * ONE_HOUR, true);
+		assertEquals("T3. Incorrect offset returned, ", -(5 * ONE_HOUR), tz1
+				.getOffset(time1));
+		assertEquals("T4. Incorrect offset returned, ", -(4 * ONE_HOUR), tz1
+				.getOffset(time2));
+
+		// an instance without daylight savings
+		tz1 = new Support_TimeZone(3 * ONE_HOUR, false);
+		assertEquals("T5. Incorrect offset returned, ", (3 * ONE_HOUR), tz1
+				.getOffset(time1));
+		assertEquals("T6. Incorrect offset returned, ", (3 * ONE_HOUR), tz1
+				.getOffset(time2));
+	}
+
+	/**
+	 * @tests java.util.TimeZone#getTimeZone(java.lang.String)
+	 */
+	public void test_getTimeZoneLjava_lang_String() {
+		assertEquals(
+				"Must return GMT when given an invalid TimeZone id SMT-8.",
+				TimeZone.getTimeZone("SMT-8").getID(), "GMT");
+		assertEquals(
+				"Must return GMT when given an invalid TimeZone time GMT+28:70.",
+				TimeZone.getTimeZone("GMT+28:70").getID(), "GMT");
+		assertEquals(
+				"Must return GMT when given an invalid TimeZone time GMT+28:30.",
+				TimeZone.getTimeZone("GMT+28:30").getID(), "GMT");
+		assertEquals(
+				"Must return GMT when given an invalid TimeZone time GMT+8:70.",
+				TimeZone.getTimeZone("GMT+8:70").getID(), "GMT");
+		assertEquals(
+				"Must return GMT when given an invalid TimeZone time GMT+3:.",
+				TimeZone.getTimeZone("GMT+3:").getID(), "GMT");
+		assertEquals(
+				"Must return GMT when given an invalid TimeZone time GMT+3:0.",
+				TimeZone.getTimeZone("GMT+3:0").getID(), "GMT");
+		assertEquals(
+				"Must return GMT when given an invalid TimeZone time GMT+2360.",
+				TimeZone.getTimeZone("GMT+2360").getID(), "GMT");
+		assertEquals(
+				"Must return GMT when given an invalid TimeZone time GMT+892.",
+				TimeZone.getTimeZone("GMT+892").getID(), "GMT");
+		assertEquals(
+				"Must return GMT when given an invalid TimeZone time GMT+082.",
+				TimeZone.getTimeZone("GMT+082").getID(), "GMT");
+		assertEquals(
+				"Must return GMT when given an invalid TimeZone time GMT+28.",
+				TimeZone.getTimeZone("GMT+28").getID(), "GMT");
+		assertEquals(
+				"Must return GMT when given an invalid TimeZone time GMT+30.",
+				TimeZone.getTimeZone("GMT+30").getID(), "GMT");
+		assertEquals("Must return GMT when given TimeZone GMT.", TimeZone
+				.getTimeZone("GMT").getID(), "GMT");
+		assertEquals("Must return GMT when given TimeZone GMT+.", TimeZone
+				.getTimeZone("GMT+").getID(), "GMT");
+		assertEquals("Must return GMT when given TimeZone GMT-.", TimeZone
+				.getTimeZone("GMT-").getID(), "GMT");
+		assertEquals(
+				"Must return GMT when given an invalid TimeZone time GMT-8.45.",
+				TimeZone.getTimeZone("GMT-8.45").getID(), "GMT");
+		assertEquals(
+				"Must return GMT when given an invalid TimeZone time GMT-123:23.",
+				TimeZone.getTimeZone("GMT-123:23").getID(), "GMT");
+		assertEquals(
+				"Must return proper GMT formatted string for GMT+8:30 (eg. GMT+08:20).",
+				TimeZone.getTimeZone("GMT+8:30").getID(), "GMT+08:30");
+		assertEquals(
+				"Must return proper GMT formatted string for GMT+3 (eg. GMT+08:20).",
+				TimeZone.getTimeZone("GMT+3").getID(), "GMT+03:00");
+		assertEquals(
+				"Must return proper GMT formatted string for GMT+3:02 (eg. GMT+08:20).",
+				TimeZone.getTimeZone("GMT+3:02").getID(), "GMT+03:02");
+		assertEquals(
+				"Must return proper GMT formatted string for GMT+2359 (eg. GMT+08:20).",
+				TimeZone.getTimeZone("GMT+2359").getID(), "GMT+23:59");
+		assertEquals(
+				"Must return proper GMT formatted string for GMT+520 (eg. GMT+08:20).",
+				TimeZone.getTimeZone("GMT+520").getID(), "GMT+05:20");
+		assertEquals(
+				"Must return proper GMT formatted string for GMT+052 (eg. GMT+08:20).",
+				TimeZone.getTimeZone("GMT+052").getID(), "GMT+00:52");
+		assertEquals(
+				"Must return proper GMT formatted string for GMT-0 (eg. GMT+08:20).",
+				TimeZone.getTimeZone("GMT-0").getID(), "GMT-00:00");
+	}
+
+	/**
+	 * @tests java.util.TimeZone#setDefault(java.util.TimeZone)
+	 */
+	public void test_setDefaultLjava_util_TimeZone() {
+		TimeZone oldDefault = TimeZone.getDefault();
+		TimeZone zone = new SimpleTimeZone(45, "TEST");
+		TimeZone.setDefault(zone);
+		assertTrue("timezone not set", TimeZone.getDefault().equals(zone));
+		TimeZone.setDefault(null);
+		assertTrue("default not restored", TimeZone.getDefault().equals(
+				oldDefault));
+	}
+
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TimerTaskTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TimerTaskTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TimerTaskTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TimerTaskTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,316 @@
+/* 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 tests.api.java.util;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+public class TimerTaskTest extends junit.framework.TestCase {
+	Object sync = new Object(), start = new Object();
+
+	/**
+	 * Warning: These tests have the possibility to leave a VM hanging if the
+	 * Timer is not cancelled.
+	 */
+	class TimerTestTask extends TimerTask {
+		private int wasRun = 0;
+
+		// Set this to true to see normal tests fail (or hang possibly)
+		// The default is false and needs to be set by some tests
+		private boolean sleepInRun = false;
+
+		private boolean cancelCalled = false;
+
+		public void run() {
+			synchronized (this) {
+				wasRun++;
+			}
+			synchronized (start) {
+				start.notify();
+			}
+			if (sleepInRun) {
+				
+				try {
+					Thread.sleep(200);
+				} catch (InterruptedException e) {
+				}
+			}
+			synchronized (sync) {
+				sync.notify();
+			}
+		}
+
+		public synchronized int wasRun() {
+			return wasRun;
+		}
+		
+		public boolean cancel() {
+			this.cancelCalled = true;
+			return super.cancel();
+		}
+
+		public synchronized boolean cancelled() {
+			return cancelCalled;
+		}
+
+		public void sleepInRun(boolean value) {
+			sleepInRun = value;
+		}
+	}
+
+	/**
+	 * @tests java.util.TimerTask#TimerTask()
+	 */
+	public void test_Constructor() {
+		// Ensure the constructor does not fail
+		new TimerTestTask();
+	}
+
+	/**
+	 * @tests java.util.TimerTask#cancel()
+	 */
+	public void test_cancel() {
+		Timer t = null;
+		try {
+			// Ensure cancel returns false if never scheduled
+			TimerTestTask testTask = new TimerTestTask();
+			assertTrue("Unsheduled tasks should return false for cancel()",
+					!testTask.cancel());
+
+			// Ensure cancelled task never runs
+			t = new Timer();
+			testTask = new TimerTestTask();
+			t.schedule(testTask, 500);
+			try {
+				Thread.sleep(100);
+			} catch (InterruptedException e) {
+			}
+			assertTrue("TimerTask should not have run yet", testTask.cancel());
+			try {
+				Thread.sleep(500);
+			} catch (InterruptedException e) {
+			}
+			assertTrue(
+					"TimerTask.run() method should not be called after cancel()",
+					testTask.wasRun() == 0);
+			t.cancel();
+
+			// Ensure cancelling a task which has already run returns true
+			t = new Timer();
+			testTask = new TimerTestTask();
+			t.schedule(testTask, 50);
+			try {
+				Thread.sleep(150);
+			} catch (InterruptedException e) {
+			}
+			assertTrue(
+					"TimerTask.cancel() should return false if task has run",
+					!testTask.cancel());
+			t.cancel();
+
+			// Ensure cancelling a task which is has already run returns true
+			t = new Timer();
+			testTask = new TimerTestTask();
+			t.schedule(testTask, 50);
+			try {
+				Thread.sleep(150);
+			} catch (InterruptedException e) {
+			}
+			assertTrue(
+					"TimerTask.cancel() should return false if task has run",
+					!testTask.cancel());
+			assertTrue(
+					"TimerTask.cancel() should return false if called a second time",
+					!testTask.cancel());
+			t.cancel();
+
+			// Ensure cancelling a repeated execution task which has never run
+			// returns true
+			t = new Timer();
+			testTask = new TimerTestTask();
+			t.schedule(testTask, 500, 500); // should never run
+			try {
+				Thread.sleep(150);
+			} catch (InterruptedException e) {
+			}
+			assertTrue(
+					"TimerTask.cancel() should return true if sheduled for repeated execution even if not run",
+					testTask.cancel());
+			t.cancel();
+
+			// Ensure cancelling a repeated execution task which HAS run returns
+			// true
+			t = new Timer();
+			testTask = new TimerTestTask();
+			t.schedule(testTask, 50, 50); // should run at least two times
+			try {
+				Thread.sleep(300);
+			} catch (InterruptedException e) {
+			}
+			assertTrue(
+					"TimerTask.cancel() should return true if sheduled for repeated execution and run",
+					testTask.cancel());
+			assertTrue("TimerTask should have run at least twice", testTask
+					.wasRun() > 2);
+			int wasRunCount = testTask.wasRun();
+			try {
+				Thread.sleep(200);
+			} catch (InterruptedException e) {
+			}
+			assertTrue("TimerTask cancelled should not run again", testTask
+					.wasRun() == wasRunCount);
+			t.cancel();
+
+			// Ensure calling cancel a second returns false
+			t = new Timer();
+			testTask = new TimerTestTask();
+			t.schedule(testTask, 5000); // Should never run
+			try {
+				Thread.sleep(100);
+			} catch (InterruptedException e) {
+			}
+			assertTrue(
+					"TimerTask.cancel() should return true if task has never run",
+					testTask.cancel());
+			assertTrue(
+					"TimerTask.cancel() should return false if called a second time",
+					!testTask.cancel());
+			t.cancel();
+
+			// Ensure cancelling a task won't cause deadlock
+			t = new Timer();
+			testTask = new TimerTestTask();
+			testTask.sleepInRun(true);
+			synchronized (start) {
+				t.schedule(testTask, 0);
+				try {
+					start.wait();
+					Thread.sleep(50);
+				} catch (InterruptedException e) {
+				}
+			}
+			testTask.cancel();
+			assertTrue("TimerTask should have been cancelled", testTask
+					.cancelled());
+			t.cancel();
+		} finally {
+			if (t != null)
+				t.cancel();
+		}
+	}
+
+	/**
+	 * @tests java.util.TimerTask#scheduledExecutionTime()
+	 */
+	public void test_scheduledExecutionTime() {
+		Timer t = null;
+		try {
+			// Ensure scheduledExecutionTime is roughly right
+			t = new Timer();
+			TimerTestTask testTask = new TimerTestTask();
+			t.schedule(testTask, 100);
+			long time = System.currentTimeMillis() + 100;
+			synchronized (sync) {
+				try {
+					sync.wait(500);
+				} catch (InterruptedException e) {
+				}
+			}
+			long scheduledExecutionTime = testTask.scheduledExecutionTime();
+			assertTrue("scheduledExecutionTime not too accurate "
+					+ scheduledExecutionTime + " vs time " + time,
+					(scheduledExecutionTime > time - 50)
+							&& scheduledExecutionTime <= time);
+			t.cancel();
+
+			// Ensure scheduledExecutionTime is the last scheduled time
+			t = new Timer();
+			testTask = new TimerTestTask();
+			t.schedule(testTask, 100, 500);
+			long estNow = System.currentTimeMillis() + 100;
+			// Will wake in 100, and every 500 run again
+			// We want to try to get it after it's run at least once but not
+			// twice
+			synchronized (sync) {
+				try {
+					sync.wait(500);
+				} catch (InterruptedException e) {
+				}
+			}
+			scheduledExecutionTime = testTask.scheduledExecutionTime();
+			assertTrue("scheduledExecutionTime should be last time it was run",
+					(scheduledExecutionTime > estNow - 50)
+							&& scheduledExecutionTime <= estNow);
+			t.cancel();
+		} finally {
+			if (t != null)
+				t.cancel();
+		}
+
+	}
+
+	/**
+	 * @tests java.util.TimerTask#run()
+	 */
+	public void test_run() {
+		Timer t = null;
+		try {
+			// Ensure a new task is never run
+			TimerTestTask testTask = new TimerTestTask();
+			try {
+				Thread.sleep(200);
+			} catch (InterruptedException e) {
+			}
+			assertTrue("TimerTask.run() method should not have been called",
+					testTask.wasRun() == 0);
+
+			// Ensure a task is run
+			t = new Timer();
+			testTask = new TimerTestTask();
+			t.schedule(testTask, 200);
+			try {
+				Thread.sleep(400);
+			} catch (InterruptedException e) {
+			}
+			assertTrue("TimerTask.run() method not called after 200ms",
+					testTask.wasRun() == 1);
+			t.cancel();
+
+			// Ensure a repeated execution task does just that
+			t = new Timer();
+			testTask = new TimerTestTask();
+			t.schedule(testTask, 50, 50);
+			try {
+				Thread.sleep(400);
+			} catch (InterruptedException e) {
+			}
+			assertTrue(
+					"TimerTask.run() method should have been called at least 4 times",
+					testTask.wasRun() >= 4);
+			t.cancel();
+		} finally {
+			if (t != null)
+				t.cancel();
+		}
+
+	}
+
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TimerTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TimerTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TimerTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TimerTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,1092 @@
+/* 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 tests.api.java.util;
+
+import java.util.Date;
+import java.util.Timer;
+import java.util.TimerTask;
+
+public class TimerTest extends junit.framework.TestCase {
+
+	int timerCounter = 0;
+
+	Object sync = new Object();
+
+	/**
+	 * Warning: These tests have the possibility to leave a VM hanging if the
+	 * Timer is not cancelled.
+	 */
+	class TimerTestTask extends TimerTask {
+		int wasRun = 0;
+
+		// Should we sleep for 200 ms each run()?
+		boolean sleepInRun = false;
+
+		// Should we increment the timerCounter?
+		boolean incrementCount = false;
+
+		// Should we terminate the timer at a specific timerCounter?
+		int terminateCount = -1;
+
+		// The timer we belong to
+		Timer timer = null;
+
+		public TimerTestTask() {
+		}
+
+		public TimerTestTask(Timer t) {
+			timer = t;
+		}
+
+		public void run() {
+			synchronized (this) {
+				wasRun++;
+			}
+			if (incrementCount)
+				timerCounter++;
+			if (terminateCount == timerCounter && timer != null)
+				timer.cancel();
+			if (sleepInRun) {
+				try {
+					Thread.sleep(200);
+				} catch (InterruptedException e) {
+				}
+			}
+			synchronized (sync) {
+				sync.notify();
+			}
+		}
+
+		public synchronized int wasRun() {
+			return wasRun;
+		}
+
+		public void sleepInRun(boolean sleepInRun) {
+			this.sleepInRun = sleepInRun;
+		}
+
+		public void incrementCount(boolean incrementCount) {
+			this.incrementCount = incrementCount;
+		}
+
+		public void terminateCount(int terminateCount) {
+			this.terminateCount = terminateCount;
+		}
+	}
+
+	/**
+	 * @tests java.util.Timer#Timer(boolean)
+	 */
+	public void test_ConstructorZ() {
+		Timer t = null;
+		try {
+			// Ensure a task is run
+			t = new Timer(true);
+			TimerTestTask testTask = new TimerTestTask();
+			t.schedule(testTask, 200);
+			synchronized (sync) {
+				try {
+					sync.wait(1000);
+				} catch (InterruptedException e) {
+				}
+			}
+			assertTrue("TimerTask.run() method not called after 200ms",
+					testTask.wasRun() == 1);
+			t.cancel();
+		} finally {
+			if (t != null)
+				t.cancel();
+		}
+
+	}
+
+	/**
+	 * @tests java.util.Timer#Timer()
+	 */
+	public void test_Constructor() {
+		Timer t = null;
+		try {
+			// Ensure a task is run
+			t = new Timer();
+			TimerTestTask testTask = new TimerTestTask();
+			t.schedule(testTask, 200);
+			synchronized (sync) {
+				try {
+					sync.wait(1000);
+				} catch (InterruptedException e) {
+				}
+			}
+			assertTrue("TimerTask.run() method not called after 200ms",
+					testTask.wasRun() == 1);
+			t.cancel();
+		} finally {
+			if (t != null)
+				t.cancel();
+		}
+
+	}
+
+	/**
+	 * @tests java.util.Timer#cancel()
+	 */
+	public void test_cancel() {
+		Timer t = null;
+		try {
+			// Ensure a task throws an IllegalStateException after cancelled
+			t = new Timer();
+			TimerTestTask testTask = new TimerTestTask();
+			t.cancel();
+			boolean exception = false;
+			try {
+				t.schedule(testTask, 100, 200);
+			} catch (IllegalStateException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a task after Timer.cancel() should throw exception",
+					exception);
+
+			// Ensure a task is run but not after cancel
+			t = new Timer();
+			testTask = new TimerTestTask();
+			t.schedule(testTask, 100, 500);
+			synchronized (sync) {
+				try {
+					sync.wait(1000);
+				} catch (InterruptedException e) {
+				}
+			}
+			assertTrue("TimerTask.run() method not called after 200ms",
+					testTask.wasRun() == 1);
+			t.cancel();
+			synchronized (sync) {
+				try {
+					sync.wait(500);
+				} catch (InterruptedException e) {
+				}
+			}
+			assertTrue(
+					"TimerTask.run() method should not have been called after cancel",
+					testTask.wasRun() == 1);
+
+			// Ensure you can call cancel more than once
+			t = new Timer();
+			testTask = new TimerTestTask();
+			t.schedule(testTask, 100, 500);
+			synchronized (sync) {
+				try {
+					sync.wait(500);
+				} catch (InterruptedException e) {
+				}
+			}
+			assertTrue("TimerTask.run() method not called after 200ms",
+					testTask.wasRun() == 1);
+			t.cancel();
+			t.cancel();
+			t.cancel();
+			synchronized (sync) {
+				try {
+					sync.wait(500);
+				} catch (InterruptedException e) {
+				}
+			}
+			assertTrue(
+					"TimerTask.run() method should not have been called after cancel",
+					testTask.wasRun() == 1);
+
+			// Ensure that a call to cancel from within a timer ensures no more
+			// run
+			t = new Timer();
+			testTask = new TimerTestTask(t);
+			testTask.incrementCount(true);
+			testTask.terminateCount(5); // Terminate after 5 runs
+			t.schedule(testTask, 100, 100);
+			synchronized (sync) {
+				try {
+					sync.wait(200);
+					sync.wait(200);
+					sync.wait(200);
+					sync.wait(200);
+					sync.wait(200);
+					sync.wait(200);
+				} catch (InterruptedException e) {
+				}
+			}
+			assertTrue("TimerTask.run() method should be called 5 times not "
+					+ testTask.wasRun(), testTask.wasRun() == 5);
+			t.cancel();
+			try {
+				Thread.sleep(200);
+			} catch (InterruptedException e) {
+			}
+		} finally {
+			if (t != null)
+				t.cancel();
+		}
+
+	}
+
+	/**
+	 * @tests java.util.Timer#schedule(java.util.TimerTask, java.util.Date)
+	 */
+	public void test_scheduleLjava_util_TimerTaskLjava_util_Date() {
+		Timer t = null;
+		try {
+			// Ensure a Timer throws an IllegalStateException after cancelled
+			t = new Timer();
+			TimerTestTask testTask = new TimerTestTask();
+			Date d = new Date(System.currentTimeMillis() + 100);
+			t.cancel();
+			boolean exception = false;
+			try {
+				t.schedule(testTask, d);
+			} catch (IllegalStateException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a task after Timer.cancel() should throw exception",
+					exception);
+
+			// Ensure a Timer throws an IllegalStateException if task already
+			// cancelled
+			t = new Timer();
+			testTask = new TimerTestTask();
+			d = new Date(System.currentTimeMillis() + 100);
+			testTask.cancel();
+			exception = false;
+			try {
+				t.schedule(testTask, d);
+			} catch (IllegalStateException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a task after cancelling it should throw exception",
+					exception);
+			t.cancel();
+
+			// Ensure a Timer throws an IllegalArgumentException if delay is
+			// negative
+			t = new Timer();
+			testTask = new TimerTestTask();
+			d = new Date(-100);
+			exception = false;
+			try {
+				t.schedule(testTask, d);
+			} catch (IllegalArgumentException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a task with negative date should throw IllegalArgumentException",
+					exception);
+			t.cancel();
+
+			// Ensure a Timer throws a NullPointerException if the task is null
+			t = new Timer();
+			exception = false;
+			d = new Date(System.currentTimeMillis() + 100);
+			try {
+				t.schedule(null, d);
+			} catch (NullPointerException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a null task should throw NullPointerException",
+					exception);
+			t.cancel();
+
+			// Ensure a Timer throws a NullPointerException if the date is null
+			t = new Timer();
+			testTask = new TimerTestTask();
+			exception = false;
+			try {
+				t.schedule(testTask, null);
+			} catch (NullPointerException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a null date should throw NullPointerException",
+					exception);
+			t.cancel();
+
+			// Ensure proper sequence of exceptions
+			t = new Timer();
+			d = new Date(-100);
+			exception = false;
+			try {
+				t.schedule(null, d);
+			} catch (NullPointerException e) {
+			} catch (IllegalArgumentException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a null task with negative date should throw IllegalArgumentException first",
+					exception);
+			t.cancel();
+
+			// Ensure a task is run
+			t = new Timer();
+			testTask = new TimerTestTask();
+			d = new Date(System.currentTimeMillis() + 200);
+			t.schedule(testTask, d);
+			try {
+				Thread.sleep(400);
+			} catch (InterruptedException e) {
+			}
+			assertTrue("TimerTask.run() method not called after 200ms",
+					testTask.wasRun() == 1);
+			t.cancel();
+
+			// Ensure multiple tasks are run
+			t = new Timer();
+			testTask = new TimerTestTask();
+			testTask.incrementCount(true);
+			d = new Date(System.currentTimeMillis() + 100);
+			t.schedule(testTask, d);
+			testTask = new TimerTestTask();
+			testTask.incrementCount(true);
+			d = new Date(System.currentTimeMillis() + 150);
+			t.schedule(testTask, d);
+			testTask = new TimerTestTask();
+			testTask.incrementCount(true);
+			d = new Date(System.currentTimeMillis() + 70);
+			t.schedule(testTask, d);
+			testTask = new TimerTestTask();
+			testTask.incrementCount(true);
+			d = new Date(System.currentTimeMillis() + 10);
+			t.schedule(testTask, d);
+			try {
+				Thread.sleep(400);
+			} catch (InterruptedException e) {
+			}
+			assertTrue(
+					"Multiple tasks should have incremented counter 4 times not "
+							+ timerCounter, timerCounter == 4);
+			t.cancel();
+		} finally {
+			if (t != null)
+				t.cancel();
+		}
+	}
+
+	/**
+	 * @tests java.util.Timer#schedule(java.util.TimerTask, long)
+	 */
+	public void test_scheduleLjava_util_TimerTaskJ() {
+		Timer t = null;
+		try {
+			// Ensure a Timer throws an IllegalStateException after cancelled
+			t = new Timer();
+			TimerTestTask testTask = new TimerTestTask();
+			t.cancel();
+			boolean exception = false;
+			try {
+				t.schedule(testTask, 100);
+			} catch (IllegalStateException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a task after Timer.cancel() should throw exception",
+					exception);
+
+			// Ensure a Timer throws an IllegalStateException if task already
+			// cancelled
+			t = new Timer();
+			testTask = new TimerTestTask();
+			testTask.cancel();
+			exception = false;
+			try {
+				t.schedule(testTask, 100);
+			} catch (IllegalStateException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a task after cancelling it should throw exception",
+					exception);
+			t.cancel();
+
+			// Ensure a Timer throws an IllegalArgumentException if delay is
+			// negative
+			t = new Timer();
+			testTask = new TimerTestTask();
+			exception = false;
+			try {
+				t.schedule(testTask, -100);
+			} catch (IllegalArgumentException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a task with negative delay should throw IllegalArgumentException",
+					exception);
+			t.cancel();
+
+			// Ensure a Timer throws a NullPointerException if the task is null
+			t = new Timer();
+			exception = false;
+			try {
+				t.schedule(null, 10);
+			} catch (NullPointerException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a null task should throw NullPointerException",
+					exception);
+			t.cancel();
+
+			// Ensure proper sequence of exceptions
+			t = new Timer();
+			exception = false;
+			try {
+				t.schedule(null, -10);
+			} catch (NullPointerException e) {
+			} catch (IllegalArgumentException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a null task with negative delays should throw IllegalArgumentException first",
+					exception);
+			t.cancel();
+
+			// Ensure a task is run
+			t = new Timer();
+			testTask = new TimerTestTask();
+			t.schedule(testTask, 200);
+			try {
+				Thread.sleep(400);
+			} catch (InterruptedException e) {
+			}
+			assertTrue("TimerTask.run() method not called after 200ms",
+					testTask.wasRun() == 1);
+			t.cancel();
+
+			// Ensure multiple tasks are run
+			t = new Timer();
+			testTask = new TimerTestTask();
+			testTask.incrementCount(true);
+			t.schedule(testTask, 100);
+			testTask = new TimerTestTask();
+			testTask.incrementCount(true);
+			t.schedule(testTask, 150);
+			testTask = new TimerTestTask();
+			testTask.incrementCount(true);
+			t.schedule(testTask, 70);
+			testTask = new TimerTestTask();
+			testTask.incrementCount(true);
+			t.schedule(testTask, 10);
+			try {
+				Thread.sleep(400);
+			} catch (InterruptedException e) {
+			}
+			assertTrue(
+					"Multiple tasks should have incremented counter 4 times not "
+							+ timerCounter, timerCounter == 4);
+			t.cancel();
+		} finally {
+			if (t != null)
+				t.cancel();
+		}
+	}
+
+	/**
+	 * @tests java.util.Timer#schedule(java.util.TimerTask, long, long)
+	 */
+	public void test_scheduleLjava_util_TimerTaskJJ() {
+		Timer t = null;
+		try {
+			// Ensure a Timer throws an IllegalStateException after cancelled
+			t = new Timer();
+			TimerTestTask testTask = new TimerTestTask();
+			t.cancel();
+			boolean exception = false;
+			try {
+				t.schedule(testTask, 100, 100);
+			} catch (IllegalStateException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a task after Timer.cancel() should throw exception",
+					exception);
+
+			// Ensure a Timer throws an IllegalStateException if task already
+			// cancelled
+			t = new Timer();
+			testTask = new TimerTestTask();
+			testTask.cancel();
+			exception = false;
+			try {
+				t.schedule(testTask, 100, 100);
+			} catch (IllegalStateException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a task after cancelling it should throw exception",
+					exception);
+			t.cancel();
+
+			// Ensure a Timer throws an IllegalArgumentException if delay is
+			// negative
+			t = new Timer();
+			testTask = new TimerTestTask();
+			exception = false;
+			try {
+				t.schedule(testTask, -100, 100);
+			} catch (IllegalArgumentException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a task with negative delay should throw IllegalArgumentException",
+					exception);
+			t.cancel();
+
+			// Ensure a Timer throws an IllegalArgumentException if period is
+			// negative
+			t = new Timer();
+			testTask = new TimerTestTask();
+			exception = false;
+			try {
+				t.schedule(testTask, 100, -100);
+			} catch (IllegalArgumentException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a task with negative period should throw IllegalArgumentException",
+					exception);
+			t.cancel();
+
+			// Ensure a Timer throws an IllegalArgumentException if period is
+			// zero
+			t = new Timer();
+			testTask = new TimerTestTask();
+			exception = false;
+			try {
+				t.schedule(testTask, 100, 0);
+			} catch (IllegalArgumentException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a task with 0 period should throw IllegalArgumentException",
+					exception);
+			t.cancel();
+
+			// Ensure a Timer throws a NullPointerException if the task is null
+			t = new Timer();
+			exception = false;
+			try {
+				t.schedule(null, 10, 10);
+			} catch (NullPointerException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a null task should throw NullPointerException",
+					exception);
+			t.cancel();
+
+			// Ensure proper sequence of exceptions
+			t = new Timer();
+			exception = false;
+			try {
+				t.schedule(null, -10, -10);
+			} catch (NullPointerException e) {
+			} catch (IllegalArgumentException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a null task with negative delays should throw IllegalArgumentException first",
+					exception);
+			t.cancel();
+
+			// Ensure a task is run at least twice
+			t = new Timer();
+			testTask = new TimerTestTask();
+			t.schedule(testTask, 100, 100);
+			try {
+				Thread.sleep(400);
+			} catch (InterruptedException e) {
+			}
+			assertTrue(
+					"TimerTask.run() method should have been called at least twice ("
+							+ testTask.wasRun() + ")", testTask.wasRun() >= 2);
+			t.cancel();
+
+			// Ensure multiple tasks are run
+			t = new Timer();
+			testTask = new TimerTestTask();
+			testTask.incrementCount(true);
+			t.schedule(testTask, 100, 100); // at least 9 times
+			testTask = new TimerTestTask();
+			testTask.incrementCount(true);
+			t.schedule(testTask, 200, 100); // at least 7 times
+			testTask = new TimerTestTask();
+			testTask.incrementCount(true);
+			t.schedule(testTask, 300, 200); // at least 4 times
+			testTask = new TimerTestTask();
+			testTask.incrementCount(true);
+			t.schedule(testTask, 100, 200); // at least 4 times
+			try {
+				Thread.sleep(1200); // Allowed more room for error
+			} catch (InterruptedException e) {
+			}
+			assertTrue(
+					"Multiple tasks should have incremented counter 24 times not "
+							+ timerCounter, timerCounter >= 24);
+			t.cancel();
+		} finally {
+			if (t != null)
+				t.cancel();
+		}
+	}
+
+	/**
+	 * @tests java.util.Timer#schedule(java.util.TimerTask, java.util.Date,
+	 *        long)
+	 */
+	public void test_scheduleLjava_util_TimerTaskLjava_util_DateJ() {
+		Timer t = null;
+		try {
+			// Ensure a Timer throws an IllegalStateException after cancelled
+			t = new Timer();
+			TimerTestTask testTask = new TimerTestTask();
+			Date d = new Date(System.currentTimeMillis() + 100);
+			t.cancel();
+			boolean exception = false;
+			try {
+				t.schedule(testTask, d, 100);
+			} catch (IllegalStateException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a task after Timer.cancel() should throw exception",
+					exception);
+
+			// Ensure a Timer throws an IllegalStateException if task already
+			// cancelled
+			t = new Timer();
+			d = new Date(System.currentTimeMillis() + 100);
+			testTask = new TimerTestTask();
+			testTask.cancel();
+			exception = false;
+			try {
+				t.schedule(testTask, d, 100);
+			} catch (IllegalStateException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a task after cancelling it should throw exception",
+					exception);
+			t.cancel();
+
+			// Ensure a Timer throws an IllegalArgumentException if delay is
+			// negative
+			t = new Timer();
+			d = new Date(-100);
+			testTask = new TimerTestTask();
+			exception = false;
+			try {
+				t.schedule(testTask, d, 100);
+			} catch (IllegalArgumentException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a task with negative delay should throw IllegalArgumentException",
+					exception);
+			t.cancel();
+
+			// Ensure a Timer throws an IllegalArgumentException if period is
+			// negative
+			t = new Timer();
+			d = new Date(System.currentTimeMillis() + 100);
+			testTask = new TimerTestTask();
+			exception = false;
+			try {
+				t.schedule(testTask, d, -100);
+			} catch (IllegalArgumentException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a task with negative period should throw IllegalArgumentException",
+					exception);
+			t.cancel();
+
+			// Ensure a Timer throws a NullPointerException if the task is null
+			t = new Timer();
+			d = new Date(System.currentTimeMillis() + 100);
+			exception = false;
+			try {
+				t.schedule(null, d, 10);
+			} catch (NullPointerException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a null task should throw NullPointerException",
+					exception);
+			t.cancel();
+
+			// Ensure a Timer throws a NullPointerException if the date is null
+			t = new Timer();
+			testTask = new TimerTestTask();
+			exception = false;
+			try {
+				t.schedule(testTask, null, 10);
+			} catch (NullPointerException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a null task should throw NullPointerException",
+					exception);
+			t.cancel();
+
+			// Ensure proper sequence of exceptions
+			t = new Timer();
+			d = new Date(-100);
+			exception = false;
+			try {
+				t.schedule(null, d, 10);
+			} catch (NullPointerException e) {
+			} catch (IllegalArgumentException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a null task with negative dates should throw IllegalArgumentException first",
+					exception);
+			t.cancel();
+
+			// Ensure a task is run at least twice
+			t = new Timer();
+			d = new Date(System.currentTimeMillis() + 100);
+			testTask = new TimerTestTask();
+			t.schedule(testTask, d, 100);
+			try {
+				Thread.sleep(800);
+			} catch (InterruptedException e) {
+			}
+			assertTrue(
+					"TimerTask.run() method should have been called at least twice ("
+							+ testTask.wasRun() + ")", testTask.wasRun() >= 2);
+			t.cancel();
+
+			// Ensure multiple tasks are run
+			t = new Timer();
+			testTask = new TimerTestTask();
+			testTask.incrementCount(true);
+			d = new Date(System.currentTimeMillis() + 100);
+			t.schedule(testTask, d, 100); // at least 9 times
+			testTask = new TimerTestTask();
+			testTask.incrementCount(true);
+			d = new Date(System.currentTimeMillis() + 200);
+			t.schedule(testTask, d, 100); // at least 7 times
+			testTask = new TimerTestTask();
+			testTask.incrementCount(true);
+			d = new Date(System.currentTimeMillis() + 300);
+			t.schedule(testTask, d, 200); // at least 4 times
+			testTask = new TimerTestTask();
+			testTask.incrementCount(true);
+			d = new Date(System.currentTimeMillis() + 100);
+			t.schedule(testTask, d, 200); // at least 4 times
+			try {
+				Thread.sleep(3000);
+			} catch (InterruptedException e) {
+			}
+			assertTrue(
+					"Multiple tasks should have incremented counter 24 times not "
+							+ timerCounter, timerCounter >= 24);
+			t.cancel();
+		} finally {
+			if (t != null)
+				t.cancel();
+		}
+	}
+
+	/**
+	 * @tests java.util.Timer#scheduleAtFixedRate(java.util.TimerTask, long,
+	 *        long)
+	 */
+	public void test_scheduleAtFixedRateLjava_util_TimerTaskJJ() {
+		Timer t = null;
+		try {
+			// Ensure a Timer throws an IllegalStateException after cancelled
+			t = new Timer();
+			TimerTestTask testTask = new TimerTestTask();
+			t.cancel();
+			boolean exception = false;
+			try {
+				t.scheduleAtFixedRate(testTask, 100, 100);
+			} catch (IllegalStateException e) {
+				exception = true;
+			}
+			assertTrue(
+					"scheduleAtFixedRate after Timer.cancel() should throw exception",
+					exception);
+
+			// Ensure a Timer throws an IllegalArgumentException if delay is
+			// negative
+			t = new Timer();
+			testTask = new TimerTestTask();
+			exception = false;
+			try {
+				t.scheduleAtFixedRate(testTask, -100, 100);
+			} catch (IllegalArgumentException e) {
+				exception = true;
+			}
+			assertTrue(
+					"scheduleAtFixedRate with negative delay should throw IllegalArgumentException",
+					exception);
+			t.cancel();
+
+			// Ensure a Timer throws an IllegalArgumentException if period is
+			// negative
+			t = new Timer();
+			testTask = new TimerTestTask();
+			exception = false;
+			try {
+				t.scheduleAtFixedRate(testTask, 100, -100);
+			} catch (IllegalArgumentException e) {
+				exception = true;
+			}
+			assertTrue(
+					"scheduleAtFixedRate with negative period should throw IllegalArgumentException",
+					exception);
+			t.cancel();
+
+			// Ensure a task is run at least twice
+			t = new Timer();
+			testTask = new TimerTestTask();
+			t.scheduleAtFixedRate(testTask, 100, 100);
+			try {
+				Thread.sleep(400);
+			} catch (InterruptedException e) {
+			}
+			assertTrue(
+					"TimerTask.run() method should have been called at least twice ("
+							+ testTask.wasRun() + ")", testTask.wasRun() >= 2);
+			t.cancel();
+
+			class SlowThenFastTask extends TimerTask {
+				int wasRun = 0;
+
+				long startedAt;
+
+				long lastDelta;
+
+				public void run() {
+					if (wasRun == 0)
+						startedAt = System.currentTimeMillis();
+					lastDelta = System.currentTimeMillis()
+							- (startedAt + (100 * wasRun));
+					wasRun++;
+					if (wasRun == 2) {
+						try {
+							Thread.sleep(200);
+						} catch (InterruptedException e) {
+						}
+					}
+				}
+
+				public long lastDelta() {
+					return lastDelta;
+				}
+
+				public int wasRun() {
+					return wasRun;
+				}
+			}
+
+			// Ensure multiple tasks are run
+			t = new Timer();
+			SlowThenFastTask slowThenFastTask = new SlowThenFastTask();
+
+			// at least 9 times even when asleep
+			t.scheduleAtFixedRate(slowThenFastTask, 100, 100);
+			try {
+				Thread.sleep(1000);
+			} catch (InterruptedException e) {
+			}
+			long lastDelta = slowThenFastTask.lastDelta();
+			assertTrue("Fixed Rate Schedule should catch up, but is off by "
+					+ lastDelta + " ms", slowThenFastTask.lastDelta < 300);
+			t.cancel();
+		} finally {
+			if (t != null)
+				t.cancel();
+		}
+	}
+
+	/**
+	 * @tests java.util.Timer#scheduleAtFixedRate(java.util.TimerTask,
+	 *        java.util.Date, long)
+	 */
+	public void test_scheduleAtFixedRateLjava_util_TimerTaskLjava_util_DateJ() {
+		Timer t = null;
+		try {
+			// Ensure a Timer throws an IllegalStateException after cancelled
+			t = new Timer();
+			TimerTestTask testTask = new TimerTestTask();
+			t.cancel();
+			boolean exception = false;
+			Date d = new Date(System.currentTimeMillis() + 100);
+			try {
+				t.scheduleAtFixedRate(testTask, d, 100);
+			} catch (IllegalStateException e) {
+				exception = true;
+			}
+			assertTrue(
+					"scheduleAtFixedRate after Timer.cancel() should throw exception",
+					exception);
+
+			// Ensure a Timer throws an IllegalArgumentException if delay is
+			// negative
+			t = new Timer();
+			testTask = new TimerTestTask();
+			exception = false;
+			d = new Date(-100);
+			try {
+				t.scheduleAtFixedRate(testTask, d, 100);
+			} catch (IllegalArgumentException e) {
+				exception = true;
+			}
+			assertTrue(
+					"scheduleAtFixedRate with negative Date should throw IllegalArgumentException",
+					exception);
+			t.cancel();
+
+			// Ensure a Timer throws an IllegalArgumentException if period is
+			// negative
+			t = new Timer();
+			testTask = new TimerTestTask();
+			exception = false;
+			try {
+				t.scheduleAtFixedRate(testTask, d, -100);
+			} catch (IllegalArgumentException e) {
+				exception = true;
+			}
+			assertTrue(
+					"scheduleAtFixedRate with negative period should throw IllegalArgumentException",
+					exception);
+			t.cancel();
+
+			// Ensure a Timer throws an NullPointerException if date is Null
+			t = new Timer();
+			testTask = new TimerTestTask();
+			exception = false;
+			try {
+				t.scheduleAtFixedRate(testTask, null, 100);
+			} catch (NullPointerException e) {
+				exception = true;
+			}
+			assertTrue(
+					"scheduleAtFixedRate with null date should throw NullPointerException",
+					exception);
+			t.cancel();
+
+			// Ensure proper sequence of exceptions
+			t = new Timer();
+			exception = false;
+			d = new Date(-100);
+			try {
+				t.scheduleAtFixedRate(null, d, 10);
+			} catch (NullPointerException e) {
+			} catch (IllegalArgumentException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a null task with negative date should throw IllegalArgumentException first",
+					exception);
+			t.cancel();
+
+			// Ensure proper sequence of exceptions
+			t = new Timer();
+			exception = false;
+			try {
+				t.scheduleAtFixedRate(null, null, -10);
+			} catch (NullPointerException e) {
+			} catch (IllegalArgumentException e) {
+				exception = true;
+			}
+			assertTrue(
+					"Scheduling a null task & null date & negative period should throw IllegalArgumentException first",
+					exception);
+			t.cancel();
+
+			// Ensure a task is run at least twice
+			t = new Timer();
+			testTask = new TimerTestTask();
+			d = new Date(System.currentTimeMillis() + 100);
+			t.scheduleAtFixedRate(testTask, d, 100);
+			try {
+				Thread.sleep(400);
+			} catch (InterruptedException e) {
+			}
+			assertTrue(
+					"TimerTask.run() method should have been called at least twice ("
+							+ testTask.wasRun() + ")", testTask.wasRun() >= 2);
+			t.cancel();
+
+			class SlowThenFastTask extends TimerTask {
+				int wasRun = 0;
+
+				long startedAt;
+
+				long lastDelta;
+
+				public void run() {
+					if (wasRun == 0)
+						startedAt = System.currentTimeMillis();
+					lastDelta = System.currentTimeMillis()
+							- (startedAt + (100 * wasRun));
+					wasRun++;
+					if (wasRun == 2) {
+						try {
+							Thread.sleep(200);
+						} catch (InterruptedException e) {
+						}
+					}
+				}
+
+				public long lastDelta() {
+					return lastDelta;
+				}
+
+				public int wasRun() {
+					return wasRun;
+				}
+			}
+
+			// Ensure multiple tasks are run
+			t = new Timer();
+			SlowThenFastTask slowThenFastTask = new SlowThenFastTask();
+			d = new Date(System.currentTimeMillis() + 100);
+
+			// at least 9 times even when asleep
+			t.scheduleAtFixedRate(slowThenFastTask, d, 100);
+			try {
+				Thread.sleep(1000);
+			} catch (InterruptedException e) {
+			}
+			long lastDelta = slowThenFastTask.lastDelta();
+			assertTrue("Fixed Rate Schedule should catch up, but is off by "
+					+ lastDelta + " ms", lastDelta < 300);
+			t.cancel();
+		} finally {
+			if (t != null)
+				t.cancel();
+		}
+	}
+
+	protected void setUp() {
+		timerCounter = 0;
+	}
+
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TooManyListenersExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TooManyListenersExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TooManyListenersExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TooManyListenersExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,62 @@
+/* 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 tests.api.java.util;
+
+import java.util.TooManyListenersException;
+
+public class TooManyListenersExceptionTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.util.TooManyListenersException#TooManyListenersException()
+	 */
+	public void test_Constructor() {
+		// Test for method java.util.TooManyListenersException()
+		try {
+			throw new TooManyListenersException();
+		} catch (TooManyListenersException e) {
+			assertTrue(
+					"Message thrown with exception constructed with no message",
+					e.getMessage() == null);
+		}
+	}
+
+	/**
+	 * @tests java.util.TooManyListenersException#TooManyListenersException(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method java.util.TooManyListenersException(java.lang.String)
+		try {
+			throw new TooManyListenersException("Gah");
+		} catch (TooManyListenersException e) {
+			assertTrue("Incorrect message thrown with exception", e
+					.getMessage().equals("Gah"));
+		}
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+	}
+}



Mime
View raw message