harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r386058 [33/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/net/URLTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,1066 @@
+/* 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.net;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.net.URLStreamHandlerFactory;
+
+import tests.support.Support_Configuration;
+import tests.support.resource.Support_Resources;
+
+public class URLTest extends junit.framework.TestCase {
+
+	public static class MyHandler extends URLStreamHandler {
+		protected URLConnection openConnection(URL u)
+				throws java.io.IOException {
+			return null;
+		}
+	}
+
+	URL u;
+
+	URL u1;
+
+	URL u2;
+
+	URL u3;
+
+	URL u4;
+
+	URL u5;
+
+	URL u6;
+
+	boolean caught = false;
+
+	/**
+	 * @tests java.net.URL#setURLStreamHandlerFactory(java.net.URLStreamHandlerFactory)
+	 */
+	public void test_setURLStreamHandlerFactoryLjava_net_URLStreamHandlerFactory() {
+		// Test for method void
+		// java.net.URL.setURLStreamHandlerFactory(java.net.URLStreamHandlerFactory)
+		class TestFactory implements URLStreamHandlerFactory {
+			public TestFactory() {
+			}
+
+			public URLStreamHandler createURLStreamHandler(String protocol) {
+				return null;
+			}
+		}
+		try {
+			u = new URL("http://www.yahoo.com");
+			u.setURLStreamHandlerFactory(new TestFactory());
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+		try {
+			u.setURLStreamHandlerFactory(new TestFactory());
+			fail("Can only set Factory once.");
+		} catch (Error e) {
+		}
+	}
+
+	/**
+	 * @tests java.net.URL#URL(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method java.net.URL(java.lang.String)
+		// Tests for multiple URL instantiation
+		try {
+			// basic parsing test
+			u = new URL(
+					"http://www.yahoo1.com:8080/dir1/dir2/test.cgi?point1.html#anchor1");
+			assertTrue("u returns a wrong protocol", u.getProtocol().equals(
+					"http"));
+			assertTrue("u returns a wrong host", u.getHost().equals(
+					"www.yahoo1.com"));
+			assertTrue("u returns a wrong port", u.getPort() == 8080);
+			assertTrue("u returns a wrong file", u.getFile().equals(
+					"/dir1/dir2/test.cgi?point1.html"));
+			assertTrue("u returns a wrong anchor", u.getRef().equals("anchor1"));
+
+			// test for no file
+			u1 = new URL("http://www.yahoo2.com:9999");
+			assertTrue("u1 returns a wrong protocol", u1.getProtocol().equals(
+					"http"));
+			assertTrue("u1 returns a wrong host", u1.getHost().equals(
+					"www.yahoo2.com"));
+			assertTrue("u1 returns a wrong port", u1.getPort() == 9999);
+			assertTrue("u1 returns a wrong file", u1.getFile().equals(""));
+			assertTrue("u1 returns a wrong anchor", u1.getRef() == null);
+
+			// test for no port
+			u2 = new URL(
+					"http://www.yahoo3.com/dir1/dir2/test.cgi?point1.html#anchor1");
+			assertTrue("u2 returns a wrong protocol", u2.getProtocol().equals(
+					"http"));
+			assertTrue("u2 returns a wrong host", u2.getHost().equals(
+					"www.yahoo3.com"));
+			assertTrue("u2 returns a wrong port", u2.getPort() == -1);
+			assertTrue("u2 returns a wrong file", u2.getFile().equals(
+					"/dir1/dir2/test.cgi?point1.html"));
+			assertTrue("u2 returns a wrong anchor", u2.getRef().equals(
+					"anchor1"));
+
+			// test for no port
+			URL u2a = new URL(
+					"file://www.yahoo3.com/dir1/dir2/test.cgi#anchor1");
+			assertTrue("u2a returns a wrong protocol", u2a.getProtocol()
+					.equals("file"));
+			assertTrue("u2a returns a wrong host", u2a.getHost().equals(
+					"www.yahoo3.com"));
+			assertTrue("u2a returns a wrong port", u2a.getPort() == -1);
+			assertTrue("u2a returns a wrong file", u2a.getFile().equals(
+					"/dir1/dir2/test.cgi"));
+			assertTrue("u2a returns a wrong anchor", u2a.getRef().equals(
+					"anchor1"));
+
+			// test for no file, no port
+			u3 = new URL("http://www.yahoo4.com/");
+			assertTrue("u3 returns a wrong protocol", u3.getProtocol().equals(
+					"http"));
+			assertTrue("u3 returns a wrong host", u3.getHost().equals(
+					"www.yahoo4.com"));
+			assertTrue("u3 returns a wrong port", u3.getPort() == -1);
+			assertTrue("u3 returns a wrong file", u3.getFile().equals("/"));
+			assertTrue("u3 returns a wrong anchor", u3.getRef() == null);
+
+			// test for no file, no port
+			URL u3a = new URL("file://www.yahoo4.com/");
+			assertTrue("u3a returns a wrong protocol", u3a.getProtocol()
+					.equals("file"));
+			assertTrue("u3a returns a wrong host", u3a.getHost().equals(
+					"www.yahoo4.com"));
+			assertTrue("u3a returns a wrong port", u3a.getPort() == -1);
+			assertTrue("u3a returns a wrong file", u3a.getFile().equals("/"));
+			assertTrue("u3a returns a wrong anchor", u3a.getRef() == null);
+
+			// test for no file, no port
+			URL u3b = new URL("file://www.yahoo4.com");
+			assertTrue("u3b returns a wrong protocol", u3b.getProtocol()
+					.equals("file"));
+			assertTrue("u3b returns a wrong host", u3b.getHost().equals(
+					"www.yahoo4.com"));
+			assertTrue("u3b returns a wrong port", u3b.getPort() == -1);
+			assertTrue("u3b returns a wrong file", u3b.getFile().equals(""));
+			assertTrue("u3b returns a wrong anchor", u3b.getRef() == null);
+
+			// test for non-port ":" and wierd characters occurences
+			u4 = new URL(
+					"http://www.yahoo5.com/di!@$%^&*()_+r1/di:::r2/test.cgi?point1.html#anchor1");
+			assertTrue("u4 returns a wrong protocol", u4.getProtocol().equals(
+					"http"));
+			assertTrue("u4 returns a wrong host", u4.getHost().equals(
+					"www.yahoo5.com"));
+			assertTrue("u4 returns a wrong port", u4.getPort() == -1);
+			assertTrue("u4 returns a wrong file", u4.getFile().equals(
+					"/di!@$%^&*()_+r1/di:::r2/test.cgi?point1.html"));
+			assertTrue("u4 returns a wrong anchor", u4.getRef().equals(
+					"anchor1"));
+
+			u5 = new URL("file:/testing.tst");
+			assertTrue("u5 returns a wrong protocol", u5.getProtocol().equals(
+					"file"));
+			assertTrue("u5 returns a wrong host", u5.getHost().equals(""));
+			assertTrue("u5 returns a wrong port", u5.getPort() == -1);
+			assertTrue("u5 returns a wrong file", u5.getFile().equals(
+					"/testing.tst"));
+			assertTrue("u5 returns a wrong anchor", u5.getRef() == null);
+
+			URL u5a = new URL("file:testing.tst");
+			assertTrue("u5a returns a wrong protocol", u5a.getProtocol()
+					.equals("file"));
+			assertTrue("u5a returns a wrong host", u5a.getHost().equals(""));
+			assertTrue("u5a returns a wrong port", u5a.getPort() == -1);
+			assertTrue("u5a returns a wrong file", u5a.getFile().equals(
+					"testing.tst"));
+			assertTrue("u5a returns a wrong anchor", u5a.getRef() == null);
+
+			URL u6 = new URL("http://host:/file");
+			assertTrue("u6 return a wrong port", u6.getPort() == -1);
+
+			URL u7 = new URL("file:../../file.txt");
+			assertTrue("u7 returns a wrong file: " + u7.getFile(), u7.getFile()
+					.equals("../../file.txt"));
+
+			URL u8 = new URL("http://[fec0::1:20d:60ff:fe24:7410]:35/file.txt");
+			assertTrue("u8 returns a wrong protocol " + u8.getProtocol(), u8
+					.getProtocol().equals("http"));
+			assertTrue("u8 returns a wrong host " + u8.getHost(), u8.getHost()
+					.equals("[fec0::1:20d:60ff:fe24:7410]"));
+			assertTrue("u8 returns a wrong port " + u8.getPort(),
+					u8.getPort() == 35);
+			assertTrue("u8 returns a wrong file " + u8.getFile(), u8.getFile()
+					.equals("/file.txt"));
+			assertTrue("u8 returns a wrong anchor " + u8.getRef(),
+					u8.getRef() == null);
+
+			URL u9 = new URL(
+					"file://[fec0::1:20d:60ff:fe24:7410]/file.txt#sogood");
+			assertTrue("u9 returns a wrong protocol " + u9.getProtocol(), u9
+					.getProtocol().equals("file"));
+			assertTrue("u9 returns a wrong host " + u9.getHost(), u9.getHost()
+					.equals("[fec0::1:20d:60ff:fe24:7410]"));
+			assertTrue("u9 returns a wrong port " + u9.getPort(),
+					u9.getPort() == -1);
+			assertTrue("u9 returns a wrong file " + u9.getFile(), u9.getFile()
+					.equals("/file.txt"));
+			assertTrue("u9 returns a wrong anchor " + u9.getRef(), u9.getRef()
+					.equals("sogood"));
+
+			URL u10 = new URL("file://[fec0::1:20d:60ff:fe24:7410]");
+			assertTrue("u10 returns a wrong protocol " + u10.getProtocol(), u10
+					.getProtocol().equals("file"));
+			assertTrue("u10 returns a wrong host " + u10.getHost(), u10
+					.getHost().equals("[fec0::1:20d:60ff:fe24:7410]"));
+			assertTrue("u10 returns a wrong port " + u10.getPort(), u10
+					.getPort() == -1);
+
+		} catch (Exception e) {
+			fail("Exception during tests : " + e.getMessage());
+		}
+
+		// test for error catching
+
+		// Bad HTTP format - no "//"
+
+		try {
+			u = new URL(
+					"http:www.yahoo5.com::22/dir1/di:::r2/test.cgi?point1.html#anchor1");
+		} catch (MalformedURLException e) {
+			fail("1 Should not have thrown MalformedURLException : "
+					+ e.getMessage());
+		} catch (Exception e) {
+			fail("1 Threw exception : " + e.getMessage());
+		}
+
+		caught = false;
+		try {
+			u = new URL(
+					"http://www.yahoo5.com::22/dir1/di:::r2/test.cgi?point1.html#anchor1");
+		} catch (MalformedURLException e) {
+			caught = true;
+		} catch (Exception e) {
+			fail("2 Threw exception : " + e.getMessage());
+		}
+		assertTrue("Should have throw MalformedURLException", caught);
+
+		// unknown protocol
+		try {
+			u = new URL("myProtocol://www.yahoo.com:22");
+		} catch (MalformedURLException e) {
+			caught = true;
+		} catch (Exception e) {
+			fail("3 Threw the wrong kind of exception : " + e);
+		}
+		assertTrue("3 Failed to throw MalformedURLException", caught);
+
+		caught = false;
+		// no protocol
+		try {
+			u = new URL("www.yahoo.com");
+		} catch (MalformedURLException e) {
+			caught = true;
+		} catch (Exception e) {
+			fail("4 Threw the wrong kind of exception : " + e);
+		}
+		assertTrue("4 Failed to throw MalformedURLException", caught);
+
+		caught = false;
+
+		URL u1 = null;
+		try {
+			// No leading or trailing spaces.
+			u1 = new URL("file:/some/path");
+			assertEquals("5 got wrong file length1", 10, u1.getFile().length());
+
+			// Leading spaces.
+			u1 = new URL("  file:/some/path");
+			assertEquals("5 got wrong file length2", 10, u1.getFile().length());
+
+			// Trailing spaces.
+			u1 = new URL("file:/some/path  ");
+			assertEquals("5 got wrong file length3", 10, u1.getFile().length());
+
+			// Leading and trailing.
+			u1 = new URL("  file:/some/path ");
+			assertEquals("5 got wrong file length4", 10, u1.getFile().length());
+
+			// in-place spaces.
+			u1 = new URL("  file:  /some/path ");
+			assertEquals("5 got wrong file length5", 12, u1.getFile().length());
+
+		} catch (MalformedURLException e) {
+			fail("5 Did not expect the exception " + e);
+		}
+	}
+
+	/**
+	 * @tests java.net.URL#URL(java.net.URL, java.lang.String)
+	 */
+	public void test_ConstructorLjava_net_URLLjava_lang_String() {
+		// Test for method java.net.URL(java.net.URL, java.lang.String)
+		try {
+			u = new URL("http://www.yahoo.com");
+			URL uf = new URL("file://www.yahoo.com");
+			// basic ones
+			u1 = new URL(u, "file.java");
+			assertTrue("1 returns a wrong protocol", u1.getProtocol().equals(
+					"http"));
+			assertTrue("1 returns a wrong host", u1.getHost().equals(
+					"www.yahoo.com"));
+			assertTrue("1 returns a wrong port", u1.getPort() == -1);
+			assertTrue("1 returns a wrong file", u1.getFile().equals(
+					"/file.java"));
+			assertTrue("1 returns a wrong anchor", u1.getRef() == null);
+
+			URL u1f = new URL(uf, "file.java");
+			assertTrue("1f returns a wrong protocol", u1f.getProtocol().equals(
+					"file"));
+			assertTrue("1f returns a wrong host", u1f.getHost().equals(
+					"www.yahoo.com"));
+			assertTrue("1f returns a wrong port", u1f.getPort() == -1);
+			assertTrue("1f returns a wrong file", u1f.getFile().equals(
+					"/file.java"));
+			assertTrue("1f returns a wrong anchor", u1f.getRef() == null);
+
+			u1 = new URL(u, "dir1/dir2/../file.java");
+			assertTrue("3 returns a wrong protocol", u1.getProtocol().equals(
+					"http"));
+			assertTrue("3 returns a wrong host: " + u1.getHost(), u1.getHost()
+					.equals("www.yahoo.com"));
+			assertTrue("3 returns a wrong port", u1.getPort() == -1);
+			assertTrue("3 returns a wrong file", u1.getFile().equals(
+					"/dir1/dir2/../file.java"));
+			assertTrue("3 returns a wrong anchor", u1.getRef() == null);
+
+			u1 = new URL(u, "http:dir1/dir2/../file.java");
+			assertTrue("3a returns a wrong protocol", u1.getProtocol().equals(
+					"http"));
+			assertTrue("3a returns a wrong host: " + u1.getHost(), u1.getHost()
+					.equals(""));
+			assertTrue("3a returns a wrong port", u1.getPort() == -1);
+			assertTrue("3a returns a wrong file", u1.getFile().equals(
+					"dir1/dir2/../file.java"));
+			assertTrue("3a returns a wrong anchor", u1.getRef() == null);
+
+			u = new URL("http://www.apache.org/testing/");
+			u1 = new URL(u, "file.java");
+			assertTrue("4 returns a wrong protocol", u1.getProtocol().equals(
+					"http"));
+			assertTrue("4 returns a wrong host", u1.getHost().equals(
+					"www.apache.org"));
+			assertTrue("4 returns a wrong port", u1.getPort() == -1);
+			assertTrue("4 returns a wrong file", u1.getFile().equals(
+					"/testing/file.java"));
+			assertTrue("4 returns a wrong anchor", u1.getRef() == null);
+
+			uf = new URL("file://www.apache.org/testing/");
+			u1f = new URL(uf, "file.java");
+			assertTrue("4f returns a wrong protocol", u1f.getProtocol().equals(
+					"file"));
+			assertTrue("4f returns a wrong host", u1f.getHost().equals(
+					"www.apache.org"));
+			assertTrue("4f returns a wrong port", u1f.getPort() == -1);
+			assertTrue("4f returns a wrong file", u1f.getFile().equals(
+					"/testing/file.java"));
+			assertTrue("4f returns a wrong anchor", u1f.getRef() == null);
+
+			uf = new URL("file:/testing/");
+			u1f = new URL(uf, "file.java");
+			assertTrue("4fa returns a wrong protocol", u1f.getProtocol()
+					.equals("file"));
+			assertTrue("4fa returns a wrong host", u1f.getHost().equals(""));
+			assertTrue("4fa returns a wrong port", u1f.getPort() == -1);
+			assertTrue("4fa returns a wrong file", u1f.getFile().equals(
+					"/testing/file.java"));
+			assertTrue("4fa returns a wrong anchor", u1f.getRef() == null);
+
+			uf = new URL("file:testing/");
+			u1f = new URL(uf, "file.java");
+			assertTrue("4fb returns a wrong protocol", u1f.getProtocol()
+					.equals("file"));
+			assertTrue("4fb returns a wrong host", u1f.getHost().equals(""));
+			assertTrue("4fb returns a wrong port", u1f.getPort() == -1);
+			assertTrue("4fb returns a wrong file", u1f.getFile().equals(
+					"testing/file.java"));
+			assertTrue("4fb returns a wrong anchor", u1f.getRef() == null);
+
+			u1f = new URL(uf, "file:file.java");
+			assertTrue("4fc returns a wrong protocol", u1f.getProtocol()
+					.equals("file"));
+			assertTrue("4fc returns a wrong host", u1f.getHost().equals(""));
+			assertTrue("4fc returns a wrong port", u1f.getPort() == -1);
+			assertTrue("4fc returns a wrong file", u1f.getFile().equals(
+					"file.java"));
+			assertTrue("4fc returns a wrong anchor", u1f.getRef() == null);
+
+			u1f = new URL(uf, "file:");
+			assertTrue("4fd returns a wrong protocol", u1f.getProtocol()
+					.equals("file"));
+			assertTrue("4fd returns a wrong host", u1f.getHost().equals(""));
+			assertTrue("4fd returns a wrong port", u1f.getPort() == -1);
+			assertTrue("4fd returns a wrong file", u1f.getFile().equals(""));
+			assertTrue("4fd returns a wrong anchor", u1f.getRef() == null);
+
+			u = new URL("http://www.apache.org/testing");
+			u1 = new URL(u, "file.java");
+			assertTrue("5 returns a wrong protocol", u1.getProtocol().equals(
+					"http"));
+			assertTrue("5 returns a wrong host", u1.getHost().equals(
+					"www.apache.org"));
+			assertTrue("5 returns a wrong port", u1.getPort() == -1);
+			assertTrue("5 returns a wrong file", u1.getFile().equals(
+					"/file.java"));
+			assertTrue("5 returns a wrong anchor", u1.getRef() == null);
+
+			uf = new URL("file://www.apache.org/testing");
+			u1f = new URL(uf, "file.java");
+			assertTrue("5f returns a wrong protocol", u1f.getProtocol().equals(
+					"file"));
+			assertTrue("5f returns a wrong host", u1f.getHost().equals(
+					"www.apache.org"));
+			assertTrue("5f returns a wrong port", u1f.getPort() == -1);
+			assertTrue("5f returns a wrong file", u1f.getFile().equals(
+					"/file.java"));
+			assertTrue("5f returns a wrong anchor", u1f.getRef() == null);
+
+			uf = new URL("file:/testing");
+			u1f = new URL(uf, "file.java");
+			assertTrue("5fa returns a wrong protocol", u1f.getProtocol()
+					.equals("file"));
+			assertTrue("5fa returns a wrong host", u1f.getHost().equals(""));
+			assertTrue("5fa returns a wrong port", u1f.getPort() == -1);
+			assertTrue("5fa returns a wrong file", u1f.getFile().equals(
+					"/file.java"));
+			assertTrue("5fa returns a wrong anchor", u1f.getRef() == null);
+
+			uf = new URL("file:testing");
+			u1f = new URL(uf, "file.java");
+			assertTrue("5fb returns a wrong protocol", u1f.getProtocol()
+					.equals("file"));
+			assertTrue("5fb returns a wrong host", u1f.getHost().equals(""));
+			assertTrue("5fb returns a wrong port", u1f.getPort() == -1);
+			assertTrue("5fb returns a wrong file", u1f.getFile().equals(
+					"file.java"));
+			assertTrue("5fb returns a wrong anchor", u1f.getRef() == null);
+
+			u = new URL("http://www.apache.org/testing/foobaz");
+			u1 = new URL(u, "/file.java");
+			assertTrue("6 returns a wrong protocol", u1.getProtocol().equals(
+					"http"));
+			assertTrue("6 returns a wrong host", u1.getHost().equals(
+					"www.apache.org"));
+			assertTrue("6 returns a wrong port", u1.getPort() == -1);
+			assertTrue("6 returns a wrong file", u1.getFile().equals(
+					"/file.java"));
+			assertTrue("6 returns a wrong anchor", u1.getRef() == null);
+
+			uf = new URL("file://www.apache.org/testing/foobaz");
+			u1f = new URL(uf, "/file.java");
+			assertTrue("6f returns a wrong protocol", u1f.getProtocol().equals(
+					"file"));
+			assertTrue("6f returns a wrong host", u1f.getHost().equals(
+					"www.apache.org"));
+			assertTrue("6f returns a wrong port", u1f.getPort() == -1);
+			assertTrue("6f returns a wrong file", u1f.getFile().equals(
+					"/file.java"));
+			assertTrue("6f returns a wrong anchor", u1f.getRef() == null);
+
+			u = new URL("http://www.apache.org:8000/testing/foobaz");
+			u1 = new URL(u, "/file.java");
+			assertTrue("7 returns a wrong protocol", u1.getProtocol().equals(
+					"http"));
+			assertTrue("7 returns a wrong host", u1.getHost().equals(
+					"www.apache.org"));
+			assertTrue("7 returns a wrong port", u1.getPort() == 8000);
+			assertTrue("7 returns a wrong file", u1.getFile().equals(
+					"/file.java"));
+			assertTrue("7 returns a wrong anchor", u1.getRef() == null);
+
+			u = new URL("http://www.apache.org/index.html");
+			u1 = new URL(u, "#bar");
+			assertTrue("8 returns a wrong host", u1.getHost().equals(
+					"www.apache.org"));
+			assertTrue("8 returns a wrong file", u1.getFile().equals(
+					"/index.html"));
+			assertTrue("8 returns a wrong anchor", u1.getRef().equals("bar"));
+
+			u = new URL("http://www.apache.org/index.html#foo");
+			u1 = new URL(u, "http:#bar");
+			assertTrue("9 returns a wrong host", u1.getHost().equals(
+					"www.apache.org"));
+			assertTrue("9 returns a wrong file", u1.getFile().equals(
+					"/index.html"));
+			assertTrue("9 returns a wrong anchor", u1.getRef().equals("bar"));
+
+			u = new URL("http://www.apache.org/index.html");
+			u1 = new URL(u, "");
+			assertTrue("10 returns a wrong host", u1.getHost().equals(
+					"www.apache.org"));
+			assertTrue("10 returns a wrong file", u1.getFile().equals(
+					"/index.html"));
+			assertTrue("10 returns a wrong anchor", u1.getRef() == null);
+
+			uf = new URL("file://www.apache.org/index.html");
+			u1f = new URL(uf, "");
+			assertTrue("10f returns a wrong host", u1.getHost().equals(
+					"www.apache.org"));
+			assertTrue("10f returns a wrong file", u1.getFile().equals(
+					"/index.html"));
+			assertTrue("10f returns a wrong anchor", u1.getRef() == null);
+
+			u = new URL("http://www.apache.org/index.html");
+			u1 = new URL(u, "http://www.apache.org");
+			assertTrue("11 returns a wrong host", u1.getHost().equals(
+					"www.apache.org"));
+			assertTrue("11 returns a wrong file", u1.getFile().equals(""));
+			assertTrue("11 returns a wrong anchor", u1.getRef() == null);
+
+			// test for question mark processing
+			u = new URL("http://www.foo.com/d0/d1/d2/cgi-bin?foo=bar/baz");
+
+			// test for relative file and out of bound "/../" processing
+			u1 = new URL(u, "../dir1/./dir2/../file.java");
+			assertTrue("A) returns a wrong file: " + u1.getFile(), u1.getFile()
+					.equals("/d0/d1/dir1/file.java"));
+
+			// test for absolute and relative file processing
+			u1 = new URL(u, "/../dir1/./dir2/../file.java");
+			assertTrue("B) returns a wrong file", u1.getFile().equals(
+					"/../dir1/./dir2/../file.java"));
+		} catch (Exception e) {
+			fail("1 Exception during tests : " + e.getMessage());
+		}
+
+		try {
+			// u should raise a MalFormedURLException because u, the context is
+			// null
+			u = null;
+			u1 = new URL(u, "file.java");
+		} catch (MalformedURLException e) {
+			return;
+		} catch (Exception e) {
+			fail("2 Exception during tests : " + e.getMessage());
+		}
+		fail("didn't throw the expected MalFormedURLException");
+	}
+
+	/**
+	 * @tests java.net.URL#URL(java.net.URL, java.lang.String,
+	 *        java.net.URLStreamHandler)
+	 */
+	public void test_ConstructorLjava_net_URLLjava_lang_StringLjava_net_URLStreamHandler() {
+		// Test for method java.net.URL(java.net.URL, java.lang.String,
+		// java.net.URLStreamHandler)
+		try {
+			u = new URL("http://www.yahoo.com");
+			// basic ones
+			u1 = new URL(u, "file.java", new MyHandler());
+			assertTrue("1 returns a wrong protocol", u1.getProtocol().equals(
+					"http"));
+			assertTrue("1 returns a wrong host", u1.getHost().equals(
+					"www.yahoo.com"));
+			assertTrue("1 returns a wrong port", u1.getPort() == -1);
+			assertTrue("1 returns a wrong file", u1.getFile().equals(
+					"/file.java"));
+			assertTrue("1 returns a wrong anchor", u1.getRef() == null);
+
+			u1 = new URL(u, "systemresource:/+/FILE0/test.java",
+					new MyHandler());
+			assertTrue("2 returns a wrong protocol", u1.getProtocol().equals(
+					"systemresource"));
+			assertTrue("2 returns a wrong host", u1.getHost().equals(""));
+			assertTrue("2 returns a wrong port", u1.getPort() == -1);
+			assertTrue("2 returns a wrong file", u1.getFile().equals(
+					"/+/FILE0/test.java"));
+			assertTrue("2 returns a wrong anchor", u1.getRef() == null);
+
+			u1 = new URL(u, "dir1/dir2/../file.java", null);
+			assertTrue("3 returns a wrong protocol", u1.getProtocol().equals(
+					"http"));
+			assertTrue("3 returns a wrong host", u1.getHost().equals(
+					"www.yahoo.com"));
+			assertTrue("3 returns a wrong port", u1.getPort() == -1);
+			assertTrue("3 returns a wrong file", u1.getFile().equals(
+					"/dir1/dir2/../file.java"));
+			assertTrue("3 returns a wrong anchor", u1.getRef() == null);
+
+			// test for question mark processing
+			u = new URL("http://www.foo.com/d0/d1/d2/cgi-bin?foo=bar/baz");
+
+			// test for relative file and out of bound "/../" processing
+			u1 = new URL(u, "../dir1/dir2/../file.java", new MyHandler());
+			assertTrue("A) returns a wrong file: " + u1.getFile(), u1.getFile()
+					.equals("/d0/d1/dir1/file.java"));
+
+			// test for absolute and relative file processing
+			u1 = new URL(u, "/../dir1/dir2/../file.java", null);
+			assertTrue("B) returns a wrong file", u1.getFile().equals(
+					"/../dir1/dir2/../file.java"));
+		} catch (Exception e) {
+			fail("1 Exception during tests : " + e.getMessage());
+		}
+
+		URL one;
+		try {
+			one = new URL("http://www.ibm.com");
+		} catch (MalformedURLException ex) {
+			// Should not happen.
+			throw new RuntimeException(ex.getMessage());
+		}
+		try {
+			new URL(one, (String) null);
+			fail("Specifying null spec on URL constructor should throw MalformedURLException");
+		} catch (MalformedURLException e) {
+			// expected
+		}
+
+		try {
+			// u should raise a MalFormedURLException because u, the context is
+			// null
+			u = null;
+			u1 = new URL(u, "file.java", new MyHandler());
+		} catch (MalformedURLException e) {
+			return;
+		} catch (Exception e) {
+			fail("2 Exception during tests : " + e.getMessage());
+		}
+		fail("didn't throw expected MalFormedURLException");
+	}
+
+	/**
+	 * @tests java.net.URL#URL(java.lang.String, java.lang.String,
+	 *        java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_StringLjava_lang_StringLjava_lang_String() {
+		// Test for method java.net.URL(java.lang.String, java.lang.String,
+		// java.lang.String)
+		try {
+			u = new URL("http", "www.yahoo.com:8080", "test.html#foo");
+			assertTrue("SSS returns a wrong protocol", u.getProtocol().equals(
+					"http"));
+			assertTrue("SSS returns a wrong host: " + u.getHost(), u.getHost()
+					.equals("www.yahoo.com:8080"));
+			assertTrue("SSS returns a wrong port", u.getPort() == -1);
+			assertTrue("SSS returns a wrong file", u.getFile().equals(
+					"test.html"));
+			assertTrue("SSS returns a wrong anchor: " + u.getRef(), u.getRef()
+					.equals("foo"));
+		} catch (Exception e) {
+			fail("SSS Exception during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.net.URL#URL(java.lang.String, java.lang.String, int,
+	 *        java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_StringLjava_lang_StringILjava_lang_String() {
+		// Test for method java.net.URL(java.lang.String, java.lang.String, int,
+		// java.lang.String)
+		try {
+			u = new URL("http", "www.yahoo.com", 8080, "test.html#foo");
+			assertTrue("SSIS returns a wrong protocol", u.getProtocol().equals(
+					"http"));
+			assertTrue("SSIS returns a wrong host", u.getHost().equals(
+					"www.yahoo.com"));
+			assertTrue("SSIS returns a wrong port", u.getPort() == 8080);
+			assertTrue("SSIS returns a wrong file", u.getFile().equals(
+					"test.html"));
+			assertTrue("SSIS returns a wrong anchor: " + u.getRef(), u.getRef()
+					.equals("foo"));
+		} catch (Exception e) {
+			fail("SSIS Exception during test : " + e.getMessage());
+		}
+
+	}
+
+	/**
+	 * @tests java.net.URL#URL(java.lang.String, java.lang.String, int,
+	 *        java.lang.String, java.net.URLStreamHandler)
+	 */
+	public void test_ConstructorLjava_lang_StringLjava_lang_StringILjava_lang_StringLjava_net_URLStreamHandler() {
+		// Test for method java.net.URL(java.lang.String, java.lang.String, int,
+		// java.lang.String, java.net.URLStreamHandler)
+		try {
+			u = new URL("http", "www.yahoo.com", 8080, "test.html#foo", null);
+			assertTrue("SSISH1 returns a wrong protocol", u.getProtocol()
+					.equals("http"));
+			assertTrue("SSISH1 returns a wrong host", u.getHost().equals(
+					"www.yahoo.com"));
+			assertTrue("SSISH1 returns a wrong port", u.getPort() == 8080);
+			assertTrue("SSISH1 returns a wrong file", u.getFile().equals(
+					"test.html"));
+			assertTrue("SSISH1 returns a wrong anchor: " + u.getRef(), u
+					.getRef().equals("foo"));
+		} catch (Exception e) {
+			fail("SSISH1 Exception during test : " + e.getMessage());
+		}
+
+		try {
+			u = new URL("http", "www.yahoo.com", 8080, "test.html#foo",
+					new MyHandler());
+			assertTrue("SSISH2 returns a wrong protocol", u.getProtocol()
+					.equals("http"));
+			assertTrue("SSISH2 returns a wrong host", u.getHost().equals(
+					"www.yahoo.com"));
+			assertTrue("SSISH2 returns a wrong port", u.getPort() == 8080);
+			assertTrue("SSISH2 returns a wrong file", u.getFile().equals(
+					"test.html"));
+			assertTrue("SSISH2 returns a wrong anchor: " + u.getRef(), u
+					.getRef().equals("foo"));
+		} catch (Exception e) {
+			fail("SSISH2 Exception during test : " + e.getMessage());
+		}
+
+	}
+
+	/**
+	 * @tests java.net.URL#equals(java.lang.Object)
+	 */
+	public void test_equalsLjava_lang_Object() {
+		// Test for method boolean java.net.URL.equals(java.lang.Object)
+		try {
+			u = new URL("http://www.apache.org:8080/dir::23??????????test.html");
+			u1 = new URL("http://www.apache.org:8080/dir::23??????????test.html");
+			assertTrue("A) equals returns false for two identical URLs", u
+					.equals(u1));
+			assertTrue("return true for null comaprison", !u1.equals(null));
+			u = new URL("ftp://www.apache.org:8080/dir::23??????????test.html");
+			assertTrue("Returned true for non-equal URLs", !u.equals(u1));
+		} catch (MalformedURLException e) {
+			fail("MalformedURLException during equals test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.net.URL#sameFile(java.net.URL)
+	 */
+	public void test_sameFileLjava_net_URL() {
+		// Test for method boolean java.net.URL.sameFile(java.net.URL)
+		try {
+			u = new URL("http://www.yahoo.com");
+			u1 = new URL("http", "www.yahoo.com", "");
+			assertTrue("Should be the same1", u.sameFile(u1));
+			u = new URL("http://www.yahoo.com/dir1/dir2/test.html#anchor1");
+			u1 = new URL("http://www.yahoo.com/dir1/dir2/test.html#anchor2");
+			assertTrue("Should be the same ", u.sameFile(u1));
+		} catch (Exception e) {
+		}
+	}
+
+	/**
+	 * @tests java.net.URL#getContent()
+	 */
+	public void test_getContent() {
+		// Test for method java.lang.Object java.net.URL.getContent()
+		byte[] ba;
+		InputStream is;
+		String s;
+		File resources = Support_Resources.createTempFolder();
+		try {
+			Support_Resources.copyFile(resources, null, "hyts_htmltest.html");
+			u = new URL("file:/" + resources.toString() + "/hyts_htmltest.html");
+			u.openConnection();
+			is = (InputStream) u.getContent();
+			is.read(ba = new byte[4096]);
+			s = new String(ba);
+			assertTrue(
+					"Incorrect content "
+							+ u
+							+ " does not contain: \" A Seemingly Non Important String \"",
+					s.indexOf("A Seemingly Non Important String") >= 0);
+		} catch (IOException e) {
+			fail("IOException thrown : " + e.getMessage());
+		} finally {
+			// Support_Resources.deleteTempFolder(resources);
+		}
+
+	}
+
+	/**
+	 * @tests java.net.URL#openStream()
+	 */
+	public void test_openStream() {
+		// Test for method java.io.InputStream java.net.URL.openStream()
+		File resources = Support_Resources.createTempFolder();
+		try {
+			Support_Resources.copyFile(resources, null, "hyts_htmltest.html");
+			u = new URL("file:/" + resources.toString() + "/hyts_htmltest.html");
+			// HTTP connection
+			InputStream is1 = u.openStream();
+			assertTrue("Unable to read from stream", is1.read() != 0);
+			is1.close();
+
+			boolean exception = false;
+			try {
+				u = new URL("file://nonexistenttestdir/tstfile");
+				u.openStream();
+			} catch (IOException e) {
+				// Correct behaviour
+				exception = true;
+			}
+			assertTrue("openStream succeeded for non existent resource",
+					exception);
+
+		} catch (MalformedURLException e) {
+			fail("Incorrect url specified : " + e.getMessage());
+		} catch (IOException e) {
+			fail("IOException opening stream : " + e.getMessage());
+		}
+
+		try {
+			URL u = new URL("jar:"
+					+ Support_Resources.getResourceURL("/JUC/lf.jar!/plus.bmp"));
+			InputStream in = u.openStream();
+			byte[] buf = new byte[3];
+			int result = in.read(buf);
+			assertTrue("Incompete read: " + result, result == 3);
+			in.close();
+			assertTrue("Returned incorrect data", buf[0] == 0x42
+					&& buf[1] == 0x4d && buf[2] == (byte) 0xbe);
+		} catch (java.io.IOException e) {
+			fail("IOException during test : " + e.getMessage());
+		}
+
+		try {
+			URL u = new URL("ftp://" + Support_Configuration.FTPTestAddress
+					+ "/nettest.txt");
+			InputStream in = u.openStream();
+			byte[] buf = new byte[3];
+			assertTrue("Incompete read 2", in.read(buf) == 3);
+			in.close();
+			assertTrue("Returned incorrect data 2", buf[0] == 0x54
+					&& buf[1] == 0x68 && buf[2] == 0x69);
+		} catch (java.io.IOException e) {
+			fail("IOException during test 2 : " + e.getMessage());
+		}
+
+		try {
+			File test = new File("hytest.$$$");
+			FileOutputStream out = new FileOutputStream(test);
+			out.write(new byte[] { 0x55, (byte) 0xaa, 0x14 });
+			out.close();
+			URL u = new URL("file:" + test.getName());
+			InputStream in = u.openStream();
+			byte[] buf = new byte[3];
+			int result = in.read(buf);
+			in.close();
+			test.delete();
+			assertTrue("Incompete read 3", result == 3);
+			assertTrue("Returned incorrect data 3", buf[0] == 0x55
+					&& buf[1] == (byte) 0xaa && buf[2] == 0x14);
+		} catch (java.io.IOException e) {
+			fail("IOException during test 3 : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.net.URL#openConnection()
+	 */
+	public void test_openConnection() {
+		// Test for method java.net.URLConnection java.net.URL.openConnection()
+		try {
+			u = new URL("systemresource:/FILE4/+/types.properties");
+			URLConnection uConn = u.openConnection();
+			assertTrue("u.openConnection() returns null", uConn != null);
+		} catch (Exception e) {
+		}
+	}
+
+	/**
+	 * @tests java.net.URL#toString()
+	 */
+	public void test_toString() {
+		// Test for method java.lang.String java.net.URL.toString()
+		try {
+			u1 = new URL("http://www.yahoo2.com:9999");
+			u = new URL(
+					"http://www.yahoo1.com:8080/dir1/dir2/test.cgi?point1.html#anchor1");
+			assertTrue(
+					"a) Does not return the right url string",
+					u
+							.toString()
+							.equals(
+									"http://www.yahoo1.com:8080/dir1/dir2/test.cgi?point1.html#anchor1"));
+			assertTrue("b) Does not return the right url string", u1.toString()
+					.equals("http://www.yahoo2.com:9999"));
+			assertTrue("c) Does not return the right url string", u
+					.equals(new URL(u.toString())));
+		} catch (Exception e) {
+		}
+	}
+
+	/**
+	 * @tests java.net.URL#toExternalForm()
+	 */
+	public void test_toExternalForm() {
+		// Test for method java.lang.String java.net.URL.toExternalForm()
+		try {
+			u1 = new URL("http://www.yahoo2.com:9999");
+			u = new URL(
+					"http://www.yahoo1.com:8080/dir1/dir2/test.cgi?point1.html#anchor1");
+			assertTrue(
+					"a) Does not return the right url string",
+					u
+							.toString()
+							.equals(
+									"http://www.yahoo1.com:8080/dir1/dir2/test.cgi?point1.html#anchor1"));
+			assertTrue("b) Does not return the right url string", u1.toString()
+					.equals("http://www.yahoo2.com:9999"));
+			assertTrue("c) Does not return the right url string", u
+					.equals(new URL(u.toString())));
+
+			u = new URL("http:index");
+			assertTrue("2 wrong external form", u.toExternalForm().equals(
+					"http:index"));
+
+			u = new URL("http", null, "index");
+			assertTrue("2 wrong external form", u.toExternalForm().equals(
+					"http:index"));
+		} catch (Exception e) {
+		}
+	}
+
+	/**
+	 * @tests java.net.URL#getFile()
+	 */
+	public void test_getFile() {
+		// Test for method java.lang.String java.net.URL.getFile()
+		try {
+			u = new URL("http", "www.yahoo.com:8080", 1233,
+					"test/!@$%^&*/test.html#foo");
+			assertTrue("returns a wrong file", u.getFile().equals(
+					"test/!@$%^&*/test.html"));
+			u = new URL("http", "www.yahoo.com:8080", 1233, "");
+			assertTrue("returns a wrong file", u.getFile().equals(""));
+		} catch (Exception e) {
+			fail("Exception raised : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.net.URL#getHost()
+	 */
+	public void test_getHost() {
+		// Test for method java.lang.String java.net.URL.getHost()
+		assertTrue("Used to test", true);
+	}
+
+	/**
+	 * @tests java.net.URL#getPort()
+	 */
+	public void test_getPort() {
+		// Test for method int java.net.URL.getPort()
+		try {
+			u = new URL("http://member12.c++.com:9999");
+			assertTrue("return wrong port number " + u.getPort(),
+					u.getPort() == 9999);
+			u = new URL("http://member12.c++.com:9999/");
+			assertTrue("return wrong port number", u.getPort() == 9999);
+		} catch (Exception e) {
+			fail("Threw exception : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.net.URL#getProtocol()
+	 */
+	public void test_getProtocol() {
+		// Test for method java.lang.String java.net.URL.getProtocol()
+		try {
+			u = new URL("http://www.yahoo2.com:9999");
+			assertTrue("u returns a wrong protocol: " + u.getProtocol(), u
+					.getProtocol().equals("http"));
+
+		} catch (Exception e) {
+			fail("Threw exception : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.net.URL#getRef()
+	 */
+	public void test_getRef() {
+		// Test for method java.lang.String java.net.URL.getRef()
+		try {
+			u1 = new URL("http://www.yahoo2.com:9999");
+			u = new URL(
+					"http://www.yahoo1.com:8080/dir1/dir2/test.cgi?point1.html#anchor1");
+			assertTrue("returns a wrong anchor1", u.getRef().equals("anchor1"));
+			assertTrue("returns a wrong anchor2", u1.getRef() == null);
+			u1 = new URL("http://www.yahoo2.com#ref");
+			assertTrue("returns a wrong anchor3", u1.getRef().equals("ref"));
+			u1 = new URL("http://www.yahoo2.com/file#ref1#ref2");
+			assertTrue("returns a wrong anchor4", u1.getRef().equals(
+					"ref1#ref2"));
+		} catch (MalformedURLException e) {
+			fail("Incorrect URL format : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.net.URL#getAuthority()
+	 */
+	public void test_getAuthority() {
+		try {
+			URL url = new URL("http", "u:p@home", 80, "/java?q1#ref");
+			assertTrue("wrong authority: " + url.getAuthority(), url
+					.getAuthority().equals("u:p@home:80"));
+			assertTrue("wrong userInfo", url.getUserInfo().equals("u:p"));
+			assertTrue("wrong host", url.getHost().equals("home"));
+			assertTrue("wrong file", url.getFile().equals("/java?q1"));
+			assertTrue("wrong path", url.getPath().equals("/java"));
+			assertTrue("wrong query", url.getQuery().equals("q1"));
+			assertTrue("wrong ref", url.getRef().equals("ref"));
+
+			url = new URL("http", "home", -1, "/java");
+			assertTrue("wrong authority2", url.getAuthority().equals("home"));
+			assertTrue("wrong userInfo2", url.getUserInfo() == null);
+			assertTrue("wrong host2", url.getHost().equals("home"));
+			assertTrue("wrong file2", url.getFile().equals("/java"));
+			assertTrue("wrong path2", url.getPath().equals("/java"));
+			assertTrue("wrong query2", url.getQuery() == null);
+			assertTrue("wrong ref2", url.getRef() == null);
+		} catch (MalformedURLException e) {
+			fail("Unexpected MalformedURLException : " + e.getMessage());
+		}
+		;
+
+	}
+
+	/**
+	 * 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/net/UnknownHostExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/UnknownHostExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/UnknownHostExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/UnknownHostExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,67 @@
+/* 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.net;
+
+public class UnknownHostExceptionTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.net.UnknownHostException#UnknownHostException()
+	 */
+	public void test_Constructor() {
+		// Test for method java.net.UnknownHostException()
+		try {
+			try {
+				java.net.InetAddress.getByName("a.b.c.x.y.z.com");
+			} catch (java.net.UnknownHostException e) {
+				return;
+			}
+			fail("Failed to generate Exception");
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.net.UnknownHostException#UnknownHostException(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method java.net.UnknownHostException(java.lang.String)
+		try {
+			try {
+				java.net.InetAddress.getByName("a.b.c.x.y.z.com");
+			} catch (java.net.UnknownHostException e) {
+				return;
+			}
+			fail("Failed to generate Exception");
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * 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/net/UnknownServiceExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/UnknownServiceExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/UnknownServiceExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/UnknownServiceExceptionTest.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.net;
+
+import java.net.URL;
+import java.net.UnknownServiceException;
+
+public class UnknownServiceExceptionTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.net.UnknownServiceException#UnknownServiceException()
+	 */
+	public void test_Constructor() {
+		// Test for method java.net.UnknownServiceException()
+		try {
+			new URL("file://moo.txt").openConnection().getOutputStream();
+		} catch (UnknownServiceException e) {
+			// correct
+			return;
+		} catch (Exception e) {
+			fail("Wrong exception during test : " + e.getMessage());
+		}
+		fail("Exception not thrown");
+	}
+
+	/**
+	 * @tests java.net.UnknownServiceException#UnknownServiceException(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method java.net.UnknownServiceException(java.lang.String)
+		try {
+			if (true)
+				throw new UnknownServiceException("HelloWorld");
+		} catch (UnknownServiceException e) {
+			assertTrue("Wrong exception message: " + e.toString(), e
+					.getMessage().equals("HelloWorld"));
+			return;
+		}
+		fail("Constructor failed");
+	}
+
+	/**
+	 * 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/AbstractCollectionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractCollectionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractCollectionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractCollectionTest.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.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+
+public class AbstractCollectionTest extends junit.framework.TestCase {
+
+	Collection org;
+
+	/**
+	 * @tests java.util.AbstractCollection#add(java.lang.Object)
+	 */
+	public void test_addLjava_lang_Object() {
+		assertTrue("Nothing to test--unsupported operation", true);
+	}
+
+	/**
+	 * @tests java.util.AbstractCollection#addAll(java.util.Collection)
+	 */
+	public void test_addAllLjava_util_Collection() {
+		Collection col = new HashSet();
+		col.addAll(org);
+		assertTrue("Collection is wrong size after addAll--wanted: 100 got: "
+				+ col.size(), col.size() == 100);
+	}
+
+	/**
+	 * @tests java.util.AbstractCollection#containsAll(java.util.Collection)
+	 */
+	public void test_containsAllLjava_util_Collection() {
+		ArrayList col = new ArrayList(org);
+		assertTrue("Should contain all of the elements it started with", col
+				.containsAll(org));
+		col.remove(5);
+		assertTrue(
+				"Should no longer contain all of the elements it started with",
+				!col.containsAll(org));
+	}
+
+	/**
+	 * @tests java.util.AbstractCollection#isEmpty()
+	 */
+	public void test_isEmpty() {
+		Collection col = new ArrayList();
+		assertTrue("Should be empty when created", col.isEmpty());
+		col.addAll(org);
+		assertTrue("Should not be empty", !col.isEmpty());
+		col.clear();
+		assertTrue("Should be empty after clear", col.isEmpty());
+	}
+
+	/**
+	 * @tests java.util.AbstractCollection#removeAll(java.util.Collection)
+	 */
+	public void test_removeAllLjava_util_Collection() {
+		Collection someCol = new HashSet(org);
+		Collection anotherCol = new HashSet(org);
+		anotherCol.remove(new Integer(5));
+		someCol.removeAll(anotherCol);
+		assertTrue("Collection is the wrong size--wanted 1, got: "
+				+ someCol.size(), someCol.size() == 1);
+		someCol.remove(new Integer(5));
+		assertTrue("Collection is the wrong size--wanted 0, got: "
+				+ someCol.size(), someCol.size() == 0);
+	}
+
+	/**
+	 * @tests java.util.AbstractCollection#retainAll(java.util.Collection)
+	 */
+	public void test_retainAllLjava_util_Collection() {
+		Collection someCol = new HashSet(org);
+		Collection anotherCol = new HashSet(org);
+		anotherCol.remove(new Integer(5));
+		someCol.retainAll(anotherCol);
+		assertTrue("Collection is the wrong size--wanted 99, got: "
+				+ someCol.size(), someCol.size() == 99);
+		someCol.add(new Integer(5));
+		assertTrue("Collection is the wrong size--wanted 100, got: "
+				+ someCol.size(), someCol.size() == 100);
+	}
+
+	/**
+	 * @tests java.util.AbstractCollection#toArray()
+	 */
+	public void test_toArray() {
+		Object[] objArray = org.toArray();
+		assertTrue("The returned array is the wrong length--wanted 100, got: "
+				+ objArray.length, objArray.length == 100);
+		HashSet duplicates = new HashSet();
+		for (int i = objArray.length - 1; i >= 0; i--) {
+			assertTrue("The returned array has an incorrect value. At i = " + i
+					+ " got: " + ((Integer) objArray[i]).intValue(), org
+					.contains(objArray[i]));
+			assertTrue("Duplicate found at i = " + i, !duplicates
+					.contains(objArray[i]));
+			duplicates.add(objArray[i]);
+		}
+	}
+
+	/**
+	 * @tests java.util.AbstractCollection#toArray(java.lang.Object[])
+	 */
+	public void test_toArray$Ljava_lang_Object() {
+		Object[] objArray = new Object[100];
+		org.toArray(objArray);
+		assertTrue(
+				"a) The returned array is the wrong length--wanted 100, got: "
+						+ objArray.length, objArray.length == 100);
+		HashSet duplicates = new HashSet();
+		for (int i = objArray.length - 1; i >= 0; i--) {
+			assertTrue("a) The returned array has an incorrect value at i = "
+					+ i, org.contains(objArray[i]));
+			assertTrue("Duplicate found at i = " + i, !duplicates
+					.contains(objArray[i]));
+			duplicates.add(objArray[i]);
+		}
+
+		Integer[] intArray = new Integer[105];
+		intArray[100] = new Integer(1203);
+		org.toArray(intArray);
+		assertTrue(
+				"b) The returned array is the wrong length--wanted 105, got: "
+						+ intArray.length, intArray.length == 105);
+		duplicates = new HashSet();
+		for (int i = 99; i >= 0; i--) {
+			assertTrue("b) The returned array has an incorrect value at i = "
+					+ i, org.contains(intArray[i]));
+			assertTrue("Duplicate found at i = " + i, !duplicates
+					.contains(intArray[i]));
+			duplicates.add(intArray[i]);
+		}
+		assertTrue("End of list should be null", intArray[100] == null);
+
+		intArray = new Integer[1];
+		intArray = (Integer[]) org.toArray(intArray);
+		assertTrue(
+				"c) The returned array is the wrong length--wanted 100, got: "
+						+ intArray.length, intArray.length == 100);
+		duplicates = new HashSet();
+		for (int i = intArray.length - 1; i >= 0; i--) {
+			assertTrue("c) The returned array has an incorrect value. At i = "
+					+ i + " got: " + intArray[i].intValue(), org
+					.contains(intArray[i]));
+			assertTrue("Duplicate found at i = " + i, !duplicates
+					.contains(intArray[i]));
+			duplicates.add(intArray[i]);
+		}
+	}
+
+	protected void setUp() {
+		org = new HashSet();
+		for (int i = 0; i < 100; i++)
+			org.add(new Integer(i));
+
+	}
+
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractListTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractListTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractListTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractListTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,174 @@
+/* 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.AbstractList;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.RandomAccess;
+
+public class AbstractListTest extends junit.framework.TestCase {
+
+	static class SimpleList extends AbstractList {
+		ArrayList arrayList;
+
+		SimpleList() {
+			this.arrayList = new ArrayList();
+		}
+
+		public Object get(int index) {
+			return this.arrayList.get(index);
+		}
+
+		public void add(int i, Object o) {
+			this.arrayList.add(i, o);
+		}
+
+		public Object remove(int i) {
+			return this.arrayList.remove(i);
+		}
+
+		public int size() {
+			return this.arrayList.size();
+		}
+	}
+
+	/**
+	 * @tests java.util.AbstractList#hashCode()
+	 */
+	public void test_hashCode() {
+		List list = new ArrayList();
+		list.add(new Integer(3));
+		list.add(new Integer(15));
+		list.add(new Integer(5));
+		list.add(new Integer(1));
+		list.add(new Integer(7));
+		int hashCode = 1;
+		Iterator i = list.iterator();
+		while (i.hasNext()) {
+			Object obj = i.next();
+			hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
+		}
+		assertTrue("Incorrect hashCode returned.  Wanted: " + hashCode
+				+ " got: " + list.hashCode(), hashCode == list.hashCode());
+	}
+
+	/**
+	 * @tests java.util.AbstractList#iterator()
+	 */
+	public void test_iterator() {
+		SimpleList list = new SimpleList();
+		list.add(new Object());
+		list.add(new Object());
+		Iterator it = list.iterator();
+		it.next();
+		it.remove();
+		it.next();
+	}
+
+	/**
+	 * @tests java.util.AbstractList#listIterator()
+	 */
+	public void test_listIterator() {
+		Integer tempValue;
+		List list = new ArrayList();
+		list.add(new Integer(3));
+		list.add(new Integer(15));
+		list.add(new Integer(5));
+		list.add(new Integer(1));
+		list.add(new Integer(7));
+		ListIterator lit = list.listIterator();
+		assertTrue("Should not have previous", !lit.hasPrevious());
+		assertTrue("Should have next", lit.hasNext());
+		tempValue = (Integer) lit.next();
+		assertTrue("next returned wrong value.  Wanted 3, got: " + tempValue,
+				tempValue.intValue() == 3);
+		tempValue = (Integer) lit.previous();
+
+		SimpleList list2 = new SimpleList();
+		list2.add(new Object());
+		ListIterator lit2 = list2.listIterator();
+		lit2.add(new Object());
+		lit2.next();
+	}
+
+	/**
+	 * @tests java.util.AbstractList#subList(int, int)
+	 */
+	public void test_subListII() {
+		// Test each of the SubList operations to ensure a
+		// ConcurrentModificationException does not occur on an AbstractList
+		// which does not update modCount
+		SimpleList mList = new SimpleList();
+		mList.add(new Object());
+		mList.add(new Object());
+		List sList = mList.subList(0, 2);
+		sList.add(new Object()); // calls add(int, Object)
+		sList.get(0);
+
+		sList.add(0, new Object());
+		sList.get(0);
+
+		sList.addAll(Arrays.asList(new String[] { "1", "2" }));
+		sList.get(0);
+
+		sList.addAll(0, Arrays.asList(new String[] { "3", "4" }));
+		sList.get(0);
+
+		sList.remove(0);
+		sList.get(0);
+
+		ListIterator lit = sList.listIterator();
+		lit.add(new Object());
+		lit.next();
+		lit.remove();
+		lit.next();
+
+		sList.clear(); // calls removeRange()
+		sList.add(new Object());
+
+		// test the type of sublist that is returned
+		List al = new ArrayList();
+		for (int i = 0; i < 10; i++) {
+			al.add(new Integer(i));
+		}
+		assertTrue(
+				"Sublist returned should have implemented Random Access interface",
+				al.subList(3, 7) instanceof RandomAccess);
+
+		List ll = new LinkedList();
+		for (int i = 0; i < 10; i++) {
+			ll.add(new Integer(i));
+		}
+		assertTrue(
+				"Sublist returned should not have implemented Random Access interface",
+				!(ll.subList(3, 7) instanceof RandomAccess));
+
+	}
+
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+	}
+
+	protected void doneSuite() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractMapTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractMapTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractMapTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractMapTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,198 @@
+/* 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.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.IdentityHashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.WeakHashMap;
+
+public class AbstractMapTest extends junit.framework.TestCase {
+
+	static final String specialKey = "specialKey".intern();
+
+	static final String specialValue = "specialValue".intern();
+
+	// The impl of MyMap is not realistic, but serves to create a type
+	// that uses the default remove behavior.
+	class MyMap extends AbstractMap {
+		final Set mySet = new HashSet(1);
+
+		MyMap() {
+			mySet.add(new Map.Entry() {
+				public Object getKey() {
+					return specialKey;
+				}
+
+				public Object getValue() {
+					return specialValue;
+				}
+
+				public Object setValue(Object object) {
+					return null;
+				}
+			});
+		}
+
+		public Object put(Object key, Object value) {
+			return null;
+		}
+
+		public Set entrySet() {
+			return mySet;
+		}
+	}
+
+	/**
+	 * @tests java.util.AbstractMap#keySet()
+	 */
+	public void test_keySet() {
+		AbstractMap map1 = new HashMap(0);
+		assertSame("HashMap(0)", map1.keySet(), map1.keySet());
+
+		AbstractMap map2 = new HashMap(10);
+		assertSame("HashMap(10)", map2.keySet(), map2.keySet());
+
+		Map map3 = Collections.EMPTY_MAP;
+		assertSame("EMPTY_MAP", map3.keySet(), map3.keySet());
+
+		AbstractMap map4 = new IdentityHashMap(1);
+		assertSame("IdentityHashMap", map4.keySet(), map4.keySet());
+
+		AbstractMap map5 = new LinkedHashMap(122);
+		assertSame("LinkedHashMap", map5.keySet(), map5.keySet());
+
+		AbstractMap map6 = new TreeMap();
+		assertSame("TreeMap", map6.keySet(), map6.keySet());
+
+		AbstractMap map7 = new WeakHashMap();
+		assertSame("WeakHashMap", map7.keySet(), map7.keySet());
+	}
+
+	/**
+	 * @tests java.util.AbstractMap#remove(java.lang.Object)
+	 */
+	public void test_removeLjava_lang_Object() {
+		Object key = new Object();
+		Object value = new Object();
+
+		AbstractMap map1 = new HashMap(0);
+		map1.put("key", value);
+		assertSame("HashMap(0)", map1.remove("key"), value);
+
+		AbstractMap map4 = new IdentityHashMap(1);
+		map4.put(key, value);
+		assertSame("IdentityHashMap", map4.remove(key), value);
+
+		AbstractMap map5 = new LinkedHashMap(122);
+		map5.put(key, value);
+		assertSame("LinkedHashMap", map5.remove(key), value);
+
+		AbstractMap map6 = new TreeMap(new Comparator() {
+			// Bogus comparator
+			public int compare(Object object1, Object object2) {
+				return 0;
+			}
+		});
+		map6.put(key, value);
+		assertSame("TreeMap", map6.remove(key), value);
+
+		AbstractMap map7 = new WeakHashMap();
+		map7.put(key, value);
+		assertSame("WeakHashMap", map7.remove(key), value);
+
+		AbstractMap aSpecialMap = new MyMap();
+		aSpecialMap.put(specialKey, specialValue);
+		Object valueOut = aSpecialMap.remove(specialKey);
+		assertSame("MyMap", valueOut, specialValue);
+	}
+
+	/**
+	 * @tests java.util.AbstractMap#values()
+	 */
+	public void test_values() {
+		AbstractMap map1 = new HashMap(0);
+		assertSame("HashMap(0)", map1.values(), map1.values());
+
+		AbstractMap map2 = new HashMap(10);
+		assertSame("HashMap(10)", map2.values(), map2.values());
+
+		Map map3 = Collections.EMPTY_MAP;
+		assertSame("EMPTY_MAP", map3.values(), map3.values());
+
+		AbstractMap map4 = new IdentityHashMap(1);
+		assertSame("IdentityHashMap", map4.values(), map4.values());
+
+		AbstractMap map5 = new LinkedHashMap(122);
+		assertSame("IdentityHashMap", map5.values(), map5.values());
+
+		AbstractMap map6 = new TreeMap();
+		assertSame("TreeMap", map6.values(), map6.values());
+
+		AbstractMap map7 = new WeakHashMap();
+		assertSame("WeakHashMap", map7.values(), map7.values());
+	}
+
+	/**
+	 * @tests java.util.AbstractMap#clone()
+	 */
+	public void test_clone() {
+		class MyMap extends AbstractMap implements Cloneable {
+			private Map map = new HashMap();
+
+			public Set entrySet() {
+				return map.entrySet();
+			}
+
+			public Object put(Object key, Object value) {
+				return map.put(key, value);
+			}
+
+			public Map getMap() {
+				return map;
+			}
+
+			public Object clone() {
+				try {
+					return super.clone();
+				} catch (CloneNotSupportedException e) {
+					return null;
+				}
+			}
+		}
+		;
+		MyMap map = new MyMap();
+		map.put("one", "1");
+		Map.Entry entry = (Map.Entry) map.entrySet().iterator().next();
+		assertTrue("entry not added", entry.getKey() == "one"
+				&& entry.getValue() == "1");
+		MyMap mapClone = (MyMap) map.clone();
+		assertTrue("clone not shallow", map.getMap() == mapClone.getMap());
+	}
+
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AllTests.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AllTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AllTests.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,82 @@
+/* Copyright 2004 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 junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * TODO Type description
+ */
+public class AllTests {
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(AllTests.suite());
+	}
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite("Test for java.util");
+		// $JUnit-BEGIN$
+		suite.addTestSuite(ConcurrentModTest.class);
+
+		suite.addTestSuite(AbstractCollectionTest.class);
+		suite.addTestSuite(AbstractListTest.class);
+		suite.addTestSuite(AbstractMapTest.class);
+		suite.addTestSuite(ArrayListTest.class);
+		suite.addTestSuite(ArraysTest.class);
+		suite.addTestSuite(BitSetTest.class);
+		suite.addTestSuite(CalendarTest.class);
+		suite.addTestSuite(CollectionsTest.class);
+		suite.addTestSuite(ConcurrentModificationExceptionTest.class);
+		suite.addTestSuite(CurrencyTest.class);
+		suite.addTestSuite(DateTest.class);
+		suite.addTestSuite(EmptyStackExceptionTest.class);
+		suite.addTestSuite(EventObjectTest.class);
+		suite.addTestSuite(GregorianCalendarTest.class);
+		suite.addTestSuite(HashMapTest.class);
+		suite.addTestSuite(HashSetTest.class);
+		suite.addTestSuite(HashtableTest.class);
+		suite.addTestSuite(IdentityHashMapTest.class);
+		suite.addTestSuite(IdentityHashMap2Test.class);
+		suite.addTestSuite(LinkedHashMapTest.class);
+		suite.addTestSuite(LinkedHashSetTest.class);
+		suite.addTestSuite(LinkedListTest.class);
+		suite.addTestSuite(ListResourceBundleTest.class);
+		suite.addTestSuite(LocaleTest.class);
+		suite.addTestSuite(MissingResourceExceptionTest.class);
+		suite.addTestSuite(NoSuchElementExceptionTest.class);
+		suite.addTestSuite(ObservableTest.class);
+		suite.addTestSuite(PropertiesTest.class);
+		suite.addTestSuite(PropertyPermissionTest.class);
+		suite.addTestSuite(PropertyResourceBundleTest.class);
+		suite.addTestSuite(RandomTest.class);
+		suite.addTestSuite(ResourceBundleTest.class);
+		suite.addTestSuite(SimpleTimeZoneTest.class);
+		suite.addTestSuite(StackTest.class);
+		suite.addTestSuite(StringTokenizerTest.class);
+		suite.addTestSuite(TimerTest.class);
+		suite.addTestSuite(TimerTaskTest.class);
+		suite.addTestSuite(TimeZoneTest.class);
+		suite.addTestSuite(TooManyListenersExceptionTest.class);
+		suite.addTestSuite(TreeMapTest.class);
+		suite.addTestSuite(TreeSetTest.class);
+		suite.addTestSuite(VectorTest.class);
+		suite.addTestSuite(WeakHashMapTest.class);
+		// $JUnit-END$
+
+		return suite;
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArrayListTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArrayListTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArrayListTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ArrayListTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,483 @@
+/* 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.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import tests.support.Support_ListTest;
+
+public class ArrayListTest extends junit.framework.TestCase {
+
+	List alist;
+
+	static Object[] objArray;
+	{
+		objArray = new Object[100];
+		for (int i = 0; i < objArray.length; i++)
+			objArray[i] = new Integer(i);
+	}
+
+	/**
+	 * @tests java.util.ArrayList#ArrayList()
+	 */
+	public void test_Constructor() {
+		// Test for method java.util.ArrayList()
+		new Support_ListTest("", alist).runTest();
+
+		ArrayList subList = new ArrayList();
+		for (int i = -50; i < 150; i++)
+			subList.add(new Integer(i));
+		new Support_ListTest("", subList.subList(50, 150)).runTest();
+	}
+
+	/**
+	 * @tests java.util.ArrayList#ArrayList(int)
+	 */
+	public void test_ConstructorI() {
+		// Test for method java.util.ArrayList(int)
+		ArrayList al = new ArrayList(5);
+		assertTrue("Incorrect arrayList created", al.size() == 0);
+	}
+
+	/**
+	 * @tests java.util.ArrayList#ArrayList(java.util.Collection)
+	 */
+	public void test_ConstructorLjava_util_Collection() {
+		// Test for method java.util.ArrayList(java.util.Collection)
+		ArrayList al = new ArrayList(Arrays.asList(objArray));
+		assertTrue("arrayList created from collection has incorrect size", al
+				.size() == objArray.length);
+		for (int counter = 0; counter < objArray.length; counter++)
+			assertTrue(
+					"arrayList created from collection has incorrect elements",
+					al.get(counter) == objArray[counter]);
+
+	}
+
+	/**
+	 * @tests java.util.ArrayList#add(int, java.lang.Object)
+	 */
+	public void test_addILjava_lang_Object() {
+		// Test for method void java.util.ArrayList.add(int, java.lang.Object)
+		Object o;
+		alist.add(50, o = new Object());
+		assertTrue("Failed to add Object", alist.get(50) == o);
+		assertTrue("Failed to fix up list after insert",
+				alist.get(51) == objArray[50]
+						&& (alist.get(52) == objArray[51]));
+		Object oldItem = alist.get(25);
+		alist.add(25, null);
+		assertTrue("Should have returned null", alist.get(25) == null);
+		assertTrue("Should have returned the old item from slot 25", alist
+				.get(26) == oldItem);
+	}
+
+	/**
+	 * @tests java.util.ArrayList#add(java.lang.Object)
+	 */
+	public void test_addLjava_lang_Object() {
+		// Test for method boolean java.util.ArrayList.add(java.lang.Object)
+		Object o = new Object();
+		alist.add(o);
+		assertTrue("Failed to add Object", alist.get(alist.size() - 1) == o);
+		alist.add(null);
+		assertTrue("Failed to add null", alist.get(alist.size() - 1) == null);
+	}
+
+	/**
+	 * @tests java.util.ArrayList#addAll(int, java.util.Collection)
+	 */
+	public void test_addAllILjava_util_Collection() {
+		// Test for method boolean java.util.ArrayList.addAll(int,
+		// java.util.Collection)
+		alist.addAll(50, alist);
+		assertTrue("Returned incorrect size after adding to existing list",
+				alist.size() == 200);
+		for (int i = 0; i < 50; i++)
+			assertTrue("Manipulated elements < index",
+					alist.get(i) == objArray[i]);
+		for (int i = 0; i >= 50 && (i < 150); i++)
+			assertTrue("Failed to ad elements properly",
+					alist.get(i) == objArray[i - 50]);
+		for (int i = 0; i >= 150 && (i < 200); i++)
+			assertTrue("Failed to ad elements properly",
+					alist.get(i) == objArray[i - 100]);
+		ArrayList listWithNulls = new ArrayList();
+		listWithNulls.add(null);
+		listWithNulls.add(null);
+		listWithNulls.add("yoink");
+		listWithNulls.add("kazoo");
+		listWithNulls.add(null);
+		alist.addAll(100, listWithNulls);
+		assertTrue("Incorrect size: " + alist.size(), alist.size() == 205);
+		assertTrue("Item at slot 100 should be null", alist.get(100) == null);
+		assertTrue("Item at slot 101 should be null", alist.get(101) == null);
+		assertTrue("Item at slot 102 should be 'yoink'", alist.get(102).equals(
+				"yoink"));
+		assertTrue("Item at slot 103 should be 'kazoo'", alist.get(103).equals(
+				"kazoo"));
+		assertTrue("Item at slot 104 should be null", alist.get(104) == null);
+		alist.addAll(205, listWithNulls);
+		assertTrue("Incorrect size2: " + alist.size(), alist.size() == 210);
+	}
+
+	/**
+	 * @tests java.util.ArrayList#addAll(java.util.Collection)
+	 */
+	public void test_addAllLjava_util_Collection() {
+		// Test for method boolean
+		// java.util.ArrayList.addAll(java.util.Collection)
+		List l = new ArrayList();
+		l.addAll(alist);
+		for (int i = 0; i < alist.size(); i++)
+			assertTrue("Failed to add elements properly", l.get(i).equals(
+					alist.get(i)));
+		alist.addAll(alist);
+		assertTrue("Returned incorrect size after adding to existing list",
+				alist.size() == 200);
+		for (int i = 0; i < 100; i++) {
+			assertTrue("Added to list in incorrect order", alist.get(i)
+					.equals(l.get(i)));
+			assertTrue("Failed to add to existing list", alist.get(i + 100)
+					.equals(l.get(i)));
+		}
+		Set setWithNulls = new HashSet();
+		setWithNulls.add(null);
+		setWithNulls.add(null);
+		setWithNulls.add("yoink");
+		setWithNulls.add("kazoo");
+		setWithNulls.add(null);
+		alist.addAll(100, setWithNulls);
+		Iterator i = setWithNulls.iterator();
+		assertTrue("Item at slot 100 is wrong: " + alist.get(100), alist
+				.get(100) == i.next());
+		assertTrue("Item at slot 101 is wrong: " + alist.get(101), alist
+				.get(101) == i.next());
+		assertTrue("Item at slot 103 is wrong: " + alist.get(102), alist
+				.get(102) == i.next());
+
+	}
+
+	/**
+	 * @tests java.util.ArrayList#clear()
+	 */
+	public void test_clear() {
+		// Test for method void java.util.ArrayList.clear()
+		alist.clear();
+		assertTrue("List did not clear", alist.size() == 0);
+		alist.add(null);
+		alist.add(null);
+		alist.add(null);
+		alist.add("bam");
+		alist.clear();
+		assertTrue("List with nulls did not clear", alist.size() == 0);
+		/*
+		 * for (int i = 0; i < alist.size(); i++) assertTrue("Failed to clear
+		 * list", alist.get(i) == null);
+		 */
+
+	}
+
+	/**
+	 * @tests java.util.ArrayList#clone()
+	 */
+	public void test_clone() {
+		// Test for method java.lang.Object java.util.ArrayList.clone()
+		ArrayList x = (ArrayList) (((ArrayList) (alist)).clone());
+		assertTrue("Cloned list was inequal to original", x.equals(alist));
+		for (int i = 0; i < alist.size(); i++)
+			assertTrue("Cloned list contains incorrect elements",
+					alist.get(i) == x.get(i));
+
+		alist.add(null);
+		alist.add(25, null);
+		x = (ArrayList) (((ArrayList) (alist)).clone());
+		assertTrue("nulls test - Cloned list was inequal to original", x
+				.equals(alist));
+		for (int i = 0; i < alist.size(); i++)
+			assertTrue("nulls test - Cloned list contains incorrect elements",
+					alist.get(i) == x.get(i));
+
+	}
+
+	/**
+	 * @tests java.util.ArrayList#contains(java.lang.Object)
+	 */
+	public void test_containsLjava_lang_Object() {
+		// Test for method boolean
+		// java.util.ArrayList.contains(java.lang.Object)
+		assertTrue("Returned false for valid element", alist
+				.contains(objArray[99]));
+		assertTrue("Returned false for equal element", alist
+				.contains(new Integer(8)));
+		assertTrue("Returned true for invalid element", !alist
+				.contains(new Object()));
+		assertTrue("Returned true for null but should have returned false",
+				!alist.contains(null));
+		alist.add(null);
+		assertTrue("Returned false for null but should have returned true",
+				alist.contains(null));
+	}
+
+	/**
+	 * @tests java.util.ArrayList#ensureCapacity(int)
+	 */
+	public void test_ensureCapacityI() {
+		// Test for method void java.util.ArrayList.ensureCapacity(int)
+		// TODO : There is no good way to test this as it only really impacts on
+		// the private implementation.
+
+		Object testObject = new Object();
+		int capacity = 20;
+		ArrayList al = new ArrayList(capacity);
+		int i;
+		for (i = 0; i < capacity / 2; i++) {
+			al.add(i, new Object());
+		}
+		al.add(i, testObject);
+		int location = al.indexOf(testObject);
+		try {
+			al.ensureCapacity(capacity);
+			assertTrue("EnsureCapacity moved objects around in array1.",
+					location == al.indexOf(testObject));
+			al.remove(0);
+			al.ensureCapacity(capacity);
+			assertTrue("EnsureCapacity moved objects around in array2.",
+					--location == al.indexOf(testObject));
+			al.ensureCapacity(capacity + 2);
+			assertTrue("EnsureCapacity did not change location.",
+					location == al.indexOf(testObject));
+		} catch (Exception e) {
+			fail("Exception during test : " + e.getMessage());
+		}
+	}
+
+	/**
+	 * @tests java.util.ArrayList#get(int)
+	 */
+	public void test_getI() {
+		// Test for method java.lang.Object java.util.ArrayList.get(int)
+		assertTrue("Returned incorrect element", alist.get(22) == objArray[22]);
+		try {
+			alist.get(8765);
+		} catch (IndexOutOfBoundsException e) {
+			// Correct
+			return;
+		}
+		fail("Failed to throw expected exception for index > size");
+	}
+
+	/**
+	 * @tests java.util.ArrayList#indexOf(java.lang.Object)
+	 */
+	public void test_indexOfLjava_lang_Object() {
+		// Test for method int java.util.ArrayList.indexOf(java.lang.Object)
+		assertTrue("Returned incorrect index",
+				alist.indexOf(objArray[87]) == 87);
+		assertTrue("Returned index for invalid Object", alist
+				.indexOf(new Object()) == -1);
+		alist.add(25, null);
+		alist.add(50, null);
+		assertTrue("Wrong indexOf for null.  Wanted 25 got: "
+				+ alist.indexOf(null), alist.indexOf(null) == 25);
+	}
+
+	/**
+	 * @tests java.util.ArrayList#isEmpty()
+	 */
+	public void test_isEmpty() {
+		// Test for method boolean java.util.ArrayList.isEmpty()
+		assertTrue("isEmpty returned false for new list", new ArrayList()
+				.isEmpty());
+		assertTrue("Returned true for existing list with elements", !alist
+				.isEmpty());
+	}
+
+	/**
+	 * @tests java.util.ArrayList#lastIndexOf(java.lang.Object)
+	 */
+	public void test_lastIndexOfLjava_lang_Object() {
+		// Test for method int java.util.ArrayList.lastIndexOf(java.lang.Object)
+		alist.add(new Integer(99));
+		assertTrue("Returned incorrect index",
+				alist.lastIndexOf(objArray[99]) == 100);
+		assertTrue("Returned index for invalid Object", alist
+				.lastIndexOf(new Object()) == -1);
+		alist.add(25, null);
+		alist.add(50, null);
+		assertTrue("Wrong lastIndexOf for null.  Wanted 50 got: "
+				+ alist.lastIndexOf(null), alist.lastIndexOf(null) == 50);
+	}
+
+	/**
+	 * @tests java.util.ArrayList#remove(int)
+	 */
+	public void test_removeI() {
+		// Test for method java.lang.Object java.util.ArrayList.remove(int)
+		alist.remove(10);
+		assertTrue("Failed to remove element",
+				alist.indexOf(objArray[10]) == -1);
+		boolean exception = false;
+		try {
+			alist.remove(999);
+		} catch (IndexOutOfBoundsException e) {
+			// Correct
+			exception = true;
+		}
+		assertTrue("Failed to throw exception when index out of range",
+				exception);
+
+		ArrayList myList = (ArrayList) (((ArrayList) (alist)).clone());
+		alist.add(25, null);
+		alist.add(50, null);
+		alist.remove(50);
+		alist.remove(25);
+		assertTrue("Removing nulls did not work", alist.equals(myList));
+
+		List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c",
+				"d", "e", "f", "g" }));
+		assertTrue("Removed wrong element 1", list.remove(0) == "a");
+		assertTrue("Removed wrong element 2", list.remove(4) == "f");
+		String[] result = new String[5];
+		list.toArray(result);
+		assertTrue("Removed wrong element 3", Arrays.equals(result,
+				new String[] { "b", "c", "d", "e", "g" }));
+
+		List l = new ArrayList(0);
+		l.add(new Object());
+		l.add(new Object());
+		l.remove(0);
+		l.remove(0);
+		try {
+			l.remove(-1);
+			fail("-1 should cause exception");
+		} catch (IndexOutOfBoundsException e) {
+		}
+		try {
+			l.remove(0);
+			fail("0 should case exception");
+		} catch (IndexOutOfBoundsException e) {
+		}
+	}
+
+	/**
+	 * @tests java.util.ArrayList#set(int, java.lang.Object)
+	 */
+	public void test_setILjava_lang_Object() {
+		// Test for method java.lang.Object java.util.ArrayList.set(int,
+		// java.lang.Object)
+		Object obj;
+		alist.set(65, obj = new Object());
+		assertTrue("Failed to set object", alist.get(65) == obj);
+		alist.set(50, null);
+		assertTrue("Setting to null did not work", alist.get(50) == null);
+		assertTrue("Setting increased the list's size to: " + alist.size(),
+				alist.size() == 100);
+	}
+
+	/**
+	 * @tests java.util.ArrayList#size()
+	 */
+	public void test_size() {
+		// Test for method int java.util.ArrayList.size()
+		assertTrue("Returned incorrect size for exiting list",
+				alist.size() == 100);
+		assertTrue("Returned incorrect size for new list", new ArrayList()
+				.size() == 0);
+	}
+
+	/**
+	 * @tests java.util.ArrayList#toArray()
+	 */
+	public void test_toArray() {
+		// Test for method java.lang.Object [] java.util.ArrayList.toArray()
+		alist.set(25, null);
+		alist.set(75, null);
+		Object[] obj = alist.toArray();
+		assertEquals("Returned array of incorrect size", objArray.length,
+				obj.length);
+
+		for (int i = 0; i < obj.length; i++) {
+			if ((i == 25) || (i == 75))
+				assertTrue("Should be null at: " + i + " but instead got: "
+						+ obj[i], obj[i] == null);
+			else
+				assertTrue("Returned incorrect array: " + i,
+						obj[i] == objArray[i]);
+		}
+
+	}
+
+	/**
+	 * @tests java.util.ArrayList#toArray(java.lang.Object[])
+	 */
+	public void test_toArray$Ljava_lang_Object() {
+		// Test for method java.lang.Object []
+		// java.util.ArrayList.toArray(java.lang.Object [])
+		alist.set(25, null);
+		alist.set(75, null);
+		Integer[] argArray = new Integer[100];
+		Object[] retArray;
+		retArray = alist.toArray(argArray);
+		assertTrue("Returned different array than passed", retArray == argArray);
+		argArray = new Integer[1000];
+		retArray = alist.toArray(argArray);
+		assertTrue("Failed to set first extra element to null", argArray[alist
+				.size()] == null);
+		for (int i = 0; i < 100; i++) {
+			if ((i == 25) || (i == 75))
+				assertTrue("Should be null: " + i, retArray[i] == null);
+			else
+				assertTrue("Returned incorrect array: " + i,
+						retArray[i] == objArray[i]);
+		}
+	}
+
+	/**
+	 * @tests java.util.ArrayList#trimToSize()
+	 */
+	public void test_trimToSize() {
+		// Test for method void java.util.ArrayList.trimToSize()
+		for (int i = 99; i > 24; i--)
+			alist.remove(i);
+		((ArrayList) alist).trimToSize();
+		assertTrue("Returned incorrect size after trim", alist.size() == 25);
+		for (int i = 0; i < alist.size(); i++)
+			assertTrue("Trimmed list contained incorrect elements", alist
+					.get(i) == objArray[i]);
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() {
+		alist = new ArrayList();
+		for (int i = 0; i < objArray.length; i++)
+			alist.add(objArray[i]);
+	}
+
+	/**
+	 * 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