You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/03/15 12:47:39 UTC

svn commit: r386058 [36/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/...

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/CurrencyTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/CurrencyTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/CurrencyTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/CurrencyTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,356 @@
+/* Copyright 2004, 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.Currency;
+import java.util.Locale;
+
+public class CurrencyTest extends junit.framework.TestCase {
+
+	private static Locale defaultLocale = Locale.getDefault();
+
+	/**
+	 * @tests java.util.Currency#getInstance(java.lang.String)
+	 */
+	public void test_getInstanceLjava_lang_String() {
+		// see test_getInstanceLjava_util_Locale() tests
+	}
+
+	/**
+	 * @tests java.util.Currency#getInstance(java.util.Locale)
+	 */
+	public void test_getInstanceLjava_util_Locale() {
+		/*
+		 * the behaviour in all these three cases should be the same since this
+		 * method ignores language and variant component of the locale.
+		 */
+		Currency c0 = Currency.getInstance("CAD");
+		Currency c1 = Currency.getInstance(new Locale("en", "CA"));
+		assertTrue(
+				"Currency.getInstance(new Locale(\"en\",\"CA\")) isn't equal to Currency.getInstance(\"CAD\")",
+				c1 == c0);
+		Currency c2 = Currency.getInstance(new Locale("fr", "CA"));
+		assertTrue(
+				"Currency.getInstance(new Locale(\"fr\",\"CA\")) isn't equal to Currency.getInstance(\"CAD\")",
+				c2 == c0);
+		Currency c3 = Currency.getInstance(new Locale("", "CA"));
+		assertTrue(
+				"Currency.getInstance(new Locale(\"\",\"CA\")) isn't equal to Currency.getInstance(\"CAD\")",
+				c3 == c0);
+
+		c0 = Currency.getInstance("JPY");
+		c1 = Currency.getInstance(new Locale("ja", "JP"));
+		assertTrue(
+				"Currency.getInstance(new Locale(\"ja\",\"JP\")) isn't equal to Currency.getInstance(\"JPY\")",
+				c1 == c0);
+		c2 = Currency.getInstance(new Locale("", "JP"));
+		assertTrue(
+				"Currency.getInstance(new Locale(\"\",\"JP\")) isn't equal to Currency.getInstance(\"JPY\")",
+				c2 == c0);
+		c3 = Currency.getInstance(new Locale("bogus", "JP"));
+		assertTrue(
+				"Currency.getInstance(new Locale(\"bogus\",\"JP\")) isn't equal to Currency.getInstance(\"JPY\")",
+				c3 == c0);
+
+		Locale localeGu = new Locale("gu", "IN");
+		Currency cGu = Currency.getInstance(localeGu);
+		Locale localeKn = new Locale("kn", "IN");
+		Currency cKn = Currency.getInstance(localeKn);
+		assertTrue("Currency.getInstance(Locale_" + localeGu.toString() + "))"
+				+ "isn't equal to " + "Currency.getInstance(Locale_"
+				+ localeKn.toString() + "))", cGu == cKn);
+
+		// some teritories do not have currencies, like Antarctica
+		Locale loc = new Locale("", "AQ");
+		try {
+			Currency curr = Currency.getInstance(loc);
+			assertTrue(
+					"Currency.getInstance(new Locale(\"\", \"AQ\")) did not return null",
+					curr == null);
+		} catch (IllegalArgumentException e) {
+			fail("Unexpected IllegalArgumentException " + e);
+		}
+
+		// unsupported/legacy iso3 countries
+		loc = new Locale("", "ZR");
+		try {
+			Currency curr = Currency.getInstance(loc);
+			fail("Expected IllegalArgumentException");
+		} catch (IllegalArgumentException e) {
+		}
+
+		loc = new Locale("", "ZAR");
+		try {
+			Currency curr = Currency.getInstance(loc);
+			fail("Expected IllegalArgumentException");
+		} catch (IllegalArgumentException e) {
+		}
+
+		loc = new Locale("", "FX");
+		try {
+			Currency curr = Currency.getInstance(loc);
+			fail("Expected IllegalArgumentException");
+		} catch (IllegalArgumentException e) {
+		}
+
+		loc = new Locale("", "FXX");
+		try {
+			Currency curr = Currency.getInstance(loc);
+			fail("Expected IllegalArgumentException");
+		} catch (IllegalArgumentException e) {
+		}
+	}
+
+	/**
+	 * @tests java.util.Currency#getSymbol()
+	 */
+	public void test_getSymbol() {
+
+		Currency currK = Currency.getInstance("KRW");
+		Currency currI = Currency.getInstance("INR");
+		Currency currUS = Currency.getInstance("USD");
+
+		Locale.setDefault(Locale.US);
+		assertEquals("currK.getSymbol()", "KRW", currK.getSymbol());
+		assertEquals("currI.getSymbol()", "INR", currI.getSymbol());
+		assertEquals("currUS.getSymbol()", "$", currUS.getSymbol());
+
+		Locale.setDefault(new Locale("ko", "KR"));
+		assertEquals("currK.getSymbol()", "\uffe6", currK.getSymbol());
+		assertEquals("currI.getSymbol()", "INR", currI.getSymbol());
+		assertEquals("currUS.getSymbol()", "USD", currUS.getSymbol());
+
+		// test what happens if this is an invalid locale,
+		// one with Korean country but an India language
+		// this method should return the currency codes in that case
+		Locale.setDefault(new Locale("kr", "KR"));
+		assertEquals("currK.getSymbol()", currK.getSymbol(), "KRW");
+		assertEquals("currI.getSymbol()", currI.getSymbol(), "INR");
+		assertEquals("currUS.getSymbol()", currUS.getSymbol(), "USD");
+	}
+
+	/**
+	 * @tests java.util.Currency#getSymbol(java.util.Locale)
+	 */
+	public void test_getSymbolLjava_util_Locale() {
+		Locale.setDefault(Locale.US);
+		Currency currE = Currency.getInstance("EUR");
+		assertEquals("EUR", currE.getSymbol(Locale.JAPAN));
+		assertEquals("EUR", currE.getSymbol(Locale.JAPANESE));
+		assertEquals("EUR", currE.getSymbol(new Locale("", "FR")));
+		assertEquals("\u20ac", currE.getSymbol(Locale.FRANCE));
+		assertEquals("EUR", currE.getSymbol(Locale.FRENCH));
+
+		Currency currJ = Currency.getInstance("JPY");
+		assertEquals("\uffe5", currJ.getSymbol(Locale.JAPAN));
+		assertEquals("JPY", currJ.getSymbol(Locale.JAPANESE));
+		assertEquals("JPY", currJ.getSymbol(Locale.FRANCE));
+		assertEquals("JPY", currJ.getSymbol(Locale.FRENCH));
+
+		Currency currUS = Currency.getInstance("USD");
+		assertEquals("USD", currUS.getSymbol(Locale.JAPAN));
+
+		Locale.setDefault(new Locale("ja", "JP"));
+		assertEquals("\uffe5", currJ.getSymbol(new Locale("", "JP")));
+		assertEquals("USD", currUS.getSymbol(new Locale("", "JP")));
+
+		Locale.setDefault(Locale.US);
+		assertEquals("JPY", currJ.getSymbol(new Locale("", "JP")));
+		assertEquals("$", currUS.getSymbol(new Locale("", "JP")));
+
+		assertEquals("USD", currUS.getSymbol(Locale.JAPANESE));
+		assertEquals("USD", currUS.getSymbol(Locale.FRANCE));
+		assertEquals("USD", currUS.getSymbol(Locale.FRENCH));
+		assertEquals("USD", currUS.getSymbol(new Locale("fr", "FR")));
+		assertEquals("$", currUS.getSymbol(new Locale("", "FR"))); // default
+		// locale
+
+		assertEquals("$", currUS.getSymbol(Locale.US));
+		assertEquals("USD", currUS.getSymbol(Locale.ENGLISH));
+
+		assertEquals("$", currUS.getSymbol(new Locale("en", "US")));
+		assertEquals("$", currUS.getSymbol(new Locale("", "US")));
+
+		Currency currCA = Currency.getInstance("CAD");
+		assertEquals("CAD", currCA.getSymbol(Locale.JAPAN));
+		assertEquals("CAD", currCA.getSymbol(Locale.JAPANESE));
+		assertEquals("CAD", currCA.getSymbol(Locale.FRANCE));
+		assertEquals("CAD", currCA.getSymbol(Locale.FRENCH));
+		assertEquals("CAD", currCA.getSymbol(Locale.US));
+		assertEquals("CAD", currCA.getSymbol(Locale.ENGLISH));
+		assertEquals("CAD", currCA.getSymbol(new Locale("es", "US")));
+		assertEquals("CAD", currCA.getSymbol(new Locale("en", "US")));
+
+		assertEquals("$", currCA.getSymbol(Locale.CANADA));
+		assertEquals("$", currCA.getSymbol(Locale.CANADA_FRENCH));
+		assertEquals("$", currCA.getSymbol(new Locale("en", "CA")));
+		assertEquals("$", currCA.getSymbol(new Locale("fr", "CA")));
+		assertEquals("CAD", currCA.getSymbol(new Locale("", "CA")));
+
+		// tests what happens with improper locales, i.e. countries without the
+		// given language
+		assertEquals("currUS.getSymbol(new Locale(\"ar\", \"US\"))", "USD",
+				currUS.getSymbol(new Locale("ar", "US")));
+		assertEquals("currUS.getSymbol(new Locale(\"ar\", \"CA\"))", "USD",
+				currUS.getSymbol(new Locale("ar", "CA")));
+		assertEquals("currCA.getSymbol(new Locale(\"ar\", \"US\"))", "CAD",
+				currCA.getSymbol(new Locale("ar", "US")));
+		assertEquals("currCA.getSymbol(new Locale(\"ar\", \"CA\"))", "CAD",
+				currCA.getSymbol(new Locale("ar", "CA")));
+		assertEquals("currJ.getSymbol(new Locale(\"ja\", \"US\"))", "JPY",
+				currJ.getSymbol(new Locale("ja", "US")));
+		assertEquals("currUS.getSymbol(new Locale(\"ja\", \"US\"))", "USD",
+				currUS.getSymbol(new Locale("ja", "US")));
+
+		// cross testing between USD and JPY when locale is JAPANESE JAPAN
+
+		// set default locale to Locale_ja_JP
+		Locale.setDefault(new Locale("ja", "JP"));
+
+		Currency currJ2 = Currency.getInstance("JPY");
+		Currency currUS2 = Currency.getInstance("USD");
+
+		// the real JAPAN locale
+		assertEquals("\uffe5", currJ2.getSymbol(new Locale("ja", "JP")));
+
+		// no language
+		assertEquals("\uffe5", currJ2.getSymbol(new Locale("", "JP")));
+
+		// no country
+		assertEquals("JPY", currJ2.getSymbol(new Locale("ja", "")));
+
+		// no language
+		assertEquals("\uffe5", currJ2.getSymbol(new Locale("", "US")));
+
+		// no country
+		assertEquals("JPY", currJ2.getSymbol(new Locale("en", "")));
+
+		// bogus Locales , when default locale is Locale_ja_JP
+		assertEquals("JPY", currJ2.getSymbol(new Locale("ar", "JP")));
+		assertEquals("JPY", currJ2.getSymbol(new Locale("ar", "US")));
+		assertEquals("JPY", currJ2.getSymbol(new Locale("ja", "AE")));
+		assertEquals("JPY", currJ2.getSymbol(new Locale("en", "AE")));
+		assertEquals("currJ.getSymbol(new Locale(\"ja\", \"US\"))", "JPY",
+				currJ.getSymbol(new Locale("ja", "US")));
+
+		// the real US locale
+		assertEquals("$", currUS2.getSymbol(new Locale("en", "US")));
+
+		// no country
+		assertEquals("USD", currUS2.getSymbol(new Locale("ja", "")));
+
+		// no language
+		assertEquals("USD", currUS2.getSymbol(new Locale("", "JP")));
+
+		// no language
+		assertEquals("USD", currUS2.getSymbol(new Locale("", "US")));
+
+		// no country
+		assertEquals("USD", currUS2.getSymbol(new Locale("en", "")));
+
+		// bogus Locales , when default locale is Locale_ja_JP
+		assertEquals("USD", currUS2.getSymbol(new Locale("ar", "JP")));
+		assertEquals("USD", currUS2.getSymbol(new Locale("ar", "US")));
+		assertEquals("USD", currUS2.getSymbol(new Locale("ja", "AE")));
+		assertEquals("USD", currUS2.getSymbol(new Locale("en", "AE")));
+		assertEquals("currUS.getSymbol(new Locale(\"ja\", \"US\"))", "USD",
+				currUS.getSymbol(new Locale("ja", "US")));
+
+		Locale.setDefault(Locale.US);
+
+		// euro tests
+		Currency currDKK = Currency.getInstance("DKK");
+		assertEquals("\u20ac", currE.getSymbol(new Locale("da", "DK")));
+		assertEquals("kr", currDKK.getSymbol(new Locale("da", "DK")));
+
+		assertEquals("EUR", currE.getSymbol(new Locale("da", "")));
+		assertEquals("DKK", currDKK.getSymbol(new Locale("da", "")));
+
+		assertEquals("EUR", currE.getSymbol(new Locale("", "DK")));
+		assertEquals("DKK", currDKK.getSymbol(new Locale("", "DK")));
+
+		Locale.setDefault(new Locale("da", "DK"));
+		assertEquals("\u20ac", currE.getSymbol(new Locale("da", "DK")));
+		assertEquals("kr", currDKK.getSymbol(new Locale("da", "DK")));
+
+		assertEquals("EUR", currE.getSymbol(new Locale("da", "")));
+		assertEquals("DKK", currDKK.getSymbol(new Locale("da", "")));
+
+		assertEquals("\u20ac", currE.getSymbol(new Locale("", "DK")));
+		assertEquals("kr", currDKK.getSymbol(new Locale("", "DK")));
+
+		assertEquals("EUR", currE.getSymbol(new Locale("ar", "AE")));
+		assertEquals("DKK", currDKK.getSymbol(new Locale("ar", "AE")));
+	}
+
+	/**
+	 * @tests java.util.Currency#getDefaultFractionDigits()
+	 */
+	public void test_getDefaultFractionDigits() {
+		Currency c1 = Currency.getInstance("EUR");
+		c1.getDefaultFractionDigits();
+		assertEquals(" Currency.getInstance(\"" + c1
+				+ "\") returned incorrect number of digits. ", 2, c1
+				.getDefaultFractionDigits());
+
+		Currency c2 = Currency.getInstance("JPY");
+		c2.getDefaultFractionDigits();
+		assertEquals(" Currency.getInstance(\"" + c2
+				+ "\") returned incorrect number of digits. ", 0, c2
+				.getDefaultFractionDigits());
+
+		Currency c3 = Currency.getInstance("XBD");
+		c3.getDefaultFractionDigits();
+		assertEquals(" Currency.getInstance(\"" + c3
+				+ "\") returned incorrect number of digits. ", -1, c3
+				.getDefaultFractionDigits());
+
+	}
+
+	protected void setUp() {
+		Locale.setDefault(defaultLocale);
+	}
+
+	protected void tearDown() {
+	}
+
+	/**
+	 * Helper method to display Currency info
+	 * 
+	 * @param c
+	 */
+	private void printCurrency(Currency c) {
+		System.out.println();
+		System.out.println(c.getCurrencyCode());
+		System.out.println(c.getSymbol());
+		System.out.println(c.getDefaultFractionDigits());
+	}
+
+	/**
+	 * helper method to display Locale info
+	 */
+	private static void printLocale(Locale loc) {
+		System.out.println();
+		System.out.println(loc.getDisplayName());
+		System.out.println(loc.getCountry());
+		System.out.println(loc.getLanguage());
+		System.out.println(loc.getDisplayCountry());
+		System.out.println(loc.getDisplayLanguage());
+		System.out.println(loc.getDisplayName());
+		System.out.println(loc.getISO3Country());
+		System.out.println(loc.getISO3Language());
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/DateTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/DateTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/DateTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/DateTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,484 @@
+/* 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.TimeZone;
+
+public class DateTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.util.Date#Date()
+	 */
+	public void test_Constructor() {
+		// Test for method java.util.Date()
+		GregorianCalendar gc = new GregorianCalendar(1998, Calendar.OCTOBER,
+				13, 19, 9);
+		long oldTime = gc.getTime().getTime();
+		long now = new Date().getTime();
+		assertTrue("Created incorrect date: " + oldTime + " now: " + now,
+				oldTime < now);
+	}
+
+	/**
+	 * @tests java.util.Date#Date(int, int, int)
+	 */
+	public void test_ConstructorIII() {
+		// Test for method java.util.Date(int, int, int)
+		Date d1 = new Date(70, 0, 1); // the epoch + local time
+		
+		// the epoch + local time
+		Date d2 = new Date(0 + d1.getTimezoneOffset() * 60 * 1000);
+		
+		assertTrue("Created incorrect date", d1.equals(d2));
+
+		Date date = new Date(99, 5, 22);
+		Calendar cal = new GregorianCalendar(1999, Calendar.JUNE, 22);
+		assertTrue("Wrong time zone", date.equals(cal.getTime()));
+	}
+
+	/**
+	 * @tests java.util.Date#Date(int, int, int, int, int)
+	 */
+	public void test_ConstructorIIIII() {
+		// Test for method java.util.Date(int, int, int, int, int)
+		
+		// the epoch + local time + (1 hour and 1 minute)
+		Date d1 = new Date(70, 0, 1, 1, 1); 
+
+		// the epoch + local time + (1 hour and 1 minute)
+		Date d2 = new Date(0 + d1.getTimezoneOffset() * 60 * 1000 + 60 * 60
+				* 1000 + 60 * 1000);
+
+		assertTrue("Created incorrect date", d1.equals(d2));
+	}
+
+	/**
+	 * @tests java.util.Date#Date(int, int, int, int, int, int)
+	 */
+	public void test_ConstructorIIIIII() {
+		// Test for method java.util.Date(int, int, int, int, int, int)
+		
+		// the epoch + local time + (1 hour and 1 minute + 1 second)
+		Date d1 = new Date(70, 0, 1, 1, 1, 1); 
+		
+		// the epoch + local time + (1 hour and 1 minute + 1 second)
+		Date d2 = new Date(0 + d1.getTimezoneOffset() * 60 * 1000 + 60 * 60
+				* 1000 + 60 * 1000 + 1000);
+		
+		assertTrue("Created incorrect date", d1.equals(d2));
+	}
+
+	/**
+	 * @tests java.util.Date#Date(long)
+	 */
+	public void test_ConstructorJ() {
+		// Test for method java.util.Date(long)
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * @tests java.util.Date#Date(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method java.util.Date(java.lang.String)
+		Date d1 = new Date("January 1, 1970, 00:00:00 GMT"); // the epoch
+		Date d2 = new Date(0); // the epoch
+		assertTrue("Created incorrect date", d1.equals(d2));
+	}
+
+	/**
+	 * @tests java.util.Date#after(java.util.Date)
+	 */
+	public void test_afterLjava_util_Date() {
+		// Test for method boolean java.util.Date.after(java.util.Date)
+		Date d1 = new Date(0);
+		Date d2 = new Date(1900000);
+		assertTrue("Older was returned as newer", d2.after(d1));
+		assertTrue("Newer was returned as older", !d1.after(d2));
+	}
+
+	/**
+	 * @tests java.util.Date#before(java.util.Date)
+	 */
+	public void test_beforeLjava_util_Date() {
+		// Test for method boolean java.util.Date.before(java.util.Date)
+		Date d1 = new Date(0);
+		Date d2 = new Date(1900000);
+		assertTrue("Older was returned as newer", !d2.before(d1));
+		assertTrue("Newer was returned as older", d1.before(d2));
+	}
+
+	/**
+	 * @tests java.util.Date#clone()
+	 */
+	public void test_clone() {
+		// Test for method java.lang.Object java.util.Date.clone()
+		Date d1 = new Date(100000);
+		Date d2 = (Date) d1.clone();
+		assertTrue(
+				"Cloning date results in same reference--new date is equivalent",
+				d1 != d2);
+		assertTrue("Cloning date results unequal date", d1.equals(d2));
+	}
+
+	/**
+	 * @tests java.util.Date#compareTo(java.lang.Object)
+	 */
+	public void test_compareToLjava_lang_Object() {
+		// Test for method int java.util.Date.compareTo(java.lang.Object)
+		final int someNumber = 10000;
+		Date d1 = new Date(someNumber);
+		Date d2 = new Date(someNumber);
+		Date d3 = new Date(someNumber + 1);
+		Date d4 = new Date(someNumber - 1);
+		Integer i = new Integer(0);
+		assertTrue("Comparing a date to itself did not answer zero", d1
+				.compareTo((Object) d1) == 0);
+		assertTrue("Comparing equal dates did not answer zero", d1
+				.compareTo((Object) d2) == 0);
+		assertTrue(
+				"date1.compareTo(date2), where date1 > date2, did not result in 1",
+				d1.compareTo((Object) d4) == 1);
+		assertTrue(
+				"date1.compareTo(date2), where date1 < date2, did not result in -1",
+				d1.compareTo((Object) d3) == -1);
+		try {
+			d1.compareTo(i);
+		} catch (ClassCastException e) {
+			return;
+		}
+		fail(
+				"Comparing a date to a non-date did not throw ClassCastException");
+	}
+
+	/**
+	 * @tests java.util.Date#compareTo(java.util.Date)
+	 */
+	public void test_compareToLjava_util_Date() {
+		// Test for method int java.util.Date.compareTo(java.util.Date)
+		final int someNumber = 10000;
+		Date d1 = new Date(someNumber);
+		Date d2 = new Date(someNumber);
+		Date d3 = new Date(someNumber + 1);
+		Date d4 = new Date(someNumber - 1);
+		assertTrue("Comparing a date to itself did not answer zero", d1
+				.compareTo(d1) == 0);
+		assertTrue("Comparing equal dates did not answer zero", d1
+				.compareTo(d2) == 0);
+		assertTrue(
+				"date1.compareTo(date2), where date1 > date2, did not result in 1",
+				d1.compareTo(d4) == 1);
+		assertTrue(
+				"date1.compareTo(date2), where date1 < date2, did not result in -1",
+				d1.compareTo(d3) == -1);
+
+	}
+
+	/**
+	 * @tests java.util.Date#equals(java.lang.Object)
+	 */
+	public void test_equalsLjava_lang_Object() {
+		// Test for method boolean java.util.Date.equals(java.lang.Object)
+		Date d1 = new Date(0);
+		Date d2 = new Date(1900000);
+		Date d3 = new Date(1900000);
+		assertTrue("Equality test failed", d2.equals(d3));
+		assertTrue("Equality test failed", !d1.equals(d2));
+	}
+
+	/**
+	 * @tests java.util.Date#getDate()
+	 */
+	public void test_getDate() {
+		// Test for method int java.util.Date.getDate()
+		Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9)
+				.getTime();
+		assertTrue("Returned incorrect date", d.getDate() == 13);
+	}
+
+	/**
+	 * @tests java.util.Date#getDay()
+	 */
+	public void test_getDay() {
+		// Test for method int java.util.Date.getDay()
+		Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9)
+				.getTime();
+		assertTrue("Returned incorrect day", d.getDay() == 2);
+	}
+
+	/**
+	 * @tests java.util.Date#getHours()
+	 */
+	public void test_getHours() {
+		// Test for method int java.util.Date.getHours()
+		Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9)
+				.getTime();
+		assertTrue("Returned incorrect hours", d.getHours() == 19);
+	}
+
+	/**
+	 * @tests java.util.Date#getMinutes()
+	 */
+	public void test_getMinutes() {
+		// Test for method int java.util.Date.getMinutes()
+		Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9)
+				.getTime();
+		assertTrue("Returned incorrect minutes", d.getMinutes() == 9);
+	}
+
+	/**
+	 * @tests java.util.Date#getMonth()
+	 */
+	public void test_getMonth() {
+		// Test for method int java.util.Date.getMonth()
+		Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9)
+				.getTime();
+		assertTrue("Returned incorrect month", d.getMonth() == 9);
+	}
+
+	/**
+	 * @tests java.util.Date#getSeconds()
+	 */
+	public void test_getSeconds() {
+		// Test for method int java.util.Date.getSeconds()
+		Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9)
+				.getTime();
+		assertTrue("Returned incorrect seconds", d.getSeconds() == 0);
+	}
+
+	/**
+	 * @tests java.util.Date#getTime()
+	 */
+	public void test_getTime() {
+		// Test for method long java.util.Date.getTime()
+		Date d1 = new Date(0);
+		Date d2 = new Date(1900000);
+		assertTrue("Returned incorrect time", d2.getTime() == 1900000);
+		assertTrue("Returned incorrect time", d1.getTime() == 0);
+	}
+
+	/**
+	 * @tests java.util.Date#getTimezoneOffset()
+	 */
+	public void test_getTimezoneOffset() {
+		// Test for method int java.util.Date.getTimezoneOffset()
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * @tests java.util.Date#getYear()
+	 */
+	public void test_getYear() {
+		// Test for method int java.util.Date.getYear()
+		Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9)
+				.getTime();
+		assertTrue("Returned incorrect year", d.getYear() == 98);
+	}
+
+	/**
+	 * @tests java.util.Date#hashCode()
+	 */
+	public void test_hashCode() {
+		// Test for method int java.util.Date.hashCode()
+		Date d1 = new Date(0);
+		Date d2 = new Date(1900000);
+		assertTrue("Returned incorrect hash", d2.hashCode() == 1900000);
+		assertTrue("Returned incorrect hash", d1.hashCode() == 0);
+	}
+
+	/**
+	 * @tests java.util.Date#parse(java.lang.String)
+	 */
+	public void test_parseLjava_lang_String() {
+		// Test for method long java.util.Date.parse(java.lang.String)
+		Date d = new Date(Date.parse("13 October 1998"));
+		GregorianCalendar cal = new GregorianCalendar();
+		cal.setTime(d);
+		assertTrue("Parsed incorrect month", cal.get(Calendar.MONTH) == 9);
+		assertTrue("Parsed incorrect year", cal.get(Calendar.YEAR) == 1998);
+		assertTrue("Parsed incorrect date", cal.get(Calendar.DATE) == 13);
+
+		d = new Date(Date.parse("Jan-12 1999"));
+		assertTrue("Wrong parsed date 1", d.equals(new GregorianCalendar(1999,
+				0, 12).getTime()));
+		d = new Date(Date.parse("Jan12-1999"));
+		assertTrue("Wrong parsed date 2", d.equals(new GregorianCalendar(1999,
+				0, 12).getTime()));
+		d = new Date(Date.parse("Jan12 69-1"));
+		cal.setTimeZone(TimeZone.getTimeZone("GMT"));
+		cal.clear();
+		cal.set(1969, Calendar.JANUARY, 12, 1, 0);
+		assertTrue("Wrong parsed date 3", d.equals(cal.getTime()));
+		d = new Date(Date.parse("6:45:13 3/2/1200 MST"));
+		cal.setTimeZone(TimeZone.getTimeZone("MST"));
+		cal.clear();
+		cal.set(1200, 2, 2, 6, 45, 13);
+		assertTrue("Wrong parsed date 4", d.equals(cal.getTime()));
+		d = new Date(Date.parse("Mon, 22 Nov 1999 12:52:06 GMT"));
+		cal.setTimeZone(TimeZone.getTimeZone("GMT"));
+		cal.clear();
+		cal.set(1999, Calendar.NOVEMBER, 22, 12, 52, 06);
+		assertTrue("Wrong parsed date 5", d.equals(cal.getTime()));
+	}
+
+	/**
+	 * @tests java.util.Date#setDate(int)
+	 */
+	public void test_setDateI() {
+		// Test for method void java.util.Date.setDate(int)
+		Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9)
+				.getTime();
+		d.setDate(23);
+		assertTrue("Set incorrect date", d.getDate() == 23);
+	}
+
+	/**
+	 * @tests java.util.Date#setHours(int)
+	 */
+	public void test_setHoursI() {
+		// Test for method void java.util.Date.setHours(int)
+		Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9)
+				.getTime();
+		d.setHours(23);
+		assertTrue("Set incorrect hours", d.getHours() == 23);
+	}
+
+	/**
+	 * @tests java.util.Date#setMinutes(int)
+	 */
+	public void test_setMinutesI() {
+		// Test for method void java.util.Date.setMinutes(int)
+		Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9)
+				.getTime();
+		d.setMinutes(45);
+		assertTrue("Set incorrect mins", d.getMinutes() == 45);
+	}
+
+	/**
+	 * @tests java.util.Date#setMonth(int)
+	 */
+	public void test_setMonthI() {
+		// Test for method void java.util.Date.setMonth(int)
+		Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9)
+				.getTime();
+		d.setMonth(0);
+		assertTrue("Set incorrect month", d.getMonth() == 0);
+	}
+
+	/**
+	 * @tests java.util.Date#setSeconds(int)
+	 */
+	public void test_setSecondsI() {
+		// Test for method void java.util.Date.setSeconds(int)
+		Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9)
+				.getTime();
+		d.setSeconds(13);
+		assertTrue("Set incorrect seconds", d.getSeconds() == 13);
+	}
+
+	/**
+	 * @tests java.util.Date#setTime(long)
+	 */
+	public void test_setTimeJ() {
+		// Test for method void java.util.Date.setTime(long)
+		Date d1 = new Date(0);
+		Date d2 = new Date(1900000);
+		d1.setTime(900);
+		d2.setTime(890000);
+		assertTrue("Returned incorrect time", d2.getTime() == 890000);
+		assertTrue("Returned incorrect time", d1.getTime() == 900);
+	}
+
+	/**
+	 * @tests java.util.Date#setYear(int)
+	 */
+	public void test_setYearI() {
+		// Test for method void java.util.Date.setYear(int)
+		Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9)
+				.getTime();
+		d.setYear(8);
+		assertTrue("Set incorrect year", d.getYear() == 8);
+	}
+
+	/**
+	 * @tests java.util.Date#toGMTString()
+	 */
+	public void test_toGMTString() {
+		// Test for method java.lang.String java.util.Date.toGMTString()
+		assertTrue("Did not convert epoch to GMT string correctly", new Date(0)
+				.toGMTString().equals("1 Jan 1970 00:00:00 GMT"));
+		assertTrue("Did not convert epoch + 1yr to GMT string correctly",
+				new Date((long) 365 * 24 * 60 * 60 * 1000).toGMTString()
+						.equals("1 Jan 1971 00:00:00 GMT"));
+	}
+
+	/**
+	 * @tests java.util.Date#toString()
+	 */
+	public void test_toString() {
+		// Test for method java.lang.String java.util.Date.toString()
+		Calendar cal = Calendar.getInstance();
+		cal.set(Calendar.DATE, 1);
+		cal.set(Calendar.MONTH, Calendar.JANUARY);
+		cal.set(Calendar.YEAR, 1970);
+		cal.set(Calendar.HOUR_OF_DAY, 0);
+		cal.set(Calendar.MINUTE, 0);
+		cal.set(Calendar.SECOND, 0);
+		Date d = cal.getTime();
+		String result = d.toString();
+		assertTrue("Incorrect result: " + d, result
+				.startsWith("Thu Jan 01 00:00:00")
+				&& result.endsWith("1970"));
+
+		TimeZone tz = TimeZone.getDefault();
+		TimeZone.setDefault(TimeZone.getTimeZone("EST"));
+		try {
+			Date d1 = new Date(0);
+			assertTrue("Returned incorrect string: " + d1, d1.toString()
+					.equals("Wed Dec 31 19:00:00 EST 1969"));
+		} finally {
+			TimeZone.setDefault(tz);
+		}
+	}
+
+	/**
+	 * @tests java.util.Date#UTC(int, int, int, int, int, int)
+	 */
+	public void test_UTCIIIIII() {
+		// Test for method long java.util.Date.UTC(int, int, int, int, int, int)
+		assertTrue("Returned incorrect UTC value for epoch", Date.UTC(70, 0, 1,
+				0, 0, 0) == (long) 0);
+		assertTrue("Returned incorrect UTC value for epoch +1yr", Date.UTC(71,
+				0, 1, 0, 0, 0) == (long) 365 * 24 * 60 * 60 * 1000);
+	}
+
+	/**
+	 * 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/EmptyStackExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EmptyStackExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EmptyStackExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EmptyStackExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,61 @@
+/* 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 EmptyStackExceptionTest extends junit.framework.TestCase {
+
+	static Object[] objArray = new Object[10];
+	Stack s;
+	
+	{
+		for (int counter = 0; counter < objArray.length; counter++)
+			objArray[counter] = new Integer(counter);
+	}
+
+	/**
+	 * @tests java.util.EmptyStackException#EmptyStackException()
+	 */
+	public void test_Constructor() {
+		// Test for method java.util.EmptyStackException()
+		try {
+			for (int counter = 0; counter < objArray.length + 1; counter++)
+				s.pop();
+		} catch (EmptyStackException e) {
+			return;
+		}
+		fail("Expected EmptyStackException not thrown");
+	}
+
+	/**
+	 * 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();
+		for (int counter = 0; counter < objArray.length; counter++)
+			s.push(objArray[counter]);
+	}
+
+	/**
+	 * 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/EventObjectTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EventObjectTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EventObjectTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/EventObjectTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,68 @@
+/* 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.EventObject;
+
+public class EventObjectTest extends junit.framework.TestCase {
+
+	Object myObject;
+
+	EventObject myEventObject;
+
+	/**
+	 * @tests java.util.EventObject#EventObject(java.lang.Object)
+	 */
+	public void test_ConstructorLjava_lang_Object() {
+		// Test for method java.util.EventObject(java.lang.Object)
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * @tests java.util.EventObject#getSource()
+	 */
+	public void test_getSource() {
+		// Test for method java.lang.Object java.util.EventObject.getSource()
+		assertTrue("Wrong source returned",
+				myEventObject.getSource() == myObject);
+	}
+
+	/**
+	 * @tests java.util.EventObject#toString()
+	 */
+	public void test_toString() {
+		// Test for method java.lang.String java.util.EventObject.toString()
+		assertTrue("Incorrect toString returned: " + myEventObject.toString(),
+				myEventObject.toString().indexOf(
+						"java.util.EventObject[source=java.lang.Object@") == 0);
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+		myObject = new Object();
+		myEventObject = new EventObject(myObject);
+	}
+
+	/**
+	 * 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/GregorianCalendarTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,556 @@
+/* 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.BitSet;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.TimeZone;
+import java.util.Vector;
+
+public class GregorianCalendarTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.util.GregorianCalendar#GregorianCalendar()
+	 */
+	public void test_Constructor() {
+		// Test for method java.util.GregorianCalendar()
+		assertTrue("Constructed incorrect calendar", (new GregorianCalendar()
+				.isLenient()));
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#GregorianCalendar(int, int, int)
+	 */
+	public void test_ConstructorIII() {
+		// Test for method java.util.GregorianCalendar(int, int, int)
+		GregorianCalendar gc = new GregorianCalendar(1972, Calendar.OCTOBER, 13);
+		assertTrue("Incorrect calendar constructed 1",
+				gc.get(Calendar.YEAR) == 1972);
+		assertTrue("Incorrect calendar constructed 2",
+				gc.get(Calendar.MONTH) == Calendar.OCTOBER);
+		assertTrue("Incorrect calendar constructed 3", gc
+				.get(Calendar.DAY_OF_MONTH) == 13);
+		assertTrue("Incorrect calendar constructed 4", gc.getTimeZone().equals(
+				TimeZone.getDefault()));
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#GregorianCalendar(int, int, int, int,
+	 *        int)
+	 */
+	public void test_ConstructorIIIII() {
+		// Test for method java.util.GregorianCalendar(int, int, int, int, int)
+		GregorianCalendar gc = new GregorianCalendar(1972, Calendar.OCTOBER,
+				13, 19, 9);
+		assertTrue("Incorrect calendar constructed",
+				gc.get(Calendar.YEAR) == 1972);
+		assertTrue("Incorrect calendar constructed",
+				gc.get(Calendar.MONTH) == Calendar.OCTOBER);
+		assertTrue("Incorrect calendar constructed", gc
+				.get(Calendar.DAY_OF_MONTH) == 13);
+		assertTrue("Incorrect calendar constructed", gc.get(Calendar.HOUR) == 7);
+		assertTrue("Incorrect calendar constructed",
+				gc.get(Calendar.AM_PM) == 1);
+		assertTrue("Incorrect calendar constructed",
+				gc.get(Calendar.MINUTE) == 9);
+		assertTrue("Incorrect calendar constructed", gc.getTimeZone().equals(
+				TimeZone.getDefault()));
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#GregorianCalendar(int, int, int, int,
+	 *        int, int)
+	 */
+	public void test_ConstructorIIIIII() {
+		// Test for method java.util.GregorianCalendar(int, int, int, int, int,
+		// int)
+		GregorianCalendar gc = new GregorianCalendar(1972, Calendar.OCTOBER,
+				13, 19, 9, 59);
+		assertTrue("Incorrect calendar constructed",
+				gc.get(Calendar.YEAR) == 1972);
+		assertTrue("Incorrect calendar constructed",
+				gc.get(Calendar.MONTH) == Calendar.OCTOBER);
+		assertTrue("Incorrect calendar constructed", gc
+				.get(Calendar.DAY_OF_MONTH) == 13);
+		assertTrue("Incorrect calendar constructed", gc.get(Calendar.HOUR) == 7);
+		assertTrue("Incorrect calendar constructed",
+				gc.get(Calendar.AM_PM) == 1);
+		assertTrue("Incorrect calendar constructed",
+				gc.get(Calendar.MINUTE) == 9);
+		assertTrue("Incorrect calendar constructed",
+				gc.get(Calendar.SECOND) == 59);
+		assertTrue("Incorrect calendar constructed", gc.getTimeZone().equals(
+				TimeZone.getDefault()));
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#GregorianCalendar(java.util.Locale)
+	 */
+	public void test_ConstructorLjava_util_Locale() {
+		// Test for method java.util.GregorianCalendar(java.util.Locale)
+		Date date = new Date();
+		GregorianCalendar gcJapan = new GregorianCalendar(Locale.JAPAN);
+		gcJapan.setTime(date);
+		GregorianCalendar gcJapan2 = new GregorianCalendar(Locale.JAPAN);
+		gcJapan2.setTime(date);
+		GregorianCalendar gcItaly = new GregorianCalendar(Locale.ITALY);
+		gcItaly.setTime(date);
+		assertTrue("Locales not created correctly", gcJapan.equals(gcJapan2)
+				&& !gcJapan.equals(gcItaly));
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#GregorianCalendar(java.util.TimeZone)
+	 */
+	public void test_ConstructorLjava_util_TimeZone() {
+		// Test for method java.util.GregorianCalendar(java.util.TimeZone)
+		Date date = new Date();
+		TimeZone.getDefault();
+		GregorianCalendar gc1 = new GregorianCalendar(TimeZone
+				.getTimeZone("EST"));
+		gc1.setTime(date);
+		GregorianCalendar gc2 = new GregorianCalendar(TimeZone
+				.getTimeZone("CST"));
+		gc2.setTime(date);
+		// CST is 1 hour before EST, add 1 to the CST time and convert to 0-12
+		// value
+		assertTrue("Incorrect calendar returned",
+				gc1.get(Calendar.HOUR) == ((gc2.get(Calendar.HOUR) + 1) % 12));
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#GregorianCalendar(java.util.TimeZone,
+	 *        java.util.Locale)
+	 */
+	public void test_ConstructorLjava_util_TimeZoneLjava_util_Locale() {
+		// Test for method java.util.GregorianCalendar(java.util.TimeZone,
+		// java.util.Locale)
+		Date date = new Date();
+		TimeZone.getDefault();
+		GregorianCalendar gc1 = new GregorianCalendar(TimeZone
+				.getTimeZone("EST"), Locale.JAPAN);
+		gc1.setTime(date);
+		GregorianCalendar gc2 = new GregorianCalendar(TimeZone
+				.getTimeZone("EST"), Locale.JAPAN);
+		gc2.setTime(date);
+		GregorianCalendar gc3 = new GregorianCalendar(TimeZone
+				.getTimeZone("CST"), Locale.ITALY);
+		gc3.setTime(date);
+		// CST is 1 hour before EST, add 1 to the CST time and convert to 0-12
+		// value
+		assertTrue("Incorrect calendar returned",
+				gc1.get(Calendar.HOUR) == ((gc3.get(Calendar.HOUR) + 1) % 12));
+		assertTrue("Locales not created correctly", gc1.equals(gc2)
+				&& !gc1.equals(gc3));
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#add(int, int)
+	 */
+	public void test_addII() {
+		// Test for method void java.util.GregorianCalendar.add(int, int)
+		GregorianCalendar gc1 = new GregorianCalendar(1998, 11, 6);
+		gc1.add(GregorianCalendar.YEAR, 1);
+		assertTrue("Add failed to Increment",
+				gc1.get(GregorianCalendar.YEAR) == 1999);
+
+		gc1 = new GregorianCalendar(1999, Calendar.JULY, 31);
+		gc1.add(Calendar.MONTH, 7);
+		assertTrue("Wrong result year 1", gc1.get(Calendar.YEAR) == 2000);
+		assertTrue("Wrong result month 1",
+				gc1.get(Calendar.MONTH) == Calendar.FEBRUARY);
+		assertTrue("Wrong result date 1", gc1.get(Calendar.DATE) == 29);
+
+		gc1.add(Calendar.YEAR, -1);
+		assertTrue("Wrong result year 2", gc1.get(Calendar.YEAR) == 1999);
+		assertTrue("Wrong result month 2",
+				gc1.get(Calendar.MONTH) == Calendar.FEBRUARY);
+		assertTrue("Wrong result date 2", gc1.get(Calendar.DATE) == 28);
+
+		gc1 = new GregorianCalendar(TimeZone.getTimeZone("EST"));
+		gc1.set(1999, Calendar.APRIL, 3, 16, 0); // day before DST change
+		gc1.add(Calendar.MILLISECOND, 24 * 60 * 60 * 1000);
+		assertTrue("Wrong time after MILLISECOND change", gc1
+				.get(Calendar.HOUR_OF_DAY) == 17);
+		gc1.set(1999, Calendar.APRIL, 3, 16, 0); // day before DST change
+		gc1.add(Calendar.SECOND, 24 * 60 * 60);
+		assertTrue("Wrong time after SECOND change", gc1
+				.get(Calendar.HOUR_OF_DAY) == 17);
+		gc1.set(1999, Calendar.APRIL, 3, 16, 0); // day before DST change
+		gc1.add(Calendar.MINUTE, 24 * 60);
+		assertTrue("Wrong time after MINUTE change", gc1
+				.get(Calendar.HOUR_OF_DAY) == 17);
+		gc1.set(1999, Calendar.APRIL, 3, 16, 0); // day before DST change
+		gc1.add(Calendar.HOUR, 24);
+		assertTrue("Wrong time after HOUR change", gc1
+				.get(Calendar.HOUR_OF_DAY) == 17);
+		gc1.set(1999, Calendar.APRIL, 3, 16, 0); // day before DST change
+		gc1.add(Calendar.HOUR_OF_DAY, 24);
+		assertTrue("Wrong time after HOUR_OF_DAY change", gc1
+				.get(Calendar.HOUR_OF_DAY) == 17);
+
+		gc1.set(1999, Calendar.APRIL, 3, 16, 0); // day before DST change
+		gc1.add(Calendar.AM_PM, 2);
+		assertTrue("Wrong time after AM_PM change", gc1
+				.get(Calendar.HOUR_OF_DAY) == 16);
+		gc1.set(1999, Calendar.APRIL, 3, 16, 0); // day before DST change
+		gc1.add(Calendar.DATE, 1);
+		assertTrue("Wrong time after DATE change", gc1
+				.get(Calendar.HOUR_OF_DAY) == 16);
+		gc1.set(1999, Calendar.APRIL, 3, 16, 0); // day before DST change
+		gc1.add(Calendar.DAY_OF_YEAR, 1);
+		assertTrue("Wrong time after DAY_OF_YEAR change", gc1
+				.get(Calendar.HOUR_OF_DAY) == 16);
+		gc1.set(1999, Calendar.APRIL, 3, 16, 0); // day before DST change
+		gc1.add(Calendar.DAY_OF_WEEK, 1);
+		assertTrue("Wrong time after DAY_OF_WEEK change", gc1
+				.get(Calendar.HOUR_OF_DAY) == 16);
+		gc1.set(1999, Calendar.APRIL, 3, 16, 0); // day before DST change
+		gc1.add(Calendar.WEEK_OF_YEAR, 1);
+		assertTrue("Wrong time after WEEK_OF_YEAR change", gc1
+				.get(Calendar.HOUR_OF_DAY) == 16);
+		gc1.set(1999, Calendar.APRIL, 3, 16, 0); // day before DST change
+		gc1.add(Calendar.WEEK_OF_MONTH, 1);
+		assertTrue("Wrong time after WEEK_OF_MONTH change", gc1
+				.get(Calendar.HOUR_OF_DAY) == 16);
+		gc1.set(1999, Calendar.APRIL, 3, 16, 0); // day before DST change
+		gc1.add(Calendar.DAY_OF_WEEK_IN_MONTH, 1);
+		assertTrue("Wrong time after DAY_OF_WEEK_IN_MONTH change", gc1
+				.get(Calendar.HOUR_OF_DAY) == 16);
+
+		gc1.clear();
+		gc1.set(2000, Calendar.APRIL, 1, 23, 0);
+		gc1.add(Calendar.DATE, 1);
+		assertTrue("Wrong time after DATE change near DST boundary", gc1
+				.get(Calendar.MONTH) == Calendar.APRIL
+				&& gc1.get(Calendar.DATE) == 2
+				&& gc1.get(Calendar.HOUR_OF_DAY) == 23);
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#equals(java.lang.Object)
+	 */
+	public void test_equalsLjava_lang_Object() {
+		// Test for method boolean
+		// java.util.GregorianCalendar.equals(java.lang.Object)
+		GregorianCalendar gc1 = new GregorianCalendar(1998, 11, 6);
+		GregorianCalendar gc2 = new GregorianCalendar(2000, 11, 6);
+		GregorianCalendar gc3 = new GregorianCalendar(1998, 11, 6);
+		assertTrue("Equality check failed", gc1.equals(gc3));
+		assertTrue("Equality check failed", !gc1.equals(gc2));
+		gc3.setGregorianChange(new Date());
+		assertTrue("Different gregorian change", !gc1.equals(gc3));
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#getActualMaximum(int)
+	 */
+	public void test_getActualMaximumI() {
+		// Test for method int java.util.GregorianCalendar.getActualMaximum(int)
+		GregorianCalendar gc1 = new GregorianCalendar(1900, 1, 1);
+		GregorianCalendar gc2 = new GregorianCalendar(1996, 1, 1);
+		GregorianCalendar gc3 = new GregorianCalendar(1997, 1, 1);
+		GregorianCalendar gc4 = new GregorianCalendar(2000, 1, 1);
+		GregorianCalendar gc5 = new GregorianCalendar(2000, 9, 9);
+		GregorianCalendar gc6 = new GregorianCalendar(2000, 3, 3);
+		assertTrue("Wrong actual maximum value for DAY_OF_MONTH for Feb 1900",
+				gc1.getActualMaximum(Calendar.DAY_OF_MONTH) == 28);
+		assertTrue("Wrong actual maximum value for DAY_OF_MONTH for Feb 1996",
+				gc2.getActualMaximum(Calendar.DAY_OF_MONTH) == 29);
+		assertTrue("Wrong actual maximum value for DAY_OF_MONTH for Feb 1998",
+				gc3.getActualMaximum(Calendar.DAY_OF_MONTH) == 28);
+		assertTrue("Wrong actual maximum value for DAY_OF_MONTH for Feb 2000",
+				gc4.getActualMaximum(Calendar.DAY_OF_MONTH) == 29);
+		assertTrue("Wrong actual maximum value for DAY_OF_MONTH for Oct 2000",
+				gc5.getActualMaximum(Calendar.DAY_OF_MONTH) == 31);
+		assertTrue("Wrong actual maximum value for DAY_OF_MONTH for Apr 2000",
+				gc6.getActualMaximum(Calendar.DAY_OF_MONTH) == 30);
+		assertTrue("Wrong actual maximum value for MONTH", gc1
+				.getActualMaximum(Calendar.MONTH) == Calendar.DECEMBER);
+		assertTrue("Wrong actual maximum value for HOUR_OF_DAY", gc1
+				.getActualMaximum(Calendar.HOUR_OF_DAY) == 23);
+		assertTrue("Wrong actual maximum value for HOUR", gc1
+				.getActualMaximum(Calendar.HOUR) == 11);
+		assertTrue("Wrong actual maximum value for DAY_OF_WEEK_IN_MONTH", gc6
+				.getActualMaximum(Calendar.DAY_OF_WEEK_IN_MONTH) == 4);
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#getActualMinimum(int)
+	 */
+	public void test_getActualMinimumI() {
+		// Test for method int java.util.GregorianCalendar.getActualMinimum(int)
+		GregorianCalendar gc1 = new GregorianCalendar(1900, 1, 1);
+		new GregorianCalendar(1996, 1, 1);
+		new GregorianCalendar(1997, 1, 1);
+		new GregorianCalendar(2000, 1, 1);
+		new GregorianCalendar(2000, 9, 9);
+		GregorianCalendar gc6 = new GregorianCalendar(2000, 3, 3);
+		assertTrue("Wrong actual minimum value for DAY_OF_MONTH for Feb 1900",
+				gc1.getActualMinimum(Calendar.DAY_OF_MONTH) == 1);
+		assertTrue("Wrong actual minimum value for MONTH", gc1
+				.getActualMinimum(Calendar.MONTH) == Calendar.JANUARY);
+		assertTrue("Wrong actual minimum value for HOUR_OF_DAY", gc1
+				.getActualMinimum(Calendar.HOUR_OF_DAY) == 0);
+		assertTrue("Wrong actual minimum value for HOUR", gc1
+				.getActualMinimum(Calendar.HOUR) == 0);
+		assertTrue("Wrong actual minimum value for DAY_OF_WEEK_IN_MONTH", gc6
+				.getActualMinimum(Calendar.DAY_OF_WEEK_IN_MONTH) == -1);
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#getGreatestMinimum(int)
+	 */
+	public void test_getGreatestMinimumI() {
+		// Test for method int
+		// java.util.GregorianCalendar.getGreatestMinimum(int)
+		GregorianCalendar gc = new GregorianCalendar();
+		assertTrue("Wrong greatest minimum value for DAY_OF_MONTH", gc
+				.getGreatestMinimum(Calendar.DAY_OF_MONTH) == 1);
+		assertTrue("Wrong greatest minimum value for MONTH", gc
+				.getGreatestMinimum(Calendar.MONTH) == Calendar.JANUARY);
+		assertTrue("Wrong greatest minimum value for HOUR_OF_DAY", gc
+				.getGreatestMinimum(Calendar.HOUR_OF_DAY) == 0);
+		assertTrue("Wrong greatest minimum value for HOUR", gc
+				.getGreatestMinimum(Calendar.HOUR) == 0);
+
+		BitSet result = new BitSet();
+		int[] min = { 0, 1, 0, 1, 0, 1, 1, 1, -1, 0, 0, 0, 0, 0, 0, -43200000,
+				0 };
+		for (int i = 0; i < min.length; i++) {
+			if (gc.getGreatestMinimum(i) != min[i])
+				result.set(i);
+		}
+		assertTrue("Wrong greatest min for " + result, result.length() == 0);
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#getGregorianChange()
+	 */
+	public void test_getGregorianChange() {
+		// Test for method java.util.Date
+		// java.util.GregorianCalendar.getGregorianChange()
+		GregorianCalendar gc = new GregorianCalendar();
+		GregorianCalendar returnedChange = new GregorianCalendar(TimeZone
+				.getTimeZone("EST"));
+		returnedChange.setTime(gc.getGregorianChange());
+		assertTrue("Returned incorrect year",
+				returnedChange.get(Calendar.YEAR) == 1582);
+		assertTrue("Returned incorrect month", returnedChange
+				.get(Calendar.MONTH) == Calendar.OCTOBER);
+		assertTrue("Returned incorrect day of month", returnedChange
+				.get(Calendar.DAY_OF_MONTH) == 4);
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#getLeastMaximum(int)
+	 */
+	public void test_getLeastMaximumI() {
+		// Test for method int java.util.GregorianCalendar.getLeastMaximum(int)
+		GregorianCalendar gc = new GregorianCalendar();
+		assertTrue("Wrong least maximum value for DAY_OF_MONTH", gc
+				.getLeastMaximum(Calendar.DAY_OF_MONTH) == 28);
+		assertTrue("Wrong least maximum value for MONTH", gc
+				.getLeastMaximum(Calendar.MONTH) == Calendar.DECEMBER);
+		assertTrue("Wrong least maximum value for HOUR_OF_DAY", gc
+				.getLeastMaximum(Calendar.HOUR_OF_DAY) == 23);
+		assertTrue("Wrong least maximum value for HOUR", gc
+				.getLeastMaximum(Calendar.HOUR) == 11);
+
+		BitSet result = new BitSet();
+		Vector values = new Vector();
+		int[] max = { 1, 292269054, 11, 52, 4, 28, 365, 7, 4, 1, 11, 23, 59,
+				59, 999, 43200000, 3600000 };
+		for (int i = 0; i < max.length; i++) {
+			if (gc.getLeastMaximum(i) != max[i]) {
+				result.set(i);
+				values.add(new Integer(gc.getLeastMaximum(i)));
+			}
+		}
+		assertTrue("Wrong least max for " + result + " = " + values, result
+				.length() == 0);
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#getMaximum(int)
+	 */
+	public void test_getMaximumI() {
+		// Test for method int java.util.GregorianCalendar.getMaximum(int)
+		GregorianCalendar gc = new GregorianCalendar();
+		assertTrue("Wrong maximum value for DAY_OF_MONTH", gc
+				.getMaximum(Calendar.DAY_OF_MONTH) == 31);
+		assertTrue("Wrong maximum value for MONTH", gc
+				.getMaximum(Calendar.MONTH) == Calendar.DECEMBER);
+		assertTrue("Wrong maximum value for HOUR_OF_DAY", gc
+				.getMaximum(Calendar.HOUR_OF_DAY) == 23);
+		assertTrue("Wrong maximum value for HOUR",
+				gc.getMaximum(Calendar.HOUR) == 11);
+
+		BitSet result = new BitSet();
+		Vector values = new Vector();
+		int[] max = { 1, 292278994, 11, 53, 6, 31, 366, 7, 6, 1, 11, 23, 59,
+				59, 999, 43200000, 3600000 };
+		for (int i = 0; i < max.length; i++) {
+			if (gc.getMaximum(i) != max[i]) {
+				result.set(i);
+				values.add(new Integer(gc.getMaximum(i)));
+			}
+		}
+		assertTrue("Wrong max for " + result + " = " + values,
+				result.length() == 0);
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#getMinimum(int)
+	 */
+	public void test_getMinimumI() {
+		// Test for method int java.util.GregorianCalendar.getMinimum(int)
+		GregorianCalendar gc = new GregorianCalendar();
+		assertTrue("Wrong minimum value for DAY_OF_MONTH", gc
+				.getMinimum(Calendar.DAY_OF_MONTH) == 1);
+		assertTrue("Wrong minimum value for MONTH", gc
+				.getMinimum(Calendar.MONTH) == Calendar.JANUARY);
+		assertTrue("Wrong minimum value for HOUR_OF_DAY", gc
+				.getMinimum(Calendar.HOUR_OF_DAY) == 0);
+		assertTrue("Wrong minimum value for HOUR",
+				gc.getMinimum(Calendar.HOUR) == 0);
+
+		BitSet result = new BitSet();
+		int[] min = { 0, 1, 0, 1, 0, 1, 1, 1, -1, 0, 0, 0, 0, 0, 0, -43200000,
+				0 };
+		for (int i = 0; i < min.length; i++) {
+			if (gc.getMinimum(i) != min[i])
+				result.set(i);
+		}
+		assertTrue("Wrong min for " + result, result.length() == 0);
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#isLeapYear(int)
+	 */
+	public void test_isLeapYearI() {
+		// Test for method boolean java.util.GregorianCalendar.isLeapYear(int)
+		GregorianCalendar gc = new GregorianCalendar(1998, 11, 6);
+		assertTrue("Returned incorrect value for leap year", !gc
+				.isLeapYear(1998));
+		assertTrue("Returned incorrect value for leap year", gc
+				.isLeapYear(2000));
+
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#roll(int, int)
+	 */
+	public void test_rollII() {
+		// Test for method void java.util.GregorianCalendar.roll(int, int)
+		GregorianCalendar gc = new GregorianCalendar(1972, Calendar.OCTOBER, 8,
+				2, 5, 0);
+		gc.roll(Calendar.DAY_OF_MONTH, -1);
+		assertTrue("Failed to roll DAY_OF_MONTH down by 1", gc
+				.equals(new GregorianCalendar(1972, Calendar.OCTOBER, 7, 2, 5,
+						0)));
+		gc = new GregorianCalendar(1972, Calendar.OCTOBER, 8, 2, 5, 0);
+		gc.roll(Calendar.DAY_OF_MONTH, 25);
+		assertTrue("Failed to roll DAY_OF_MONTH up by 25", gc
+				.equals(new GregorianCalendar(1972, Calendar.OCTOBER, 2, 2, 5,
+						0)));
+		gc = new GregorianCalendar(1972, Calendar.OCTOBER, 8, 2, 5, 0);
+		gc.roll(Calendar.DAY_OF_MONTH, -10);
+		assertTrue("Failed to roll DAY_OF_MONTH down by 10", gc
+				.equals(new GregorianCalendar(1972, Calendar.OCTOBER, 29, 2, 5,
+						0)));
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#roll(int, boolean)
+	 */
+	public void test_rollIZ() {
+		// Test for method void java.util.GregorianCalendar.roll(int, boolean)
+		GregorianCalendar gc = new GregorianCalendar(1972, Calendar.OCTOBER,
+				13, 19, 9, 59);
+		gc.roll(Calendar.DAY_OF_MONTH, false);
+		assertTrue("Failed to roll day_of_month down", gc
+				.equals(new GregorianCalendar(1972, Calendar.OCTOBER, 12, 19,
+						9, 59)));
+		gc = new GregorianCalendar(1972, Calendar.OCTOBER, 13, 19, 9, 59);
+		gc.roll(Calendar.DAY_OF_MONTH, true);
+		assertTrue("Failed to roll day_of_month up", gc
+				.equals(new GregorianCalendar(1972, Calendar.OCTOBER, 14, 19,
+						9, 59)));
+		gc = new GregorianCalendar(1972, Calendar.OCTOBER, 31, 19, 9, 59);
+		gc.roll(Calendar.DAY_OF_MONTH, true);
+		assertTrue("Failed to roll day_of_month up", gc
+				.equals(new GregorianCalendar(1972, Calendar.OCTOBER, 1, 19, 9,
+						59)));
+
+		GregorianCalendar cal = new GregorianCalendar();
+		int result;
+		try {
+			cal.roll(Calendar.ZONE_OFFSET, true);
+			result = 0;
+		} catch (IllegalArgumentException e) {
+			result = 1;
+		}
+		assertTrue("ZONE_OFFSET roll", result == 1);
+		try {
+			cal.roll(Calendar.DST_OFFSET, true);
+			result = 0;
+		} catch (IllegalArgumentException e) {
+			result = 1;
+		}
+		assertTrue("ZONE_OFFSET roll", result == 1);
+
+		cal.set(2004, Calendar.DECEMBER, 31, 5, 0, 0);
+		cal.roll(Calendar.WEEK_OF_YEAR, true);
+		assertTrue("Wrong year: " + cal.getTime(),
+				cal.get(Calendar.YEAR) == 2004);
+		assertTrue("Wrong month: " + cal.getTime(),
+				cal.get(Calendar.MONTH) == Calendar.JANUARY);
+		assertTrue("Wrong date: " + cal.getTime(), cal.get(Calendar.DATE) == 9);
+	}
+
+	/**
+	 * @tests java.util.GregorianCalendar#setGregorianChange(java.util.Date)
+	 */
+	public void test_setGregorianChangeLjava_util_Date() {
+		// Test for method void
+		// java.util.GregorianCalendar.setGregorianChange(java.util.Date)
+		GregorianCalendar gc1 = new GregorianCalendar(1582, Calendar.OCTOBER,
+				4, 0, 0);
+		GregorianCalendar gc2 = new GregorianCalendar(1972, Calendar.OCTOBER,
+				13, 0, 0);
+		gc1.setGregorianChange(gc2.getTime());
+		assertTrue("Returned incorrect value", gc2.getTime().equals(
+				gc1.getGregorianChange()));
+	}
+
+	/**
+	 * 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/HashMapTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,397 @@
+/* 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.AbstractMap;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import tests.support.Support_MapTest2;
+import tests.support.Support_UnmodifiableCollectionTest;
+
+public class HashMapTest extends junit.framework.TestCase {
+
+	HashMap hm;
+
+	final static int hmSize = 1000;
+
+	static Object[] objArray;
+
+	static Object[] objArray2;
+	{
+		objArray = new Object[hmSize];
+		objArray2 = new Object[hmSize];
+		for (int i = 0; i < objArray.length; i++) {
+			objArray[i] = new Integer(i);
+			objArray2[i] = objArray[i].toString();
+		}
+	}
+
+	/**
+	 * @tests java.util.HashMap#HashMap()
+	 */
+	public void test_Constructor() {
+		// Test for method java.util.HashMap()
+		new Support_MapTest2(new HashMap()).runTest();
+
+		HashMap hm2 = new HashMap();
+		assertTrue("Created incorrect HashMap", hm2.size() == 0);
+	}
+
+	/**
+	 * @tests java.util.HashMap#HashMap(int)
+	 */
+	public void test_ConstructorI() {
+		// Test for method java.util.HashMap(int)
+		HashMap hm2 = new HashMap(5);
+		assertTrue("Created incorrect HashMap", hm2.size() == 0);
+		try {
+			new HashMap(-1);
+		} catch (IllegalArgumentException e) {
+			return;
+		}
+		fail(
+				"Failed to throw IllegalArgumentException for initial capacity < 0");
+
+		HashMap empty = new HashMap(0);
+		assertTrue("Empty hashmap access", empty.get("nothing") == null);
+		empty.put("something", "here");
+		assertTrue("cannot get element", empty.get("something") == "here");
+	}
+
+	/**
+	 * @tests java.util.HashMap#HashMap(int, float)
+	 */
+	public void test_ConstructorIF() {
+		// Test for method java.util.HashMap(int, float)
+		HashMap hm2 = new HashMap(5, (float) 0.5);
+		assertTrue("Created incorrect HashMap", hm2.size() == 0);
+		try {
+			new HashMap(0, 0);
+		} catch (IllegalArgumentException e) {
+			return;
+		}
+		fail(
+				"Failed to throw IllegalArgumentException for initial load factor <= 0");
+
+		HashMap empty = new HashMap(0, 0.75f);
+		assertTrue("Empty hashtable access", empty.get("nothing") == null);
+		empty.put("something", "here");
+		assertTrue("cannot get element", empty.get("something") == "here");
+	}
+
+	/**
+	 * @tests java.util.HashMap#HashMap(java.util.Map)
+	 */
+	public void test_ConstructorLjava_util_Map() {
+		// Test for method java.util.HashMap(java.util.Map)
+		Map myMap = new TreeMap();
+		for (int counter = 0; counter < hmSize; counter++)
+			myMap.put(objArray2[counter], objArray[counter]);
+		HashMap hm2 = new HashMap(myMap);
+		for (int counter = 0; counter < hmSize; counter++)
+			assertTrue("Failed to construct correct HashMap", hm
+					.get(objArray2[counter]) == hm2.get(objArray2[counter]));
+	}
+
+	/**
+	 * @tests java.util.HashMap#clear()
+	 */
+	public void test_clear() {
+		// Test for method void java.util.HashMap.clear()
+		hm.clear();
+		assertTrue("Clear failed to reset size", hm.size() == 0);
+		for (int i = 0; i < hmSize; i++)
+			assertTrue("Failed to clear all elements",
+					hm.get(objArray2[i]) == null);
+
+	}
+
+	/**
+	 * @tests java.util.HashMap#clone()
+	 */
+	public void test_clone() {
+		// Test for method java.lang.Object java.util.HashMap.clone()
+		HashMap hm2 = (HashMap) hm.clone();
+		assertTrue("Clone answered equivalent HashMap", hm2 != hm);
+		for (int counter = 0; counter < hmSize; counter++)
+			assertTrue("Clone answered unequal HashMap", hm
+					.get(objArray2[counter]) == hm2.get(objArray2[counter]));
+
+		HashMap map = new HashMap();
+		map.put("key", "value");
+		// get the keySet() and values() on the original Map
+		Set keys = map.keySet();
+		Collection values = map.values();
+		assertTrue("values() does not work", values.iterator().next().equals(
+				"value"));
+		assertTrue("keySet() does not work", keys.iterator().next().equals(
+				"key"));
+		AbstractMap map2 = (AbstractMap) map.clone();
+		map2.put("key", "value2");
+		Collection values2 = map2.values();
+		assertTrue("values() is identical", values2 != values);
+		// values() and keySet() on the cloned() map should be different
+		assertTrue("values() was not cloned", values2.iterator().next().equals(
+				"value2"));
+		map2.clear();
+		map2.put("key2", "value3");
+		Set key2 = map2.keySet();
+		assertTrue("keySet() is identical", key2 != keys);
+		assertTrue("keySet() was not cloned", key2.iterator().next().equals(
+				"key2"));
+	}
+
+	/**
+	 * @tests java.util.HashMap#containsKey(java.lang.Object)
+	 */
+	public void test_containsKeyLjava_lang_Object() {
+		// Test for method boolean
+		// java.util.HashMap.containsKey(java.lang.Object)
+		assertTrue("Returned false for valid key", hm.containsKey(new Integer(
+				876).toString()));
+		assertTrue("Returned true for invalid key", !hm.containsKey("KKDKDKD"));
+
+		HashMap m = new HashMap();
+		m.put(null, "test");
+		assertTrue("Failed with null key", m.containsKey(null));
+		assertTrue("Failed with missing key matching null hash", !m
+				.containsKey(new Integer(0)));
+	}
+
+	/**
+	 * @tests java.util.HashMap#containsValue(java.lang.Object)
+	 */
+	public void test_containsValueLjava_lang_Object() {
+		// Test for method boolean
+		// java.util.HashMap.containsValue(java.lang.Object)
+		assertTrue("Returned false for valid value", hm
+				.containsValue(new Integer(875)));
+		assertTrue("Returned true for invalid valie", !hm
+				.containsValue(new Integer(-9)));
+	}
+
+	/**
+	 * @tests java.util.HashMap#entrySet()
+	 */
+	public void test_entrySet() {
+		// Test for method java.util.Set java.util.HashMap.entrySet()
+		Set s = hm.entrySet();
+		Iterator i = s.iterator();
+		assertTrue("Returned set of incorrect size", hm.size() == s.size());
+		while (i.hasNext()) {
+			Map.Entry m = (Map.Entry) i.next();
+			assertTrue("Returned incorrect entry set", hm.containsKey(m
+					.getKey())
+					&& hm.containsValue(m.getValue()));
+		}
+	}
+
+	/**
+	 * @tests java.util.HashMap#get(java.lang.Object)
+	 */
+	public void test_getLjava_lang_Object() {
+		// Test for method java.lang.Object
+		// java.util.HashMap.get(java.lang.Object)
+		assertTrue("Get returned non-null for non existent key",
+				hm.get("T") == null);
+		hm.put("T", "HELLO");
+		assertTrue("Get returned incorecct value for existing key", hm.get("T")
+				.equals("HELLO"));
+
+		HashMap m = new HashMap();
+		m.put(null, "test");
+		assertTrue("Failed with null key", m.get(null).equals("test"));
+		assertTrue("Failed with missing key matching null hash", m
+				.get(new Integer(0)) == null);
+	}
+
+	/**
+	 * @tests java.util.HashMap#isEmpty()
+	 */
+	public void test_isEmpty() {
+		// Test for method boolean java.util.HashMap.isEmpty()
+		assertTrue("Returned false for new map", new HashMap().isEmpty());
+		assertTrue("Returned true for non-empty", !hm.isEmpty());
+	}
+
+	/**
+	 * @tests java.util.HashMap#keySet()
+	 */
+	public void test_keySet() {
+		// Test for method java.util.Set java.util.HashMap.keySet()
+		Set s = hm.keySet();
+		assertTrue("Returned set of incorrect size()", s.size() == hm.size());
+		for (int i = 0; i < objArray.length; i++)
+			assertTrue("Returned set does not contain all keys", s
+					.contains(objArray[i].toString()));
+
+		HashMap m = new HashMap();
+		m.put(null, "test");
+		assertTrue("Failed with null key", m.keySet().contains(null));
+		assertTrue("Failed with null key", m.keySet().iterator().next() == null);
+
+		Map map = new HashMap(101);
+		map.put(new Integer(1), "1");
+		map.put(new Integer(102), "102");
+		map.put(new Integer(203), "203");
+		Iterator it = map.keySet().iterator();
+		Integer remove1 = (Integer) it.next();
+		it.hasNext();
+		it.remove();
+		Integer remove2 = (Integer) it.next();
+		it.remove();
+		ArrayList list = new ArrayList(Arrays.asList(new Integer[] {
+				new Integer(1), new Integer(102), new Integer(203) }));
+		list.remove(remove1);
+		list.remove(remove2);
+		assertTrue("Wrong result", it.next().equals(list.get(0)));
+		assertTrue("Wrong size", map.size() == 1);
+		assertTrue("Wrong contents", map.keySet().iterator().next().equals(
+				list.get(0)));
+
+		Map map2 = new HashMap(101);
+		map2.put(new Integer(1), "1");
+		map2.put(new Integer(4), "4");
+		Iterator it2 = map2.keySet().iterator();
+		Integer remove3 = (Integer) it2.next();
+		Integer next;
+		if (remove3.intValue() == 1)
+			next = new Integer(4);
+		else
+			next = new Integer(1);
+		it2.hasNext();
+		it2.remove();
+		assertTrue("Wrong result 2", it2.next().equals(next));
+		assertTrue("Wrong size 2", map2.size() == 1);
+		assertTrue("Wrong contents 2", map2.keySet().iterator().next().equals(
+				next));
+	}
+
+	/**
+	 * @tests java.util.HashMap#put(java.lang.Object, java.lang.Object)
+	 */
+	public void test_putLjava_lang_ObjectLjava_lang_Object() {
+		// Test for method java.lang.Object
+		// java.util.HashMap.put(java.lang.Object, java.lang.Object)
+		hm.put("KEY", "VALUE");
+		assertTrue("Failed to install key/value pair", hm.get("KEY").equals(
+				"VALUE"));
+
+		HashMap m = new HashMap();
+		m.put(new Short((short) 0), "short");
+		m.put(null, "test");
+		m.put(new Integer(0), "int");
+		assertTrue("Failed adding to bucket containing null", m.get(
+				new Short((short) 0)).equals("short"));
+		assertTrue("Failed adding to bucket containing null2", m.get(
+				new Integer(0)).equals("int"));
+	}
+
+	/**
+	 * @tests java.util.HashMap#putAll(java.util.Map)
+	 */
+	public void test_putAllLjava_util_Map() {
+		// Test for method void java.util.HashMap.putAll(java.util.Map)
+		HashMap hm2 = new HashMap();
+		hm2.putAll(hm);
+		for (int i = 0; i < 1000; i++)
+			assertTrue("Failed to clear all elements", hm2.get(
+					new Integer(i).toString()).equals((new Integer(i))));
+	}
+
+	/**
+	 * @tests java.util.HashMap#remove(java.lang.Object)
+	 */
+	public void test_removeLjava_lang_Object() {
+		// Test for method java.lang.Object
+		// java.util.HashMap.remove(java.lang.Object)
+		int size = hm.size();
+		Integer y = new Integer(9);
+		Integer x = ((Integer) hm.remove(y.toString()));
+		assertTrue("Remove returned incorrect value", x.equals(new Integer(9)));
+		assertTrue("Failed to remove given key", hm.get(new Integer(9)) == null);
+		assertTrue("Failed to decrement size", hm.size() == (size - 1));
+		assertTrue("Remove of non-existent key returned non-null", hm
+				.remove("LCLCLC") == null);
+
+		HashMap m = new HashMap();
+		m.put(null, "test");
+		assertTrue("Failed with same hash as null",
+				m.remove(new Integer(0)) == null);
+		assertTrue("Failed with null key", m.remove(null).equals("test"));
+	}
+
+	/**
+	 * @tests java.util.HashMap#size()
+	 */
+	public void test_size() {
+		// Test for method int java.util.HashMap.size()
+		assertTrue("Returned incorrect size",
+				hm.size() == (objArray.length + 2));
+	}
+
+	/**
+	 * @tests java.util.HashMap#values()
+	 */
+	public void test_values() {
+		// Test for method java.util.Collection java.util.HashMap.values()
+		Collection c = hm.values();
+		assertTrue("Returned collection of incorrect size()", c.size() == hm
+				.size());
+		for (int i = 0; i < objArray.length; i++)
+			assertTrue("Returned collection does not contain all keys", c
+					.contains(objArray[i]));
+
+		HashMap myHashMap = new HashMap();
+		for (int i = 0; i < 100; i++)
+			myHashMap.put(objArray2[i], objArray[i]);
+		Collection values = myHashMap.values();
+		new Support_UnmodifiableCollectionTest(
+				"Test Returned Collection From HashMap.values()", values)
+				.runTest();
+		values.remove(new Integer(0));
+		assertTrue(
+				"Removing from the values collection should remove from the original map",
+				!myHashMap.containsValue(new Integer(0)));
+
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+		hm = new HashMap();
+		for (int i = 0; i < objArray.length; i++)
+			hm.put(objArray2[i], objArray[i]);
+		hm.put("test", null);
+		hm.put(null, "test");
+	}
+
+	/**
+	 * 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/HashSetTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashSetTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashSetTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashSetTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,209 @@
+/* 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.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+public class HashSetTest extends junit.framework.TestCase {
+
+	HashSet hs;
+
+	static Object[] objArray;
+	{
+		objArray = new Object[1000];
+		for (int i = 0; i < objArray.length; i++)
+			objArray[i] = new Integer(i);
+	}
+
+	/**
+	 * @tests java.util.HashSet#HashSet()
+	 */
+	public void test_Constructor() {
+		// Test for method java.util.HashSet()
+		HashSet hs2 = new HashSet();
+		assertTrue("Created incorrect HashSet", hs2.size() == 0);
+	}
+
+	/**
+	 * @tests java.util.HashSet#HashSet(int)
+	 */
+	public void test_ConstructorI() {
+		// Test for method java.util.HashSet(int)
+		HashSet hs2 = new HashSet(5);
+		assertTrue("Created incorrect HashSet", hs2.size() == 0);
+		try {
+			new HashSet(-1);
+		} catch (IllegalArgumentException e) {
+			return;
+		}
+		fail(
+				"Failed to throw IllegalArgumentException for capacity < 0");
+	}
+
+	/**
+	 * @tests java.util.HashSet#HashSet(int, float)
+	 */
+	public void test_ConstructorIF() {
+		// Test for method java.util.HashSet(int, float)
+		HashSet hs2 = new HashSet(5, (float) 0.5);
+		assertTrue("Created incorrect HashSet", hs2.size() == 0);
+		try {
+			new HashSet(0, 0);
+		} catch (IllegalArgumentException e) {
+			return;
+		}
+		fail(
+				"Failed to throw IllegalArgumentException for initial load factor <= 0");
+	}
+
+	/**
+	 * @tests java.util.HashSet#HashSet(java.util.Collection)
+	 */
+	public void test_ConstructorLjava_util_Collection() {
+		// Test for method java.util.HashSet(java.util.Collection)
+		HashSet hs2 = new HashSet(Arrays.asList(objArray));
+		for (int counter = 0; counter < objArray.length; counter++)
+			assertTrue("HashSet does not contain correct elements", hs
+					.contains(objArray[counter]));
+		assertTrue("HashSet created from collection incorrect size",
+				hs2.size() == objArray.length);
+	}
+
+	/**
+	 * @tests java.util.HashSet#add(java.lang.Object)
+	 */
+	public void test_addLjava_lang_Object() {
+		// Test for method boolean java.util.HashSet.add(java.lang.Object)
+		int size = hs.size();
+		hs.add(new Integer(8));
+		assertTrue("Added element already contained by set", hs.size() == size);
+		hs.add(new Integer(-9));
+		assertTrue("Failed to increment set size after add",
+				hs.size() == size + 1);
+		assertTrue("Failed to add element to set", hs.contains(new Integer(-9)));
+	}
+
+	/**
+	 * @tests java.util.HashSet#clear()
+	 */
+	public void test_clear() {
+		// Test for method void java.util.HashSet.clear()
+		Set orgSet = (Set) hs.clone();
+		hs.clear();
+		Iterator i = orgSet.iterator();
+		assertTrue("Returned non-zero size after clear", hs.size() == 0);
+		while (i.hasNext())
+			assertTrue("Failed to clear set", !hs.contains(i.next()));
+	}
+
+	/**
+	 * @tests java.util.HashSet#clone()
+	 */
+	public void test_clone() {
+		// Test for method java.lang.Object java.util.HashSet.clone()
+		HashSet hs2 = (HashSet) hs.clone();
+		assertTrue("clone returned an equivalent HashSet", hs != hs2);
+		assertTrue("clone did not return an equal HashSet", hs.equals(hs2));
+	}
+
+	/**
+	 * @tests java.util.HashSet#contains(java.lang.Object)
+	 */
+	public void test_containsLjava_lang_Object() {
+		// Test for method boolean java.util.HashSet.contains(java.lang.Object)
+		assertTrue("Returned false for valid object", hs.contains(objArray[90]));
+		assertTrue("Returned true for invalid Object", !hs
+				.contains(new Object()));
+
+		HashSet s = new HashSet();
+		s.add(null);
+		assertTrue("Cannot handle null", s.contains(null));
+	}
+
+	/**
+	 * @tests java.util.HashSet#isEmpty()
+	 */
+	public void test_isEmpty() {
+		// Test for method boolean java.util.HashSet.isEmpty()
+		assertTrue("Empty set returned false", new HashSet().isEmpty());
+		assertTrue("Non-empty set returned true", !hs.isEmpty());
+	}
+
+	/**
+	 * @tests java.util.HashSet#iterator()
+	 */
+	public void test_iterator() {
+		// Test for method java.util.Iterator java.util.HashSet.iterator()
+		Iterator i = hs.iterator();
+		int x = 0;
+		while (i.hasNext()) {
+			assertTrue("Failed to iterate over all elements", hs.contains(i
+					.next()));
+			++x;
+		}
+		assertTrue("Returned iteration of incorrect size", hs.size() == x);
+
+		HashSet s = new HashSet();
+		s.add(null);
+		assertTrue("Cannot handle null", s.iterator().next() == null);
+	}
+
+	/**
+	 * @tests java.util.HashSet#remove(java.lang.Object)
+	 */
+	public void test_removeLjava_lang_Object() {
+		// Test for method boolean java.util.HashSet.remove(java.lang.Object)
+		int size = hs.size();
+		hs.remove(new Integer(98));
+		assertTrue("Failed to remove element", !hs.contains(new Integer(98)));
+		assertTrue("Failed to decrement set size", hs.size() == size - 1);
+
+		HashSet s = new HashSet();
+		s.add(null);
+		assertTrue("Cannot handle null", s.remove(null));
+	}
+
+	/**
+	 * @tests java.util.HashSet#size()
+	 */
+	public void test_size() {
+		// Test for method int java.util.HashSet.size()
+		assertTrue("Returned incorrect size", hs.size() == (objArray.length + 1));
+		hs.clear();
+		assertTrue("Cleared set returned non-zero size", hs.size() == 0);
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+		hs = new HashSet();
+		for (int i = 0; i < objArray.length; i++)
+			hs.add(objArray[i]);
+		hs.add(null);
+	}
+
+	/**
+	 * Tears down the fixture, for example, close a network connection. This
+	 * method is called after a test is executed.
+	 */
+	protected void tearDown() {
+	}
+}