harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r485491 - /harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java
Date Mon, 11 Dec 2006 04:22:54 GMT
Author: ndbeyer
Date: Sun Dec 10 20:22:53 2006
New Revision: 485491

URL: http://svn.apache.org/viewvc?view=rev&rev=485491
Log:
Cleanup source and correct assert method usage

Modified:
    harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java?view=diff&rev=485491&r1=485490&r2=485491
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java
Sun Dec 10 20:22:53 2006
@@ -18,135 +18,132 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 import java.util.zip.ZipOutputStream;
 
+import junit.framework.TestCase;
 import tests.support.resource.Support_Resources;
 
-public class ZipInputStreamTest extends junit.framework.TestCase {
+public class ZipInputStreamTest extends TestCase {
 	// the file hyts_zipFile.zip used in setup needs to included as a resource
-	java.util.zip.ZipFile zfile;
+	private ZipEntry zentry;
 
-	java.util.zip.ZipEntry zentry;
-
-	java.util.zip.ZipInputStream zis;
+	private ZipInputStream zis;
     
-    byte[] zipBytes;
+    private byte[] zipBytes;
 
-    byte[] dataBytes = "Some data in my file".getBytes();
+    private byte[] dataBytes = "Some data in my file".getBytes();
 
+    @Override
+    protected void setUp() {
+        try {
+            InputStream is = Support_Resources.getStream("hyts_ZipFile.zip");
+            if (is == null) {
+                System.out.println("file hyts_ZipFile.zip can not be found");
+            }
+            zis = new ZipInputStream(is);
+
+            ByteArrayOutputStream bos = new ByteArrayOutputStream();
+            ZipOutputStream zos = new ZipOutputStream(bos);
+            ZipEntry entry = new ZipEntry("myFile");
+            zos.putNextEntry(entry);
+            zos.write(dataBytes);
+            zos.closeEntry();
+            zos.close();
+            zipBytes = bos.toByteArray();
+        } catch (Exception e) {
+            System.out.println("Exception during ZipFile setup:");
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    protected void tearDown() {
+        if (zis != null) {
+            try {
+                zis.close();
+            } catch (Exception e) {
+            }
+        }
+    }
 
 	/**
-	 * @tests java.util.zip.ZipInputStream#ZipInputStream(java.io.InputStream)
-	 */
-	public void test_ConstructorLjava_io_InputStream() {
-		// Test for method java.util.zip.ZipInputStream(java.io.InputStream)
-		try {
-			zentry = zis.getNextEntry();
-			zis.closeEntry();
-		} catch (java.io.IOException e) {
-			fail("Failed to create ZipInputStream");
-		}
+     * @tests java.util.zip.ZipInputStream#ZipInputStream(java.io.InputStream)
+     */
+	public void test_ConstructorLjava_io_InputStream() throws Exception {
+	    zentry = zis.getNextEntry();
+	    zis.closeEntry();
 	}
 
 	/**
 	 * @tests java.util.zip.ZipInputStream#close()
 	 */
 	public void test_close() {
-		// Test for method void java.util.zip.ZipInputStream.close()
 		try {
 			zis.close();
 			byte[] rbuf = new byte[10];
 			zis.read(rbuf, 0, 1);
-		} catch (java.io.IOException e) {
+		} catch (IOException e) {
 			return;
 		}
-		fail("Read data after stream was closed--is this an error?");
+		fail("Read data after stream was closed");
 	}
 
 	/**
      * @tests java.util.zip.ZipInputStream#close()
      */
-    public void test_close2() {
+    public void test_close2() throws Exception {
         // Regression for HARMONY-1101
-        try {
-            zis.close();
-            zis.close();
-        } catch (java.io.IOException e) {
-            fail("No exception expected: " + e);
-        }
+        zis.close();
+        // another call to close should NOT cause an exception
+        zis.close();
     }
 
 	/**
 	 * @tests java.util.zip.ZipInputStream#closeEntry()
 	 */
-	public void test_closeEntry() {
-		// Test for method void java.util.zip.ZipInputStream.closeEntry()
-		try {
-			zentry = zis.getNextEntry();
-			zis.closeEntry();
-		} catch (java.io.IOException e) {
-			fail("Exception during closeEntry test");
-		}
+	public void test_closeEntry() throws Exception {
+	    zentry = zis.getNextEntry();
+	    zis.closeEntry();
 	}
 
 	/**
 	 * @tests java.util.zip.ZipInputStream#getNextEntry()
 	 */
-	public void test_getNextEntry() {
-		// Test for method java.util.zip.ZipEntry
-		// java.util.zip.ZipInputStream.getNextEntry()
-		try {
-			assertNotNull("getNextEntry failed", zis.getNextEntry());
-		} catch (java.io.IOException e) {
-			fail("Exception during getNextEntry test");
-		}
+	public void test_getNextEntry() throws Exception {
+	    assertNotNull("getNextEntry failed", zis.getNextEntry());
 	}
 
 	/**
 	 * @tests java.util.zip.ZipInputStream#read(byte[], int, int)
 	 */
-	public void test_read$BII() {
-		// Test for method int java.util.zip.ZipInputStream.read(byte [], int,
-		// int)
-		try {
-			zentry = zis.getNextEntry();
-			byte[] rbuf = new byte[(int) zentry.getSize()];
-			int r = zis.read(rbuf, 0, rbuf.length);
-			new String(rbuf, 0, r);
-			assertEquals("Failed to read entry", 12, r);
-		} catch (java.io.IOException e) {
-			fail("Exception during read test");
-		}
+	public void test_read$BII() throws Exception {
+	    zentry = zis.getNextEntry();
+	    byte[] rbuf = new byte[(int) zentry.getSize()];
+	    int r = zis.read(rbuf, 0, rbuf.length);
+	    new String(rbuf, 0, r);
+	    assertEquals("Failed to read entry", 12, r);
 	}
 
 	/**
 	 * @tests java.util.zip.ZipInputStream#skip(long)
 	 */
 	public void test_skipJ() throws Exception {
-		// Test for method long java.util.zip.ZipInputStream.skip(long)
-		try {
-			zentry = zis.getNextEntry();
-			byte[] rbuf = new byte[(int) zentry.getSize()];
-			zis.skip(2);
-			int r = zis.read(rbuf, 0, rbuf.length);
-			assertEquals("Failed to skip data", 10, r);
-		} catch (java.io.IOException e) {
-			fail("Unexpected1: " + e);
-		}
+        zentry = zis.getNextEntry();
+        byte[] rbuf = new byte[(int) zentry.getSize()];
+        zis.skip(2);
+        int r = zis.read(rbuf, 0, rbuf.length);
+        assertEquals("Failed to skip data", 10, r);
+
+        zentry = zis.getNextEntry();
+        zentry = zis.getNextEntry();
+        long s = zis.skip(1025);
+        assertTrue("invalid skip: " + s, s == 1025);
 
-		try {
-			zentry = zis.getNextEntry();
-			zentry = zis.getNextEntry();
-			long s = zis.skip(1025);
-			assertTrue("invalid skip: " + s, s == 1025);
-		} catch (java.io.IOException e) {
-			fail("Unexpected2: " + e);
-		}
-        
-        ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(
-                zipBytes));
+        ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(zipBytes));
         zis.getNextEntry();
         long skipLen = dataBytes.length / 2;
         assertEquals("Assert 0: failed valid skip", skipLen, zis.skip(skipLen));
@@ -159,48 +156,5 @@
         } catch (IllegalArgumentException e) {
             // Expected
         }
-	}
-
-	/**
-	 * Sets up the fixture, for example, open a network connection. This method
-	 * is called before a test is executed.
-	 */
-	@Override
-    protected void setUp() {
-		try {
-			java.io.InputStream is = Support_Resources
-					.getStream("hyts_ZipFile.zip");
-			if (is == null) {
-                System.out.println("file hyts_ZipFile.zip can not be found");
-            }
-			zis = new ZipInputStream(is);
-            
-            ByteArrayOutputStream bos = new ByteArrayOutputStream();
-            ZipOutputStream zos = new ZipOutputStream(bos);
-            ZipEntry entry = new ZipEntry("myFile");
-            zos.putNextEntry(entry);
-            zos.write(dataBytes);
-            zos.closeEntry();
-            zos.close();
-            zipBytes = bos.toByteArray();
-		} catch (Exception e) {
-			System.out.println("Exception during ZipFile setup:");
-			e.printStackTrace();
-		}
-	}
-
-	/**
-	 * Tears down the fixture, for example, close a network connection. This
-	 * method is called after a test is executed.
-	 */
-	@Override
-    protected void tearDown() {
-
-		if (zis != null) {
-            try {
-				zis.close();
-			} catch (Exception e) {
-			}
-        }
-	}
+    }
 }



Mime
View raw message