harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r378067 - in /incubator/harmony/enhanced/classlib/trunk/modules/archive/src: main/java/java/util/jar/ test/java/org/apache/harmony/tests/java/util/jar/
Date Wed, 15 Feb 2006 19:20:41 GMT
Author: tellison
Date: Wed Feb 15 11:20:39 2006
New Revision: 378067

URL: http://svn.apache.org/viewcvs?rev=378067&view=rev
Log:
Fix for HARMONY-79 (java.util.jar.Attributes.put(Object name, Object value) doesn't throw
ClassCastException)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/jar/AttributesTest.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/jar/AllTests.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java?rev=378067&r1=378066&r2=378067&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java
Wed Feb 15 11:20:39 2006
@@ -229,14 +229,14 @@
 	 *                String
 	 */
 	public Object put(Object key, Object value) {
-		return map.put(key, value);
+		return map.put((Name)key, (String)value);
 	}
 
 	/**
 	 * putAll method comment.
 	 */
 	public void putAll(Map attrib) {
-		this.map.putAll(attrib);
+		this.map.putAll((Attributes)attrib);
 	}
 
 	/**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/jar/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/jar/AllTests.java?rev=378067&r1=378066&r2=378067&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/jar/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/jar/AllTests.java
Wed Feb 15 11:20:39 2006
@@ -29,6 +29,7 @@
 				"Test for org.apache.harmony.tests.java.util.jar");
 		//$JUnit-BEGIN$
 		suite.addTestSuite(ManifestTest.class);
+		suite.addTestSuite(AttributesTest.class);
 		suite.addTestSuite(AttributesNameTest.class);
 		//$JUnit-END$
 		return suite;

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/jar/AttributesTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/jar/AttributesTest.java?rev=378067&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/jar/AttributesTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/jar/AttributesTest.java
Wed Feb 15 11:20:39 2006
@@ -0,0 +1,76 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.util.jar;
+
+import java.util.Collections;
+import java.util.jar.Attributes;
+
+import junit.framework.TestCase;
+
+public class AttributesTest extends TestCase {
+
+	/*
+	 * @tests java.util.jar.Attributes.put(java.lang.Object, java.lang.Object)
+	 */
+	public void test_putLjava_lang_ObjectLjava_lang_Object() {
+		Attributes atts = new Attributes();
+		assertNull("Assert 0: ",
+				atts.put(Attributes.Name.CLASS_PATH, "tools.jar"));
+		assertEquals("Assert 1: ", "tools.jar", 
+				atts.getValue(Attributes.Name.CLASS_PATH));
+
+		// Regression for HARMONY-79
+		try {
+			atts.put("not a name", "value");
+			fail("Assert 2: no class cast from key parameter");
+		} catch (ClassCastException e) {
+			// Expected
+		}
+
+		try {
+			atts.put(Attributes.Name.CLASS_PATH, Boolean.TRUE);
+			fail("Assert 3: no class cast from value parameter");
+		} catch (ClassCastException e) {
+			// Expected
+		}
+	}
+
+	/**
+	 * @tests java.util.jar.Attributes.putAll(java.util.Map)
+	 */
+	public void test_putAllLjava_util_Map() {
+		Attributes atts = new Attributes();
+		assertNull("Assert 0: ",
+				atts.put(Attributes.Name.CLASS_PATH, "tools.jar"));
+		assertNull("Assert 1: ", 
+				atts.put(Attributes.Name.MANIFEST_VERSION, "1"));
+
+		Attributes atts2 = new Attributes();
+		atts2.putAll(atts);
+
+		assertEquals("Assert 2:", "tools.jar", 
+				atts2.get(Attributes.Name.CLASS_PATH));
+		assertEquals("Assert 3: ", "1", 
+				atts2.get(Attributes.Name.MANIFEST_VERSION));
+
+		try {
+			atts.putAll(Collections.EMPTY_MAP);
+			fail("Assert 4: no class cast from attrib parameter");
+		} catch (ClassCastException e) {
+			// Expected
+		}
+	}
+}



Mime
View raw message