You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/10/26 05:29:06 UTC
svn commit: r467851 - in
/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar:
AttributesTest.java JarEntryTest.java JarExceptionTest.java
JarFileTest.java JarInputStreamTest.java
Author: ndbeyer
Date: Wed Oct 25 20:29:06 2006
New Revision: 467851
URL: http://svn.apache.org/viewvc?view=rev&rev=467851
Log:
Cleanup JUnits.
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesTest.java
incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarEntryTest.java
incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarExceptionTest.java
incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java
incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarInputStreamTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesTest.java?view=diff&rev=467851&r1=467850&r2=467851
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesTest.java Wed Oct 25 20:29:06 2006
@@ -14,202 +14,166 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.harmony.archive.tests.java.util.jar;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import java.util.Collections;
import java.util.jar.Attributes;
+import junit.framework.TestCase;
-public class AttributesTest extends junit.framework.TestCase {
+public class AttributesTest extends TestCase {
+ private Attributes a;
- Attributes a;
+ @Override
+ protected void setUp() {
+ a = new Attributes();
+ a.putValue("1", "one");
+ a.putValue("2", "two");
+ a.putValue("3", "three");
+ a.putValue("4", "four");
+ }
- /**
- * @tests java.util.jar.Attributes#Attributes()
- */
- public void test_Constructor() {
- // Test for method java.util.jar.Attributes()
- assertTrue("Used to test", true);
- }
-
- /**
- * @tests java.util.jar.Attributes#Attributes(java.util.jar.Attributes)
- */
- public void test_ConstructorLjava_util_jar_Attributes() {
- Attributes a2 = new Attributes(a);
- assertTrue("not equal", a.equals(a2));
- a.putValue("1", "one(1)");
- assertTrue("equal", !a.equals(a2));
- }
-
- /**
- * @tests java.util.jar.Attributes#clear()
- */
- public void test_clear() {
- // Test for method void java.util.jar.Attributes.clear()
- a.clear();
- assertNull("a) All entries should be null after clear",
- a.get("1"));
- assertNull("b) All entries should be null after clear",
- a.get("2"));
- assertNull("c) All entries should be null after clear",
- a.get("3"));
- assertNull("d) All entries should be null after clear",
- a.get("4"));
- assertTrue("Should not contain any keys", !a.containsKey("1"));
- }
-
- /**
- * @tests java.util.jar.Attributes#containsKey(java.lang.Object)
- */
- public void test_containsKeyLjava_lang_Object() {
- // Test for method boolean
- // java.util.jar.Attributes.containsKey(java.lang.Object)
- assertTrue("a) Should have returned false", !a.containsKey(new Integer(
- 1)));
- assertTrue("b) Should have returned false", !a.containsKey("0"));
- assertTrue("Should have returned true", a
- .containsKey(new Attributes.Name("1")));
- }
-
- /**
- * @tests java.util.jar.Attributes#containsValue(java.lang.Object)
- */
- public void test_containsValueLjava_lang_Object() {
- // Test for method boolean
- // java.util.jar.Attributes.containsValue(java.lang.Object)
- assertTrue("Should have returned false", !a.containsValue("One"));
- assertTrue("Should have returned true", a.containsValue("one"));
-
- }
-
- /**
- * @tests java.util.jar.Attributes#entrySet()
- */
- public void test_entrySet() {
- // Test for method java.util.Set java.util.jar.Attributes.entrySet()
- Set<Map.Entry<Object, Object>> entrySet = a.entrySet();
- Set<Object> keySet = new HashSet<Object>();
- Set<Object> valueSet = new HashSet<Object>();
- Iterator<?> i;
- assertTrue("Wrong size--Wanted: 4, got: " + entrySet.size(), entrySet
- .size() == 4);
- i = entrySet.iterator();
- while (i.hasNext()) {
- java.util.Map.Entry<?, ?> e;
- e = (Map.Entry<?, ?>) i.next();
- keySet.add(e.getKey());
- valueSet.add(e.getValue());
- }
-
- assertTrue("a) Should contain entry", valueSet.contains("one"));
- assertTrue("b) Should contain entry", valueSet.contains("two"));
- assertTrue("c) Should contain entry", valueSet.contains("three"));
- assertTrue("d) Should contain entry", valueSet.contains("four"));
-
- assertTrue("a) Should contain key", keySet
- .contains(new Attributes.Name("1")));
- assertTrue("b) Should contain key", keySet
- .contains(new Attributes.Name("2")));
- assertTrue("c) Should contain key", keySet
- .contains(new Attributes.Name("3")));
- assertTrue("d) Should contain key", keySet
- .contains(new Attributes.Name("4")));
- }
-
- /**
- * @tests java.util.jar.Attributes#get(java.lang.Object)
- */
- public void test_getLjava_lang_Object() {
- // Test for method java.lang.Object
- // java.util.jar.Attributes.get(java.lang.Object)
- assertEquals("a) Incorrect value returned", "one", a.getValue("1"));
- assertNull("b) Incorrect value returned", a.getValue("0"));
- }
-
- /**
- * @tests java.util.jar.Attributes#isEmpty()
- */
- public void test_isEmpty() {
- // Test for method boolean java.util.jar.Attributes.isEmpty()
- assertTrue("Should not be empty", !a.isEmpty());
- a.clear();
- assertTrue("a) Should be empty", a.isEmpty());
- a = new Attributes();
- assertTrue("b) Should be empty", a.isEmpty());
- }
-
- /**
- * @tests java.util.jar.Attributes#keySet()
- */
- public void test_keySet() {
- // Test for method java.util.Set java.util.jar.Attributes.keySet()
- Set<?> s = a.keySet();
- assertTrue("Wrong size--Wanted: 4, got: " + s.size(), s.size() == 4);
- assertTrue("a) Should contain entry", s.contains(new Attributes.Name(
- "1")));
- assertTrue("b) Should contain entry", s.contains(new Attributes.Name(
- "2")));
- assertTrue("c) Should contain entry", s.contains(new Attributes.Name(
- "3")));
- assertTrue("d) Should contain entry", s.contains(new Attributes.Name(
- "4")));
- }
-
- /**
- * @tests java.util.jar.Attributes#putAll(java.util.Map)
- */
- public void test_putAllLjava_util_Map() {
- // Test for method void java.util.jar.Attributes.putAll(java.util.Map)
- Attributes b = new Attributes();
- b.putValue("3", "san");
- b.putValue("4", "shi");
- b.putValue("5", "go");
- b.putValue("6", "roku");
- a.putAll(b);
- assertEquals("Should not have been replaced",
- "one", a.getValue("1"));
- assertEquals("Should have been replaced", "san", a.getValue("3"));
- assertEquals("Should have been added", "go", a.getValue("5"));
-
- 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"));
+ /**
+ * @tests java.util.jar.Attributes#Attributes(java.util.jar.Attributes)
+ */
+ public void test_ConstructorLjava_util_jar_Attributes() {
+ Attributes a2 = new Attributes(a);
+ assertEquals(a, a2);
+ a.putValue("1", "one(1)");
+ assertTrue("equal", !a.equals(a2));
+ }
- Attributes atts2 = new Attributes();
- atts2.putAll(atts);
+ /**
+ * @tests java.util.jar.Attributes#clear()
+ */
+ public void test_clear() {
+ a.clear();
+ assertNull("a) All entries should be null after clear", a.get("1"));
+ assertNull("b) All entries should be null after clear", a.get("2"));
+ assertNull("c) All entries should be null after clear", a.get("3"));
+ assertNull("d) All entries should be null after clear", a.get("4"));
+ assertTrue("Should not contain any keys", !a.containsKey("1"));
+ }
+
+ /**
+ * @tests java.util.jar.Attributes#containsKey(java.lang.Object)
+ */
+ public void test_containsKeyLjava_lang_Object() {
+ assertTrue("a) Should have returned false", !a.containsKey(new Integer(1)));
+ assertTrue("b) Should have returned false", !a.containsKey("0"));
+ assertTrue("Should have returned true", a.containsKey(new Attributes.Name("1")));
+ }
+
+ /**
+ * @tests java.util.jar.Attributes#containsValue(java.lang.Object)
+ */
+ public void test_containsValueLjava_lang_Object() {
+ assertTrue("Should have returned false", !a.containsValue("One"));
+ assertTrue("Should have returned true", a.containsValue("one"));
+ }
+
+ /**
+ * @tests java.util.jar.Attributes#entrySet()
+ */
+ public void test_entrySet() {
+ Set<Map.Entry<Object, Object>> entrySet = a.entrySet();
+ Set<Object> keySet = new HashSet<Object>();
+ Set<Object> valueSet = new HashSet<Object>();
+ Iterator<?> i;
+ assertEquals(4, entrySet.size());
+ i = entrySet.iterator();
+ while (i.hasNext()) {
+ java.util.Map.Entry<?, ?> e;
+ e = (Map.Entry<?, ?>) i.next();
+ keySet.add(e.getKey());
+ valueSet.add(e.getValue());
+ }
+ assertTrue("a) Should contain entry", valueSet.contains("one"));
+ assertTrue("b) Should contain entry", valueSet.contains("two"));
+ assertTrue("c) Should contain entry", valueSet.contains("three"));
+ assertTrue("d) Should contain entry", valueSet.contains("four"));
+ assertTrue("a) Should contain key", keySet.contains(new Attributes.Name("1")));
+ assertTrue("b) Should contain key", keySet.contains(new Attributes.Name("2")));
+ assertTrue("c) Should contain key", keySet.contains(new Attributes.Name("3")));
+ assertTrue("d) Should contain key", keySet.contains(new Attributes.Name("4")));
+ }
+
+ /**
+ * @tests java.util.jar.Attributes#get(java.lang.Object)
+ */
+ public void test_getLjava_lang_Object() {
+ assertEquals("a) Incorrect value returned", "one", a.getValue("1"));
+ assertNull("b) Incorrect value returned", a.getValue("0"));
+ }
+
+ /**
+ * @tests java.util.jar.Attributes#isEmpty()
+ */
+ public void test_isEmpty() {
+ assertTrue("Should not be empty", !a.isEmpty());
+ a.clear();
+ assertTrue("a) Should be empty", a.isEmpty());
+ a = new Attributes();
+ assertTrue("b) Should be empty", a.isEmpty());
+ }
- assertEquals("Assert 2:", "tools.jar",
- atts2.get(Attributes.Name.CLASS_PATH));
- assertEquals("Assert 3: ", "1",
- atts2.get(Attributes.Name.MANIFEST_VERSION));
+ /**
+ * @tests java.util.jar.Attributes#keySet()
+ */
+ public void test_keySet() {
+ Set<?> s = a.keySet();
+ assertEquals(4, s.size());
+ assertTrue("a) Should contain entry", s.contains(new Attributes.Name("1")));
+ assertTrue("b) Should contain entry", s.contains(new Attributes.Name("2")));
+ assertTrue("c) Should contain entry", s.contains(new Attributes.Name("3")));
+ assertTrue("d) Should contain entry", s.contains(new Attributes.Name("4")));
+ }
+ /**
+ * @tests java.util.jar.Attributes#putAll(java.util.Map)
+ */
+ public void test_putAllLjava_util_Map() {
+ Attributes b = new Attributes();
+ b.putValue("3", "san");
+ b.putValue("4", "shi");
+ b.putValue("5", "go");
+ b.putValue("6", "roku");
+ a.putAll(b);
+ assertEquals("Should not have been replaced", "one", a.getValue("1"));
+ assertEquals("Should have been replaced", "san", a.getValue("3"));
+ assertEquals("Should have been added", "go", a.getValue("5"));
+ 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
}
- }
+ }
/**
* @tests java.util.jar.Attributes#putAll(java.util.Map)
*/
public void test_putAllLjava_util_Map2() {
- //Regression for HARMONY-464
+ // Regression for HARMONY-464
try {
new Attributes().putAll((Map) null);
fail("ClassCastException expected");
} catch (ClassCastException e) {
}
-
- //verify that special care for null is done in the Attributes.putAll() method
+ // verify that special care for null is done in the Attributes.putAll()
+ // method
try {
new Attributes() {
@Override
@@ -222,93 +186,68 @@
}
}
- /**
- * @tests java.util.jar.Attributes#remove(java.lang.Object)
- */
- public void test_removeLjava_lang_Object() {
- // Test for method java.lang.Object
- // java.util.jar.Attributes.remove(java.lang.Object)
- a.remove(new Attributes.Name("1"));
- a.remove(new Attributes.Name("3"));
- assertNull("Should have been removed", a.getValue("1"));
- assertEquals("Should not have been removed",
- "four", a.getValue("4"));
- }
-
- /**
- * @tests java.util.jar.Attributes#size()
- */
- public void test_size() {
- // Test for method int java.util.jar.Attributes.size()
- assertEquals("Incorrect size returned", 4, a.size());
- a.clear();
- assertTrue("Should have returned 0 size, but got: " + a.size(), a
- .size() == 0);
- }
-
- /**
- * @tests java.util.jar.Attributes#values()
- */
- public void test_values() {
- // Test for method java.util.Collection
- // java.util.jar.Attributes.values()
- Collection<?> valueCollection = a.values();
- assertTrue("a) Should contain entry", valueCollection.contains("one"));
- assertTrue("b) Should contain entry", valueCollection.contains("two"));
- assertTrue("c) Should contain entry", valueCollection.contains("three"));
- assertTrue("d) Should contain entry", valueCollection.contains("four"));
- }
-
- /**
- * @tests java.util.jar.Attributes#clone()
- */
- public void test_clone() {
- Attributes a2 = (Attributes) a.clone();
- assertTrue("not equal", a.equals(a2));
- a.putValue("1", "one(1)");
- assertTrue("equal", !a.equals(a2));
- }
-
- /**
- * @tests java.util.jar.Attributes#equals(java.lang.Object)
- */
- public void test_equalsLjava_lang_Object() {
- Attributes.Name n1 = new Attributes.Name("name"), n2 = new Attributes.Name(
- "Name");
- assertTrue("Names not equal", n1.equals(n2));
-
- Attributes a1 = new Attributes();
- a1.putValue("one", "1");
- a1.putValue("two", "2");
- Attributes a2 = new Attributes();
- a2.putValue("One", "1");
- a2.putValue("TWO", "2");
- assertTrue("not equal", a1.equals(a2));
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- @Override
- protected void setUp() {
- a = new Attributes();
- a.putValue("1", "one");
- a.putValue("2", "two");
- a.putValue("3", "three");
- a.putValue("4", "four");
- }
-
- /*
+ /**
+ * @tests java.util.jar.Attributes#remove(java.lang.Object)
+ */
+ public void test_removeLjava_lang_Object() {
+ a.remove(new Attributes.Name("1"));
+ a.remove(new Attributes.Name("3"));
+ assertNull("Should have been removed", a.getValue("1"));
+ assertEquals("Should not have been removed", "four", a.getValue("4"));
+ }
+
+ /**
+ * @tests java.util.jar.Attributes#size()
+ */
+ public void test_size() {
+ assertEquals("Incorrect size returned", 4, a.size());
+ a.clear();
+ assertEquals(0, a.size());
+ }
+
+ /**
+ * @tests java.util.jar.Attributes#values()
+ */
+ public void test_values() {
+ Collection<?> valueCollection = a.values();
+ assertTrue("a) Should contain entry", valueCollection.contains("one"));
+ assertTrue("b) Should contain entry", valueCollection.contains("two"));
+ assertTrue("c) Should contain entry", valueCollection.contains("three"));
+ assertTrue("d) Should contain entry", valueCollection.contains("four"));
+ }
+
+ /**
+ * @tests java.util.jar.Attributes#clone()
+ */
+ public void test_clone() {
+ Attributes a2 = (Attributes) a.clone();
+ assertEquals(a, a2);
+ a.putValue("1", "one(1)");
+ assertTrue("equal", !a.equals(a2));
+ }
+
+ /**
+ * @tests java.util.jar.Attributes#equals(java.lang.Object)
+ */
+ public void test_equalsLjava_lang_Object() {
+ Attributes.Name n1 = new Attributes.Name("name"), n2 = new Attributes.Name("Name");
+ assertEquals(n1, n2);
+ Attributes a1 = new Attributes();
+ a1.putValue("one", "1");
+ a1.putValue("two", "2");
+ Attributes a2 = new Attributes();
+ a2.putValue("One", "1");
+ a2.putValue("TWO", "2");
+ assertEquals(a1, a2);
+ }
+
+ /**
* @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));
-
+ 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");
@@ -316,7 +255,6 @@
} catch (ClassCastException e) {
// Expected
}
-
try {
atts.put(Attributes.Name.CLASS_PATH, Boolean.TRUE);
fail("Assert 3: no class cast from value parameter");
Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarEntryTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarEntryTest.java?view=diff&rev=467851&r1=467850&r2=467851
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarEntryTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarEntryTest.java Wed Oct 25 20:29:06 2006
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.harmony.archive.tests.java.util.jar;
import java.io.File;
@@ -23,158 +24,122 @@
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
-
+import java.util.zip.ZipEntry;
+import junit.framework.TestCase;
import tests.support.resource.Support_Resources;
-public class JarEntryTest extends junit.framework.TestCase {
-
- java.util.zip.ZipEntry zipEntry;
+public class JarEntryTest extends TestCase {
+ private ZipEntry zipEntry;
- java.util.jar.JarEntry jarEntry;
+ private JarEntry jarEntry;
- java.util.jar.JarFile jarFile;
+ private JarFile jarFile;
- final String jarName = "hyts_patch.jar";
-
- final String entryName = "foo/bar/A.class";
-
- final String entryName2 = "Blah.txt";
-
- final String attJarName = "hyts_att.jar";
-
- final String attEntryName = "HasAttributes.txt";
-
- final String attEntryName2 = "NoAttributes.txt";
-
- File resources;
-
- /**
- * @tests java.util.jar.JarEntry#JarEntry(java.util.zip.ZipEntry)
- */
- public void test_ConstructorLjava_util_zip_ZipEntry() {
- // Test for method java.util.jar.JarEntry(java.util.zip.ZipEntry)
- assertNotNull("Jar file is null", jarFile);
- zipEntry = jarFile.getEntry(entryName);
- assertNotNull("Zip entry is null", zipEntry);
- jarEntry = new JarEntry(zipEntry);
- assertNotNull("Jar entry is null", jarEntry);
- assertTrue("Wrong entry constucted--wrong name", jarEntry.getName()
- .equals(entryName));
- assertEquals("Wrong entry constucted--wrong size",
- 311, jarEntry.getSize());
- }
-
- /**
- * @tests java.util.jar.JarEntry#getAttributes()
- */
- public void test_getAttributes() {
- // Test for method java.util.jar.Attributes
- // java.util.jar.JarEntry.getAttributes()
- JarFile attrJar = null;
- File file = null;
- try {
- Support_Resources.copyFile(resources, null, attJarName);
- file = new File(resources, attJarName);
- attrJar = new JarFile(file);
- } catch (Exception e) {
- assertTrue(file + " does not exist", file.exists());
- fail("Exception opening file: " + e.toString());
- }
-
- try {
- jarEntry = attrJar.getJarEntry(attEntryName);
- assertNotNull("Should have Manifest attributes", jarEntry
- .getAttributes());
- } catch (Exception e) {
- fail("Exception during 2nd test: " + e.toString());
- }
-
- try {
- jarEntry = attrJar.getJarEntry(attEntryName2);
- assertNull("Shouldn't have any Manifest attributes", jarEntry
- .getAttributes());
- attrJar.close();
- } catch (Exception e) {
- fail("Exception during 1st test: " + e.toString());
- }
- }
-
- /**
- * @tests java.util.jar.JarEntry#getCertificates()
- */
- public void test_getCertificates() {
- // Test for method java.security.cert.Certificate []
- // java.util.jar.JarEntry.getCertificates()
- zipEntry = jarFile.getEntry(entryName2);
- jarEntry = new JarEntry(zipEntry);
- assertNull("Shouldn't have any Certificates", jarEntry
- .getCertificates());
- }
-
-
- /**
- * @tests java.util.jar.JarEntry#getCodeSigners()
- */
- public void test_getCodeSigners() throws IOException {
- String jarFileName = "TestCodeSigners.jar";
- Support_Resources.copyFile(resources, null, jarFileName);
- File file = new File(resources, jarFileName);
- JarFile jarFile = new JarFile(file);
- JarEntry jarEntry = jarFile.getJarEntry("Test.class");
- InputStream in = jarFile.getInputStream(jarEntry);
- byte[] buffer = new byte[1024];
- while(in.available()>0)
- {
- in.read(buffer);
- }
- CodeSigner[] codeSigners = jarEntry.getCodeSigners();
- assertEquals(2, codeSigners.length);
- List<?> certs_bob = codeSigners[0].getSignerCertPath().getCertificates();
- List<?> certs_alice = codeSigners[1].getSignerCertPath().getCertificates();
- if(1 == certs_bob.size())
- {
- List<?> temp = certs_bob;
- certs_bob = certs_alice;
- certs_alice = temp;
- }
- assertEquals(2,certs_bob.size());
- assertEquals(1,certs_alice.size());
-
- assertNull("getCodeSigners() of a primitive JarEntry should return null",
- new JarEntry("aaa").getCodeSigners());
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
-
- @Override
- protected void setUp() {
- try {
- resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, jarName);
- jarFile = new JarFile(new File(resources, jarName));
- } catch (Exception e) {
- e.printStackTrace();
- fail("Exception during setup: " + e.toString());
- }
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
-
- @Override
- protected void tearDown() {
- try {
- if (jarFile != null) {
- jarFile.close();
- }
- } catch (java.io.IOException e) {
- System.out.println("Exception during tearDown");
- }
- }
+ private final String jarName = "hyts_patch.jar";
+ private final String entryName = "foo/bar/A.class";
+
+ private final String entryName2 = "Blah.txt";
+
+ private final String attJarName = "hyts_att.jar";
+
+ private final String attEntryName = "HasAttributes.txt";
+
+ private final String attEntryName2 = "NoAttributes.txt";
+
+ private File resources;
+
+ @Override
+ protected void setUp() throws Exception {
+ resources = Support_Resources.createTempFolder();
+ Support_Resources.copyFile(resources, null, jarName);
+ jarFile = new JarFile(new File(resources, jarName));
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ if (jarFile != null) {
+ jarFile.close();
+ }
+ }
+
+ /**
+ * @tests java.util.jar.JarEntry#JarEntry(java.util.zip.ZipEntry)
+ */
+ public void test_ConstructorLjava_util_zip_ZipEntry() {
+ assertNotNull("Jar file is null", jarFile);
+ zipEntry = jarFile.getEntry(entryName);
+ assertNotNull("Zip entry is null", zipEntry);
+ jarEntry = new JarEntry(zipEntry);
+ assertNotNull("Jar entry is null", jarEntry);
+ assertEquals("Wrong entry constructed--wrong name", entryName, jarEntry.getName());
+ assertEquals("Wrong entry constructed--wrong size", 311, jarEntry.getSize());
+ }
+
+ /**
+ * @tests java.util.jar.JarEntry#getAttributes()
+ */
+ public void test_getAttributes() {
+ JarFile attrJar = null;
+ File file = null;
+ try {
+ Support_Resources.copyFile(resources, null, attJarName);
+ file = new File(resources, attJarName);
+ attrJar = new JarFile(file);
+ } catch (Exception e) {
+ assertTrue(file + " does not exist", file.exists());
+ fail("Exception opening file: " + e.toString());
+ }
+ try {
+ jarEntry = attrJar.getJarEntry(attEntryName);
+ assertNotNull("Should have Manifest attributes", jarEntry.getAttributes());
+ } catch (Exception e) {
+ fail("Exception during 2nd test: " + e.toString());
+ }
+ try {
+ jarEntry = attrJar.getJarEntry(attEntryName2);
+ assertNull("Shouldn't have any Manifest attributes", jarEntry.getAttributes());
+ attrJar.close();
+ } catch (Exception e) {
+ fail("Exception during 1st test: " + e.toString());
+ }
+ }
+
+ /**
+ * @tests java.util.jar.JarEntry#getCertificates()
+ */
+ public void test_getCertificates() {
+ zipEntry = jarFile.getEntry(entryName2);
+ jarEntry = new JarEntry(zipEntry);
+ assertNull("Shouldn't have any Certificates", jarEntry.getCertificates());
+ }
+
+ /**
+ * @tests java.util.jar.JarEntry#getCodeSigners()
+ */
+ public void test_getCodeSigners() throws IOException {
+ String jarFileName = "TestCodeSigners.jar";
+ Support_Resources.copyFile(resources, null, jarFileName);
+ File file = new File(resources, jarFileName);
+ JarFile jarFile = new JarFile(file);
+ JarEntry jarEntry = jarFile.getJarEntry("Test.class");
+ InputStream in = jarFile.getInputStream(jarEntry);
+ byte[] buffer = new byte[1024];
+ while (in.available() > 0) {
+ in.read(buffer);
+ }
+ CodeSigner[] codeSigners = jarEntry.getCodeSigners();
+ assertEquals(2, codeSigners.length);
+ List<?> certs_bob = codeSigners[0].getSignerCertPath().getCertificates();
+ List<?> certs_alice = codeSigners[1].getSignerCertPath().getCertificates();
+ if (1 == certs_bob.size()) {
+ List<?> temp = certs_bob;
+ certs_bob = certs_alice;
+ certs_alice = temp;
+ }
+ assertEquals(2, certs_bob.size());
+ assertEquals(1, certs_alice.size());
+ assertNull("getCodeSigners() of a primitive JarEntry should return null", new JarEntry(
+ "aaa").getCodeSigners());
+ }
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarExceptionTest.java?view=diff&rev=467851&r1=467850&r2=467851
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarExceptionTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarExceptionTest.java Wed Oct 25 20:29:06 2006
@@ -14,44 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.harmony.archive.tests.java.util.jar;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.jar.Manifest;
+import junit.framework.TestCase;
-public class JarExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.util.jar.JarException#JarException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.util.jar.JarException(java.lang.String)
- try {
- new Manifest(new java.io.ByteArrayInputStream(
- "jlkasj dl: dsklf jlks dslka : fdsfsd\n\n\n\ndsfas"
- .getBytes()));
- fail("Should have thrown exception");
- } catch (IOException e) {
- // correct
- } catch (Exception e) {
- fail("Threw the wrong exception: " + e.toString());
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- @Override
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- @Override
- protected void tearDown() {
- }
-
+public class JarExceptionTest extends TestCase {
+ /**
+ * @tests java.util.jar.JarException#JarException(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() throws Exception {
+ try {
+ new Manifest(new ByteArrayInputStream(
+ "jlkasj dl: dsklf jlks dslka : fdsfsd\n\n\n\ndsfas".getBytes()));
+ fail("Should have thrown exception");
+ } catch (IOException e) {
+ // correct
+ }
+ }
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java?view=diff&rev=467851&r1=467850&r2=467851
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java Wed Oct 25 20:29:06 2006
@@ -86,63 +86,52 @@
/**
* @tests java.util.jar.JarFile#entries()
*/
- public void test_entries() {
- // Test for method java.util.Enumeration java.util.jar.JarFile.entries()
-
- /*
- * Note only (and all of) the following should be contained in the file
- * META-INF/ META-INF/MANIFEST.MF foo/ foo/bar/ foo/bar/A.class Blah.txt
- */
-
- try {
- Support_Resources.copyFile(resources, null, jarName);
- JarFile jarFile = new JarFile(new File(resources, jarName));
- Enumeration<JarEntry> e = jarFile.entries();
- int i = 0;
- while (e.hasMoreElements()) {
- i++;
- e.nextElement();
- }
- jarFile.close();
- assertTrue("Wrong number of elements--wanted 6, got: " + i, i == 6);
- } catch (Exception e) {
- fail("Exception during test: " + e.toString());
- }
-
- try {
- Support_Resources.copyFile(resources, null, jarName);
- JarFile jarFile = new JarFile(new File(resources, jarName));
- Enumeration<JarEntry> enumeration = jarFile.entries();
- jarFile.close();
- boolean pass = false;
- try {
- enumeration.hasMoreElements();
- } catch (IllegalStateException e) {
- pass = true;
- }
- assertTrue("hasMoreElements did not detect closed jar file", pass);
- Support_Resources.copyFile(resources, null, jarName);
- jarFile = new JarFile(new File(resources, jarName));
- enumeration = jarFile.entries();
- jarFile.close();
- pass = false;
- try {
- enumeration.nextElement();
- } catch (IllegalStateException e) {
- pass = true;
- }
- assertTrue("nextElement did not detect closed jar file", pass);
- } catch (Exception e) {
- fail("Exception during entries test: " + e.toString());
- }
- }
+ public void test_entries() throws Exception {
+ /*
+ * Note only (and all of) the following should be contained in the file
+ * META-INF/ META-INF/MANIFEST.MF foo/ foo/bar/ foo/bar/A.class Blah.txt
+ */
+ Support_Resources.copyFile(resources, null, jarName);
+ JarFile jarFile = new JarFile(new File(resources, jarName));
+ Enumeration<JarEntry> e = jarFile.entries();
+ int i = 0;
+ while (e.hasMoreElements()) {
+ i++;
+ e.nextElement();
+ }
+ jarFile.close();
+ assertEquals(6, i);
+ }
+
+ public void test_entries2() throws Exception {
+ Support_Resources.copyFile(resources, null, jarName);
+ JarFile jarFile = new JarFile(new File(resources, jarName));
+ Enumeration<JarEntry> enumeration = jarFile.entries();
+ jarFile.close();
+ boolean pass = false;
+ try {
+ enumeration.hasMoreElements();
+ } catch (IllegalStateException e) {
+ pass = true;
+ }
+ assertTrue("hasMoreElements did not detect closed jar file", pass);
+ Support_Resources.copyFile(resources, null, jarName);
+ jarFile = new JarFile(new File(resources, jarName));
+ enumeration = jarFile.entries();
+ jarFile.close();
+ pass = false;
+ try {
+ enumeration.nextElement();
+ } catch (IllegalStateException e) {
+ pass = true;
+ }
+ assertTrue("nextElement did not detect closed jar file", pass);
+ }
/**
* @tests java.util.jar.JarFile#getJarEntry(java.lang.String)
*/
public void test_getJarEntryLjava_lang_String() {
- // Test for method java.util.jar.JarEntry
- // java.util.jar.JarFile.getJarEntry(java.lang.String)
try {
Support_Resources.copyFile(resources, null, jarName);
JarFile jarFile = new JarFile(new File(resources, jarName));
Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarInputStreamTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarInputStreamTest.java?view=diff&rev=467851&r1=467850&r2=467851
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarInputStreamTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarInputStreamTest.java Wed Oct 25 20:29:06 2006
@@ -107,26 +107,19 @@
/**
* @tests java.util.jar.JarInputStream#getNextJarEntry()
*/
- public void test_getNextJarEntry() {
- // Test for method java.util.jar.JarEntry
- // java.util.jar.JarInputStream.getNextJarEntry()
- final Set<String> desired = new HashSet<String>(Arrays.asList(new String[] { "foo/",
- "foo/bar/", "foo/bar/A.class", "Blah.txt" }));
- Set<String> actual = new HashSet<String>();
- try {
- InputStream is = new URL(jarName).openConnection()
- .getInputStream();
- JarInputStream jis = new JarInputStream(is);
- JarEntry je = jis.getNextJarEntry();
- while (je != null) {
- actual.add(je.toString());
- je = jis.getNextJarEntry();
- }
- } catch (Exception e) {
- fail("Exception during test: " + e.toString());
- }
- assertTrue("Set of entries is not correct", actual.equals(desired));
- }
+ public void test_getNextJarEntry() throws Exception {
+ final Set<String> desired = new HashSet<String>(Arrays.asList(new String[] { "foo/",
+ "foo/bar/", "foo/bar/A.class", "Blah.txt" }));
+ Set<String> actual = new HashSet<String>();
+ InputStream is = new URL(jarName).openConnection().getInputStream();
+ JarInputStream jis = new JarInputStream(is);
+ JarEntry je = jis.getNextJarEntry();
+ while (je != null) {
+ actual.add(je.toString());
+ je = jis.getNextJarEntry();
+ }
+ assertEquals(actual, desired);
+ }
public void test_JarInputStream_Integrate_Jar_getNextEntry()
throws IOException {