harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r485488 - in /harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util: jar/AttributesTest.java zip/CheckedInputStreamTest.java zip/DeflaterOutputStreamTest.java zip/DeflaterTest.java
Date Mon, 11 Dec 2006 04:12:44 GMT
Author: ndbeyer
Date: Sun Dec 10 20:12:41 2006
New Revision: 485488

URL: http://svn.apache.org/viewvc?view=rev&rev=485488
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/jar/AttributesTest.java
    harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java
    harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java
    harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java

Modified: 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/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesTest.java?view=diff&rev=485488&r1=485487&r2=485488
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesTest.java Sun Dec 10 20:12:41 2006
@@ -287,7 +287,7 @@
         Attributes.Name name = new Attributes.Name("null");
         attribute.put(name, null);
         assertEquals(2, attribute.size());
-        assertEquals(null, attribute.get(name));
+        assertNull(attribute.get(name));
     }
 
 }

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java?view=diff&rev=485488&r1=485487&r2=485488
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java Sun Dec 10 20:12:41 2006
@@ -18,126 +18,91 @@
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
-import java.io.IOException;
 import java.io.InputStream;
 import java.util.zip.CRC32;
 import java.util.zip.CheckedInputStream;
 
+import junit.framework.TestCase;
 import tests.support.resource.Support_Resources;
 
-public class CheckedInputStreamTest extends junit.framework.TestCase {
-	InputStream checkInput;
+public class CheckedInputStreamTest extends TestCase {
+    
+    @Override
+    protected void tearDown() {
+        try {
+            File deletedFile = new File("empty.txt");
+            deletedFile.delete();
+        } catch (SecurityException e) {
+            fail("Cannot delete file for security reasons");
+        }
+
+    }
 
 	/**
 	 * @tests java.util.zip.CheckedInputStream#CheckedInputStream(java.io.InputStream,
 	 *        java.util.zip.Checksum)
 	 */
-	public void test_ConstructorLjava_io_InputStreamLjava_util_zip_Checksum() {
-		// test method java.util.zip.checkedInputStream.constructor()
-		try {
-			checkInput = Support_Resources.getStream("hyts_checkInput.txt");
-			CheckedInputStream checkIn = new CheckedInputStream(checkInput,
-					new CRC32());
-			assertEquals("constructor of checkedInputStream has failed", 0, checkIn
-					.getChecksum().getValue());
-			checkInput.close();
-		} catch (FileNotFoundException e) {
-			fail("File for checkInputStream is not found");
-		} catch (IOException e) {
-			fail("error occured while trying to open input file");
-		}
-	}
+	public void test_ConstructorLjava_io_InputStreamLjava_util_zip_Checksum() throws Exception {
+        InputStream checkInput = Support_Resources.getStream("hyts_checkInput.txt");
+        CheckedInputStream checkIn = new CheckedInputStream(checkInput, new CRC32());
+        assertEquals("constructor of checkedInputStream has failed", 0, checkIn.getChecksum()
+                .getValue());
+        checkInput.close();
+    }
 
 	/**
 	 * @tests java.util.zip.CheckedInputStream#getChecksum()
 	 */
-	public void test_getChecksum() {
-		// test method java.util.zip.checkInputStream.getChecksum()
-		byte outBuf[] = new byte[100];
-		try {
-			// testing getChecksum for an empty file
-			FileOutputStream outEmp = new FileOutputStream("empty.txt");
-			outEmp.close();
-			InputStream inEmp = new FileInputStream("empty.txt");
-			CheckedInputStream checkEmpty = new CheckedInputStream(inEmp,
-					new CRC32());
-			while (checkEmpty.read() >= 0) {
-			}
-			assertEquals("the checkSum value of an empty file is not zero",
-					0, checkEmpty.getChecksum().getValue());
-			inEmp.close();
-
-			// testing getChecksum for the file checkInput
-			checkInput = Support_Resources.getStream("hyts_checkInput.txt");
-			CheckedInputStream checkIn = new CheckedInputStream(checkInput,
-					new CRC32());
-			while (checkIn.read() >= 0) {
-			}
-			// ran JDK and found that the checkSum value of this is 2036203193
-			// System.out.print(" " + checkIn.getChecksum().getValue());
-			assertEquals("the checksum value is incorrect", 2036203193, checkIn.getChecksum()
-					.getValue());
-			checkInput.close();
-			// testing getChecksum for file checkInput
-			checkInput = Support_Resources.getStream("hyts_checkInput.txt");
-			CheckedInputStream checkIn2 = new CheckedInputStream(checkInput,
-					new CRC32());
-			checkIn2.read(outBuf, 0, 10);
-			// ran JDK and found that the checkSum value of this is 2235765342
-			// System.out.print(" " + checkIn2.getChecksum().getValue());
-			assertEquals("the checksum value is incorrect", 2235765342L, checkIn2
-					.getChecksum().getValue());
-			checkInput.close();
-		} catch (FileNotFoundException e) {
-			fail("File for checkInputStream is not found");
-		} catch (IOException e) {
-			fail("error occured while trying to open input file");
-		}
-	}
+	public void test_getChecksum() throws Exception {
+        byte outBuf[] = new byte[100];
+        // testing getChecksum for an empty file
+        FileOutputStream outEmp = new FileOutputStream("empty.txt");
+        outEmp.close();
+        InputStream inEmp = new FileInputStream("empty.txt");
+        CheckedInputStream checkEmpty = new CheckedInputStream(inEmp, new CRC32());
+        while (checkEmpty.read() >= 0) {
+        }
+        assertEquals("the checkSum value of an empty file is not zero", 0, checkEmpty
+                .getChecksum().getValue());
+        inEmp.close();
+
+        // testing getChecksum for the file checkInput
+        InputStream checkInput = Support_Resources.getStream("hyts_checkInput.txt");
+        CheckedInputStream checkIn = new CheckedInputStream(checkInput, new CRC32());
+        while (checkIn.read() >= 0) {
+        }
+        // ran JDK and found that the checkSum value of this is 2036203193
+        // System.out.print(" " + checkIn.getChecksum().getValue());
+        assertEquals("the checksum value is incorrect", 2036203193, checkIn.getChecksum()
+                .getValue());
+        checkInput.close();
+        // testing getChecksum for file checkInput
+        checkInput = Support_Resources.getStream("hyts_checkInput.txt");
+        CheckedInputStream checkIn2 = new CheckedInputStream(checkInput, new CRC32());
+        checkIn2.read(outBuf, 0, 10);
+        // ran JDK and found that the checkSum value of this is 2235765342
+        // System.out.print(" " + checkIn2.getChecksum().getValue());
+        assertEquals("the checksum value is incorrect", 2235765342L, checkIn2.getChecksum()
+                .getValue());
+        checkInput.close();
+    }
 
 	/**
 	 * @tests java.util.zip.CheckedInputStream#skip(long)
 	 */
-	public void test_skipJ() {
-		// test method java.util.zip.skip
-		try {
-			// testing that the return by skip is valid
-			checkInput = Support_Resources.getStream("hyts_checkInput.txt");
-			CheckedInputStream checkIn = new CheckedInputStream(checkInput,
-					new CRC32());
-			long skipValue = 5;
-			assertTrue(
-					"the value returned by skip(n) is not the same as its parameter",
-					checkIn.skip(skipValue) == skipValue);
-			checkIn.skip(skipValue);
-			// ran JDK and found the checkSum value is 2235765342
-			// System.out.print(checkIn.getChecksum().getValue());
-			assertEquals("checkSum value is not correct", 2235765342L, checkIn.getChecksum()
-					.getValue());
-			checkInput.close();
-		} catch (FileNotFoundException e) {
-			fail("File for checkInputStream is not found");
-		} catch (IOException e) {
-			fail("error occured while trying to open input file");
-		}
-	}
-
-	@Override
-    protected void setUp() {
-
-	}
-
-	@Override
-    protected void tearDown() {
-		try {
-			File deletedFile = new File("empty.txt");
-			deletedFile.delete();
-		} catch (SecurityException e) {
-			fail("Cannot delete file for security reasons");
-		}
-
-	}
-
+	public void test_skipJ() throws Exception {
+        // testing that the return by skip is valid
+        InputStream checkInput = Support_Resources.getStream("hyts_checkInput.txt");
+        CheckedInputStream checkIn = new CheckedInputStream(checkInput, new CRC32());
+        long skipValue = 5;
+        assertEquals("the value returned by skip(n) is not the same as its parameter",
+                skipValue, checkIn.skip(skipValue));
+        checkIn.skip(skipValue);
+        // ran JDK and found the checkSum value is 2235765342
+        // System.out.print(checkIn.getChecksum().getValue());
+        assertEquals("checkSum value is not correct", 2235765342L, checkIn.getChecksum()
+                .getValue());
+        checkInput.close();
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java?view=diff&rev=485488&r1=485487&r2=485488
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java Sun Dec 10 20:12:41 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.zip;
 
 import java.io.EOFException;
@@ -26,436 +27,356 @@
 import java.util.zip.DeflaterOutputStream;
 import java.util.zip.InflaterInputStream;
 
-public class DeflaterOutputStreamTest extends junit.framework.TestCase {
-	byte outPutBuf[] = new byte[500];
+import junit.framework.TestCase;
 
-	class MyDeflaterOutputStream extends java.util.zip.DeflaterOutputStream {
-		MyDeflaterOutputStream(OutputStream out) {
-			super(out);
-		}
-
-		MyDeflaterOutputStream(OutputStream out, Deflater defl) {
-			super(out, defl);
-		}
-
-		MyDeflaterOutputStream(OutputStream out, Deflater defl, int size) {
-			super(out, defl, size);
-		}
-
-		byte[] getProtectedBuf() {
-			return buf;
-		}
-
-		void myDeflate() throws IOException {
-			deflate();
-		}
-	}
-
-	/**
-	 * @tests java.util.zip.DeflaterOutputStream#DeflaterOutputStream(java.io.OutputStream,
-	 *        java.util.zip.Deflater)
-	 */
-	public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_Deflater() {
-		// Test for method
-		// java.util.zip.deflaterOutputStream.DeflaterOutPutStream(OutputStream,Deflater)
-
-		try {
-			byte byteArray[] = { 1, 3, 4, 7, 8 };
-			File f1 = new File("hyts_Constru(OD).tst");
-			FileOutputStream fos = new FileOutputStream(f1);
-			Deflater defl = null;
-			MyDeflaterOutputStream dos;
-			// Test for a null Deflater.
-			try {
-				dos = new MyDeflaterOutputStream(fos, defl);
-				fail("NullPointerException Not Thrown");
-			} catch (NullPointerException e) {
-			}
-			defl = new Deflater();
-			dos = new MyDeflaterOutputStream(fos, defl);
-
-			// Test to see if DflaterOutputStream was created with the correct
-			// buffer.
-			assertEquals("Incorrect Buffer Size",
-					512, dos.getProtectedBuf().length);
-
-			dos.write(byteArray);
-			dos.close();
-			f1.delete();
-		} catch (SecurityException e) {
-			fail("SecurityException During Test");
-		} catch (IOException e) {
-			fail("IOException During Test");
-		}
-	}
-
-	/**
-	 * @tests java.util.zip.DeflaterOutputStream#DeflaterOutputStream(java.io.OutputStream)
-	 */
-	public void test_ConstructorLjava_io_OutputStream() {
-		// Test for method
-		// java.util.zip.deflaterOutputStream.DeflaterOutPutStream(OutputStream)
-
-		try {
-			File f1 = new File("hyts_Constru(O).tst");
-			FileOutputStream fos = new FileOutputStream(f1);
-			MyDeflaterOutputStream dos = new MyDeflaterOutputStream(fos);
-
-			// Test to see if DflaterOutputStream was created with the correct
-			// buffer.
-			assertEquals("Incorrect Buffer Size",
-					512, dos.getProtectedBuf().length);
-
-			dos.write(outPutBuf);
-			dos.close();
-			f1.delete();
-		} catch (SecurityException e) {
-			fail("SecurityException During Test");
-		} catch (IOException e) {
-			fail("IOException During Test");
-		}
-
-	}
-
-	/**
-	 * @tests java.util.zip.DeflaterOutputStream#DeflaterOutputStream(java.io.OutputStream,
-	 *        java.util.zip.Deflater, int)
-	 */
-	public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_DeflaterI() {
-		// Test for method
-		// java.util.zip.deflaterOutputStream.DeflaterOutPutStream(OutputStream,Deflater,int)
-
-		try {
-			int buf = 5;
-			int negBuf = -5;
-			int zeroBuf = 0;
-			byte byteArray[] = { 1, 3, 4, 7, 8, 3, 6 };
-			File f1 = new File("hyts_Constru(ODI).tst");
-			FileOutputStream fos = new FileOutputStream(f1);
-			Deflater defl = null;
-			MyDeflaterOutputStream dos;
-
-			// Test for a null Deflater.
-			try {
-				dos = new MyDeflaterOutputStream(fos, defl, buf);
-				fail("NullPointerException Not Thrown");
-			} catch (NullPointerException e) {
-			}
-			defl = new Deflater();
-
-			// Test for a negative buf.
-			try {
-				dos = new MyDeflaterOutputStream(fos, defl, negBuf);
-				fail("IllegalArgumentException Not Thrown");
-			} catch (IllegalArgumentException e) {
-			}
-
-			// Test for a zero buf.
-			try {
-				dos = new MyDeflaterOutputStream(fos, defl, zeroBuf);
-				fail("IllegalArgumentException Not Thrown");
-			} catch (IllegalArgumentException e) {
-			}
-
-			// Test to see if DflaterOutputStream was created with the correct
-			// buffer.
-			dos = new MyDeflaterOutputStream(fos, defl, buf);
-			assertEquals("Incorrect Buffer Size",
-					5, dos.getProtectedBuf().length);
-
-			dos.write(byteArray);
-			dos.close();
-			f1.delete();
-		} catch (SecurityException e) {
-			fail("SecurityException During Test");
-		} catch (IOException e) {
-			fail("IOException During Test");
-		}
-	}
-
-	/**
-	 * @tests java.util.zip.DeflaterOutputStream#close()
-	 */
-	public void test_close() {
-		// Test for method java.util.zip.DeflaterOutputStream.close()
-		try {
-			File f1 = new File("close.tst");
-			FileOutputStream fos = new FileOutputStream(f1);
-			DeflaterOutputStream dos = new DeflaterOutputStream(fos);
-			byte byteArray[] = { 1, 3, 4, 6 };
-			dos.write(byteArray);
-
-			FileInputStream fis = new FileInputStream(f1);
-			InflaterInputStream iis = new InflaterInputStream(fis);
-			try {
-				iis.read();
-				fail("EOFException Not Thrown");
-			} catch (EOFException e) {
-			}
-
-			dos.close();
-
-			// Test to see if the finish method wrote the bytes to the file.
-			assertEquals("Incorrect Byte Returned.", 1, iis.read());
-			assertEquals("Incorrect Byte Returned.", 3, iis.read());
-			assertEquals("Incorrect Byte Returned.", 4, iis.read());
-			assertEquals("Incorrect Byte Returned.", 6, iis.read());
-			assertEquals("Incorrect Byte Returned.", -1, iis.read());
-			assertEquals("Incorrect Byte Returned.", -1, iis.read());
-			iis.close();
-
-			// Not sure if this test will stay.
-			FileOutputStream fos2 = new FileOutputStream(f1);
-			DeflaterOutputStream dos2 = new DeflaterOutputStream(fos2);
-			fos2.close();
-			try {
-				dos2.close();
-				fail("IOException not thrown");
-			} catch (IOException e) {
-			}
-
-			// Test to write to a closed DeflaterOutputStream
-			try {
-				dos.write(5);
-				fail(
-						"DeflaterOutputStream Able To Write After Being Closed.");
-			} catch (IOException e) {
-			}
-
-			// Test to write to a FileOutputStream that should have been closed
-			// by
-			// the DeflaterOutputStream.
-			try {
-				fos.write(("testing").getBytes());
-				fail(
-						"FileOutputStream Able To Write After Being Closed.");
-			} catch (IOException e) {
-			}
-
-			f1.delete();
-		} catch (SecurityException e) {
-			fail("Unexpected SecurityException during test");
-		} catch (IOException e) {
-			fail("Unexpected IOException during test");
-		}
-	}
-
-	/**
-	 * @tests java.util.zip.DeflaterOutputStream#finish()
-	 */
-	public void test_finish() {
-		// Test for method java.util.zip.DeflaterOutputStream.finish()
-
-		// Need test to see if method finish() actually finishes
-		// Only testing possible errors, not if it actually works
-
-		try {
-			File f1 = new File("finish.tst");
-			FileOutputStream fos1 = new FileOutputStream(f1);
-			DeflaterOutputStream dos = new DeflaterOutputStream(fos1);
-			byte byteArray[] = { 1, 3, 4, 6 };
-			dos.write(byteArray);
-			dos.finish();
-
-			// Test to see if the same FileOutputStream can be used with the
-			// DeflaterOutputStream after finish is called.
-			try {
-				dos.write(1);
-				fail("IOException not thrown");
-			} catch (IOException e) {
-			}
-
-			// Test for writing with a new FileOutputStream using the same
-			// DeflaterOutputStream.
-			FileOutputStream fos2 = new FileOutputStream(f1);
-			try {
-				dos = new DeflaterOutputStream(fos2);
-				dos.write(1);
-			} catch (IOException e) {
-				fail("Unexpected IOException");
-			}
-
-			// Test for writing to FileOutputStream fos1, which should be open.
-			try {
-				fos1.write(("testing").getBytes());
-			} catch (IOException e) {
-				fail(
-						"Unexpected IOException While Using The FileOutputStream 1.");
-			}
-
-			// Test for writing to FileOutputStream fos2, which should be open.
-			try {
-				fos2.write(("testing").getBytes());
-			} catch (IOException e) {
-				fail("Unexpected IOException while using the FileOutputStream 2");
-			}
-
-			// Not sure if this test will stay.
-			FileOutputStream fos3 = new FileOutputStream(f1);
-			DeflaterOutputStream dos3 = new DeflaterOutputStream(fos3);
-			fos3.close();
-			try {
-				dos3.finish();
-				fail("IOException not thrown");
-			} catch (IOException e) {
-			}
-
-			// dos.close() won't close fos1 because it has been re-assigned to
-			// fos2
-			fos1.close();
-			dos.close();
-			f1.delete();
-		} catch (SecurityException e) {
-			fail("Unexpected SecurityException during test");
-		} catch (IOException e) {
-			fail("Unexpected IOException during test");
-		}
-
-	}
-
-	/**
-	 * @tests java.util.zip.DeflaterOutputStream#write(int)
-	 */
-	public void test_writeI() {
-		// Test for method java.util.zip.deflaterOutputStream.write(int)
-
-		try {
-			File f1 = new File("writeI1.tst");
-			FileOutputStream fos = new FileOutputStream(f1);
-			DeflaterOutputStream dos = new DeflaterOutputStream(fos);
-			for (int i = 0; i < 3; i++) {
-                dos.write(i);
-            }
-			dos.close();
-			FileInputStream fis = new FileInputStream(f1);
-			InflaterInputStream iis = new InflaterInputStream(fis);
-			for (int i = 0; i < 3; i++) {
-                assertTrue("Incorrect Byte Returned.", iis.read() == i);
-            }
-			assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
-			assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
-			iis.close();
-
-			// Not sure if this test is that important.
-			// Checks to see if you can write using the DeflaterOutputStream
-			// after
-			// the FileOutputStream has been closed.
-			FileOutputStream fos2 = new FileOutputStream(f1);
-			DeflaterOutputStream dos2 = new DeflaterOutputStream(fos2);
-			fos2.close();
-			try {
-				dos2.write(2);
-				fail("IOException not thrown");
-			} catch (IOException e) {
-			}
-
-			f1.delete();
-		} catch (SecurityException e) {
-			fail("Unexpected SecurityException during test");
-		} catch (IOException e) {
-			fail("Unexpected IOException during test.");
-		}
-	}
-
-	/**
-	 * @tests java.util.zip.DeflaterOutputStream#write(byte[], int, int)
-	 */
-	public void test_write$BII() {
-		// Test method
-		// java.util.zip.deflaterOutputStream.write(byteArrat,int,int)
-		try {
-			byte byteArray[] = { 1, 3, 4, 7, 8, 3, 6 };
-
-			// Test to see if the correct bytes are saved.
-			File f1 = new File("writeBII.tst");
-			FileOutputStream fos1 = new FileOutputStream(f1);
-			DeflaterOutputStream dos1 = new DeflaterOutputStream(fos1);
-			dos1.write(byteArray, 2, 3);
-			dos1.close();
-			FileInputStream fis = new FileInputStream(f1);
-			InflaterInputStream iis = new InflaterInputStream(fis);
-			assertEquals("Incorrect Byte Returned.", 4, iis.read());
-			assertEquals("Incorrect Byte Returned.", 7, iis.read());
-			assertEquals("Incorrect Byte Returned.", 8, iis.read());
-			assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
-			assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
-			iis.close();
-			f1.delete();
-
-			// Test for trying to write more bytes than available from the array
-			File f2 = new File("writeBII2.tst");
-			FileOutputStream fos2 = new FileOutputStream(f2);
-			DeflaterOutputStream dos2 = new DeflaterOutputStream(fos2);
-			try {
-				dos2.write(byteArray, 2, 10);
-				fail("IndexOutOfBoundsException not thrown");
-			} catch (IndexOutOfBoundsException e) {
-			}
-
-			// Test for trying to write a negative number of bytes.
-			try {
-				dos2.write(byteArray, 2, Integer.MIN_VALUE);
-				fail("IndexOutOfBoundsException not thrown");
-			} catch (IndexOutOfBoundsException e) {
-			}
-
-			// Test for trying to start writing from a byte < 0 from the array.
-			try {
-				dos2.write(byteArray, Integer.MIN_VALUE, 2);
-				fail("IndexOutOfBoundsException not thrown");
-			} catch (IndexOutOfBoundsException e) {
-			}
-
-			// Test for trying to start writing from a byte > than the array
-			// size.
-			try {
-				dos2.write(byteArray, 10, 2);
-				fail("IndexOutOfBoundsException not thrown");
-			} catch (IndexOutOfBoundsException e) {
-			}
-			dos2.close();
-
-			// Not sure if this test is that important.
-			// Checks to see if you can write using the DeflaterOutputStream
-			// after
-			// the FileOutputStream has been closed.
-			FileOutputStream fos3 = new FileOutputStream(f2);
-			DeflaterOutputStream dos3 = new DeflaterOutputStream(fos3);
-			fos3.close();
-			try {
-				dos3.write(byteArray, 2, 3);
-				fail("IOException not thrown");
-			} catch (IOException e) {
-			}
-
-			f2.delete();
-		} catch (SecurityException e) {
-			fail("Unexpectd SecurityException during test");
-		} catch (IOException e) {
-			fail("Unexpected IOException during test");
-		}
-	}
+public class DeflaterOutputStreamTest extends TestCase {
 
-	@Override
-    protected void setUp() {
-		// setting up a deflater to be used
-		byte byteArray[] = { 1, 3, 4, 7, 8 };
-		int x = 0;
-		Deflater deflate = new Deflater(1);
-		deflate.setInput(byteArray);
-		while (!(deflate.needsInput())) {
-			x += deflate.deflate(outPutBuf, x, outPutBuf.length - x);
-		}
-		deflate.finish();
-		while (!(deflate.finished())) {
-			x = x + deflate.deflate(outPutBuf, x, outPutBuf.length - x);
-		}
-		deflate.end();
-	}
+    private class MyDeflaterOutputStream extends DeflaterOutputStream {
+        MyDeflaterOutputStream(OutputStream out) {
+            super(out);
+        }
+
+        MyDeflaterOutputStream(OutputStream out, Deflater defl) {
+            super(out, defl);
+        }
+
+        MyDeflaterOutputStream(OutputStream out, Deflater defl, int size) {
+            super(out, defl, size);
+        }
 
-	@Override
-    protected void tearDown() {
+        byte[] getProtectedBuf() {
+            return buf;
+        }
 
-	}
+        void myDeflate() throws IOException {
+            deflate();
+        }
+    }
+
+    private byte outPutBuf[] = new byte[500];
+
+    @Override
+    protected void setUp() {
+        // setting up a deflater to be used
+        byte byteArray[] = { 1, 3, 4, 7, 8 };
+        int x = 0;
+        Deflater deflate = new Deflater(1);
+        deflate.setInput(byteArray);
+        while (!(deflate.needsInput())) {
+            x += deflate.deflate(outPutBuf, x, outPutBuf.length - x);
+        }
+        deflate.finish();
+        while (!(deflate.finished())) {
+            x = x + deflate.deflate(outPutBuf, x, outPutBuf.length - x);
+        }
+        deflate.end();
+    }
+
+    /**
+     * @tests java.util.zip.DeflaterOutputStream#DeflaterOutputStream(java.io.OutputStream,
+     *        java.util.zip.Deflater)
+     */
+    public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_Deflater() throws Exception {
+        byte byteArray[] = { 1, 3, 4, 7, 8 };
+        File f1 = new File("hyts_Constru(OD).tst");
+        FileOutputStream fos = new FileOutputStream(f1);
+        Deflater defl = null;
+        MyDeflaterOutputStream dos;
+        // Test for a null Deflater.
+        try {
+            dos = new MyDeflaterOutputStream(fos, defl);
+            fail("NullPointerException Not Thrown");
+        } catch (NullPointerException e) {
+        }
+        defl = new Deflater();
+        dos = new MyDeflaterOutputStream(fos, defl);
+
+        // Test to see if DflaterOutputStream was created with the correct
+        // buffer.
+        assertEquals("Incorrect Buffer Size", 512, dos.getProtectedBuf().length);
+
+        dos.write(byteArray);
+        dos.close();
+        f1.delete();
+    }
+
+    /**
+     * @tests java.util.zip.DeflaterOutputStream#DeflaterOutputStream(java.io.OutputStream)
+     */
+    public void test_ConstructorLjava_io_OutputStream() throws Exception {
+        File f1 = new File("hyts_Constru(O).tst");
+        FileOutputStream fos = new FileOutputStream(f1);
+        MyDeflaterOutputStream dos = new MyDeflaterOutputStream(fos);
+
+        // Test to see if DflaterOutputStream was created with the correct
+        // buffer.
+        assertEquals("Incorrect Buffer Size", 512, dos.getProtectedBuf().length);
+
+        dos.write(outPutBuf);
+        dos.close();
+        f1.delete();
+    }
+
+    /**
+     * @tests java.util.zip.DeflaterOutputStream#DeflaterOutputStream(java.io.OutputStream,
+     *        java.util.zip.Deflater, int)
+     */
+    public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_DeflaterI()
+            throws Exception {
+        int buf = 5;
+        int negBuf = -5;
+        int zeroBuf = 0;
+        byte byteArray[] = { 1, 3, 4, 7, 8, 3, 6 };
+        File f1 = new File("hyts_Constru(ODI).tst");
+        FileOutputStream fos = new FileOutputStream(f1);
+        Deflater defl = null;
+        MyDeflaterOutputStream dos;
+
+        // Test for a null Deflater.
+        try {
+            dos = new MyDeflaterOutputStream(fos, defl, buf);
+            fail("NullPointerException Not Thrown");
+        } catch (NullPointerException e) {
+        }
+        defl = new Deflater();
+
+        // Test for a negative buf.
+        try {
+            dos = new MyDeflaterOutputStream(fos, defl, negBuf);
+            fail("IllegalArgumentException Not Thrown");
+        } catch (IllegalArgumentException e) {
+        }
+
+        // Test for a zero buf.
+        try {
+            dos = new MyDeflaterOutputStream(fos, defl, zeroBuf);
+            fail("IllegalArgumentException Not Thrown");
+        } catch (IllegalArgumentException e) {
+        }
+
+        // Test to see if DflaterOutputStream was created with the correct
+        // buffer.
+        dos = new MyDeflaterOutputStream(fos, defl, buf);
+        assertEquals("Incorrect Buffer Size", 5, dos.getProtectedBuf().length);
+
+        dos.write(byteArray);
+        dos.close();
+        f1.delete();
+    }
+
+    /**
+     * @tests java.util.zip.DeflaterOutputStream#close()
+     */
+    public void test_close() throws Exception {
+        File f1 = new File("close.tst");
+        FileOutputStream fos = new FileOutputStream(f1);
+        DeflaterOutputStream dos = new DeflaterOutputStream(fos);
+        byte byteArray[] = { 1, 3, 4, 6 };
+        dos.write(byteArray);
+
+        FileInputStream fis = new FileInputStream(f1);
+        InflaterInputStream iis = new InflaterInputStream(fis);
+        try {
+            iis.read();
+            fail("EOFException Not Thrown");
+        } catch (EOFException e) {
+        }
+
+        dos.close();
+
+        // Test to see if the finish method wrote the bytes to the file.
+        assertEquals("Incorrect Byte Returned.", 1, iis.read());
+        assertEquals("Incorrect Byte Returned.", 3, iis.read());
+        assertEquals("Incorrect Byte Returned.", 4, iis.read());
+        assertEquals("Incorrect Byte Returned.", 6, iis.read());
+        assertEquals("Incorrect Byte Returned.", -1, iis.read());
+        assertEquals("Incorrect Byte Returned.", -1, iis.read());
+        iis.close();
+
+        // Not sure if this test will stay.
+        FileOutputStream fos2 = new FileOutputStream(f1);
+        DeflaterOutputStream dos2 = new DeflaterOutputStream(fos2);
+        fos2.close();
+        try {
+            dos2.close();
+            fail("IOException not thrown");
+        } catch (IOException e) {
+        }
+
+        // Test to write to a closed DeflaterOutputStream
+        try {
+            dos.write(5);
+            fail("DeflaterOutputStream Able To Write After Being Closed.");
+        } catch (IOException e) {
+        }
+
+        // Test to write to a FileOutputStream that should have been closed
+        // by
+        // the DeflaterOutputStream.
+        try {
+            fos.write(("testing").getBytes());
+            fail("FileOutputStream Able To Write After Being Closed.");
+        } catch (IOException e) {
+        }
+
+        f1.delete();
+    }
+
+    /**
+     * @tests java.util.zip.DeflaterOutputStream#finish()
+     */
+    public void test_finish() throws Exception {
+        // Need test to see if method finish() actually finishes
+        // Only testing possible errors, not if it actually works
+
+        File f1 = new File("finish.tst");
+        FileOutputStream fos1 = new FileOutputStream(f1);
+        DeflaterOutputStream dos = new DeflaterOutputStream(fos1);
+        byte byteArray[] = { 1, 3, 4, 6 };
+        dos.write(byteArray);
+        dos.finish();
+
+        // Test to see if the same FileOutputStream can be used with the
+        // DeflaterOutputStream after finish is called.
+        try {
+            dos.write(1);
+            fail("IOException not thrown");
+        } catch (IOException e) {
+        }
+
+        // Test for writing with a new FileOutputStream using the same
+        // DeflaterOutputStream.
+        FileOutputStream fos2 = new FileOutputStream(f1);
+        dos = new DeflaterOutputStream(fos2);
+        dos.write(1);
+
+        // Test for writing to FileOutputStream fos1, which should be open.
+        fos1.write(("testing").getBytes());
+
+        // Test for writing to FileOutputStream fos2, which should be open.
+        fos2.write(("testing").getBytes());
+
+        // Not sure if this test will stay.
+        FileOutputStream fos3 = new FileOutputStream(f1);
+        DeflaterOutputStream dos3 = new DeflaterOutputStream(fos3);
+        fos3.close();
+        try {
+            dos3.finish();
+            fail("IOException not thrown");
+        } catch (IOException e) {
+        }
+
+        // dos.close() won't close fos1 because it has been re-assigned to
+        // fos2
+        fos1.close();
+        dos.close();
+        f1.delete();
+    }
+
+    /**
+     * @tests java.util.zip.DeflaterOutputStream#write(int)
+     */
+    public void test_writeI() throws Exception {
+        File f1 = new File("writeI1.tst");
+        FileOutputStream fos = new FileOutputStream(f1);
+        DeflaterOutputStream dos = new DeflaterOutputStream(fos);
+        for (int i = 0; i < 3; i++) {
+            dos.write(i);
+        }
+        dos.close();
+        FileInputStream fis = new FileInputStream(f1);
+        InflaterInputStream iis = new InflaterInputStream(fis);
+        for (int i = 0; i < 3; i++) {
+            assertEquals("Incorrect Byte Returned.", i, iis.read());
+        }
+        assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
+        assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
+        iis.close();
+
+        // Not sure if this test is that important.
+        // Checks to see if you can write using the DeflaterOutputStream
+        // after
+        // the FileOutputStream has been closed.
+        FileOutputStream fos2 = new FileOutputStream(f1);
+        DeflaterOutputStream dos2 = new DeflaterOutputStream(fos2);
+        fos2.close();
+        try {
+            dos2.write(2);
+            fail("IOException not thrown");
+        } catch (IOException e) {
+        }
+
+        f1.delete();
+    }
+
+    /**
+     * @tests java.util.zip.DeflaterOutputStream#write(byte[], int, int)
+     */
+    public void test_write$BII() throws Exception {
+        byte byteArray[] = { 1, 3, 4, 7, 8, 3, 6 };
+
+        // Test to see if the correct bytes are saved.
+        File f1 = new File("writeBII.tst");
+        FileOutputStream fos1 = new FileOutputStream(f1);
+        DeflaterOutputStream dos1 = new DeflaterOutputStream(fos1);
+        dos1.write(byteArray, 2, 3);
+        dos1.close();
+        FileInputStream fis = new FileInputStream(f1);
+        InflaterInputStream iis = new InflaterInputStream(fis);
+        assertEquals("Incorrect Byte Returned.", 4, iis.read());
+        assertEquals("Incorrect Byte Returned.", 7, iis.read());
+        assertEquals("Incorrect Byte Returned.", 8, iis.read());
+        assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
+        assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
+        iis.close();
+        f1.delete();
+
+        // Test for trying to write more bytes than available from the array
+        File f2 = new File("writeBII2.tst");
+        FileOutputStream fos2 = new FileOutputStream(f2);
+        DeflaterOutputStream dos2 = new DeflaterOutputStream(fos2);
+        try {
+            dos2.write(byteArray, 2, 10);
+            fail("IndexOutOfBoundsException not thrown");
+        } catch (IndexOutOfBoundsException e) {
+        }
+
+        // Test for trying to write a negative number of bytes.
+        try {
+            dos2.write(byteArray, 2, Integer.MIN_VALUE);
+            fail("IndexOutOfBoundsException not thrown");
+        } catch (IndexOutOfBoundsException e) {
+        }
+
+        // Test for trying to start writing from a byte < 0 from the array.
+        try {
+            dos2.write(byteArray, Integer.MIN_VALUE, 2);
+            fail("IndexOutOfBoundsException not thrown");
+        } catch (IndexOutOfBoundsException e) {
+        }
+
+        // Test for trying to start writing from a byte > than the array
+        // size.
+        try {
+            dos2.write(byteArray, 10, 2);
+            fail("IndexOutOfBoundsException not thrown");
+        } catch (IndexOutOfBoundsException e) {
+        }
+        dos2.close();
+
+        // Not sure if this test is that important.
+        // Checks to see if you can write using the DeflaterOutputStream
+        // after
+        // the FileOutputStream has been closed.
+        FileOutputStream fos3 = new FileOutputStream(f2);
+        DeflaterOutputStream dos3 = new DeflaterOutputStream(fos3);
+        fos3.close();
+        try {
+            dos3.write(byteArray, 2, 3);
+            fail("IOException not thrown");
+        } catch (IOException e) {
+        }
 
+        f2.delete();
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java?view=diff&rev=485488&r1=485487&r2=485488
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java Sun Dec 10 20:12:41 2006
@@ -14,22 +14,22 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.harmony.archive.tests.java.util.zip;
 
-import java.io.IOException;
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
 import java.util.zip.Adler32;
 import java.util.zip.DataFormatException;
 import java.util.zip.Deflater;
 import java.util.zip.Inflater;
 
-import java.io.UnsupportedEncodingException;
-
+import junit.framework.TestCase;
 import tests.support.resource.Support_Resources;
 
-public class DeflaterTest extends junit.framework.TestCase {
+public class DeflaterTest extends TestCase {
 
-	class MyDeflater extends java.util.zip.Deflater {
+	class MyDeflater extends Deflater {
 		MyDeflater() {
 			super();
 		}
@@ -67,7 +67,6 @@
 	 * @tests java.util.zip.Deflater#deflate(byte[])
 	 */
 	public void test_deflate$B() {
-		// test method of java.util.zip.deflater.deflate(byte)
 		byte outPutBuf[] = new byte[50];
 		byte byteArray[] = { 1, 3, 4, 7, 8 };
 		byte outPutInf[] = new byte[50];
@@ -81,15 +80,10 @@
         }
 		assertEquals("Deflater at end of stream, should return 0", 0, defl
 				.deflate(outPutBuf));
-		int totalOut = defl.getTotalOut();
-		int totalIn = defl.getTotalIn();
-		assertTrue(
-				"The total number of bytes from deflate did not equal getTotalOut",
-				x == totalOut);
-		assertTrue(
-				"The number of input bytes from the array did not correspond with getTotalIn: Was "
-						+ totalIn + " Should Be " + byteArray.length,
-				totalIn == byteArray.length);
+        int totalOut = defl.getTotalOut();
+        int totalIn = defl.getTotalIn();
+        assertEquals(x, totalOut);
+        assertEquals(byteArray.length, totalIn);
 		defl.end();
 
 		Inflater infl = new Inflater();
@@ -101,16 +95,10 @@
 		} catch (DataFormatException e) {
 			fail("Invalid input to be decompressed");
 		}
-		assertTrue(
-				"Inflates getTotalOut() did not correspond with deflates getTotalIn()",
-				infl.getTotalOut() == totalIn);
-		assertTrue(
-				"Inflates getTotalIn() did not correspond with deflates getTotalOut()",
-				infl.getTotalIn() == totalOut);
+        assertEquals(totalIn, infl.getTotalOut());
+        assertEquals(totalOut, infl.getTotalIn());
 		for (int i = 0; i < byteArray.length; i++) {
-            assertTrue(
-					"Final decompressed data does not equal the original data",
-					byteArray[i] == outPutInf[i]);
+            assertEquals(byteArray[i], outPutInf[i]);
         }
 		assertEquals("Final decompressed data contained more bytes than original",
 				0, outPutInf[byteArray.length]);
@@ -121,7 +109,6 @@
 	 * @tests java.util.zip.Deflater#deflate(byte[], int, int)
 	 */
 	public void test_deflate$BII() {
-		// test method of java.util.zip.deflater.deflate(byte,int,int)
 		byte outPutBuf[] = new byte[50];
 		byte byteArray[] = { 5, 2, 3, 7, 8 };
 		byte outPutInf[] = new byte[50];
@@ -139,12 +126,8 @@
 				outPutBuf, offSet, length));
 		int totalOut = defl.getTotalOut();
 		int totalIn = defl.getTotalIn();
-		assertTrue(
-				"The total number of bytes from deflate did not equal getTotalOut",
-				totalOut == x);
-		assertTrue(
-				"The number of input bytes from the array did not correspond with getTotalIn - side effect of deflate()",
-				totalIn == byteArray.length);
+        assertEquals(x, totalOut);
+        assertEquals(byteArray.length, totalIn);
 		defl.end();
 
 		Inflater infl = new Inflater();
@@ -156,16 +139,10 @@
 		} catch (DataFormatException e) {
 			fail("Invalid input to be decompressed");
 		}
-		assertTrue(
-				"inflates getTotalOut() did not correspond with deflates getTotalIn()",
-				infl.getTotalOut() == totalIn);
-		assertTrue(
-				"inflates getTotalIn() did not correspond with deflates getTotalOut()",
-				infl.getTotalIn() == totalOut);
+        assertEquals(totalIn, infl.getTotalOut());
+        assertEquals(totalOut, infl.getTotalIn());
 		for (int i = 0; i < byteArray.length; i++) {
-            assertTrue(
-					"Final decompressed data does not equal the original data",
-					byteArray[i] == outPutInf[i]);
+            assertEquals(byteArray[i], outPutInf[i]);
         }
 		assertEquals("Final decompressed data contained more bytes than original",
 				0, outPutInf[byteArray.length]);
@@ -197,8 +174,6 @@
 	 * @tests java.util.zip.Deflater#end()
 	 */
 	public void test_end() {
-		// test method java.util.zip.deflater.end();
-
 		byte byteArray[] = { 5, 2, 3, 7, 8 };
 		byte outPutBuf[] = new byte[100];
 
@@ -216,7 +191,6 @@
 	 * @tests java.util.zip.Deflater#finalize()
 	 */
 	public void test_finalize() {
-		// test method java.util.zip.deflater.finalize()
 		MyDeflater mdefl = new MyDeflater();
 		mdefl.myFinalize();
 		System.gc();
@@ -226,8 +200,7 @@
 	/**
 	 * @tests java.util.zip.Deflater#finish()
 	 */
-	public void test_finish() {
-		// test method java.util.zip.deflater.finish()
+	public void test_finish() throws Exception {
 		// This test already here, its the same as test_deflate()
 		byte byteArray[] = { 5, 2, 3, 7, 8 };
 		byte outPutBuf[] = new byte[100];
@@ -239,9 +212,8 @@
 
 		// needsInput should never return true after finish() is called
 		if (System.getProperty("java.vendor").startsWith("IBM")) {
-            assertTrue(
-					"needsInput() should return false after finish() is called",
-					!defl.needsInput());
+            assertFalse("needsInput() should return false after finish() is called", defl
+                    .needsInput());
         }
 
 		while (!defl.finished()) {
@@ -249,33 +221,19 @@
         }
 		int totalOut = defl.getTotalOut();
 		int totalIn = defl.getTotalIn();
-		assertTrue(
-				"The total number of bytes from deflate did not equal getTotalOut",
-				x == totalOut);
-		assertTrue(
-				"The number of input bytes from the array did not correspond with getTotalIn",
-				totalIn == byteArray.length);
+        assertEquals(x, totalOut);
+        assertEquals(byteArray.length, totalIn);
 		defl.end();
 
 		Inflater infl = new Inflater();
-		try {
-			infl.setInput(outPutBuf);
-			while (!infl.finished()) {
-                infl.inflate(outPutInf);
-            }
-		} catch (DataFormatException e) {
-			fail("Invalid input to be decompressed");
+		infl.setInput(outPutBuf);
+		while (!infl.finished()) {
+		    infl.inflate(outPutInf);
 		}
-		assertTrue(
-				"Inflates getTotalOut() did not correspond with deflates getTotalIn()",
-				infl.getTotalOut() == totalIn);
-		assertTrue(
-				"Inflates getTotalIn() did not correspond with deflates getTotalOut()",
-				infl.getTotalIn() == totalOut);
+        assertEquals(totalIn, infl.getTotalOut());
+        assertEquals(totalOut, infl.getTotalIn());
 		for (int i = 0; i < byteArray.length; i++) {
-            assertTrue(
-					"Final decompressed data does not equal the original data",
-					byteArray[i] == outPutInf[i]);
+            assertEquals(byteArray[i], outPutInf[i]);
         }
 		assertEquals("Final decompressed data contained more bytes than original",
 				0, outPutInf[byteArray.length]);
@@ -286,7 +244,6 @@
 	 * @tests java.util.zip.Deflater#finished()
 	 */
 	public void test_finished() {
-		// test method java.util.zip.deflater.finish()
 		byte byteArray[] = { 5, 2, 3, 7, 8 };
 		byte outPutBuf[] = new byte[100];
 		Deflater defl = new Deflater();
@@ -307,7 +264,6 @@
 	 * @tests java.util.zip.Deflater#getAdler()
 	 */
 	public void test_getAdler() {
-		// test method for java.util.zip.Deflater.getAdler()
 		byte byteArray[] = { 'a', 'b', 'c', 1, 2, 3 };
 		byte outPutBuf[] = new byte[100];
 		Deflater defl = new Deflater();
@@ -325,16 +281,15 @@
 		Adler32 adl = new Adler32();
 		adl.update(byteArray);
 		long checkSumR = adl.getValue();
-		assertTrue(
-				"The checksum value returned by getAdler() is not the same as the checksum returned by creating the adler32 instance",
-				checkSumR == checkSumD);
+		assertEquals(
+                "The checksum value returned by getAdler() is not the same as the checksum returned by creating the adler32 instance",
+                checkSumD, checkSumR);
 	}
 
 	/**
 	 * @tests java.util.zip.Deflater#getTotalIn()
 	 */
 	public void test_getTotalIn() {
-		// test method java.util.zip.deflater.getTotalIn()
 		byte outPutBuf[] = new byte[5];
 		byte byteArray[] = { 1, 3, 4, 7, 8 };
 
@@ -344,9 +299,7 @@
 		while (!defl.finished()) {
             defl.deflate(outPutBuf);
         }
-		assertTrue(
-				"The number of input byte from the array did not correspond with getTotalIn",
-				defl.getTotalIn() == byteArray.length);
+        assertEquals(byteArray.length, defl.getTotalIn());
 		defl.end();
 
 		defl = new Deflater();
@@ -358,9 +311,7 @@
 		while (!defl.finished()) {
             defl.deflate(outPutBuf);
         }
-		assertTrue(
-				"The number of input byte sent to setInputBII() did not corrsepond with getTotalIn",
-				defl.getTotalIn() == length);
+        assertEquals(length, defl.getTotalIn());
 		defl.end();
 	}
 
@@ -368,7 +319,6 @@
 	 * @tests java.util.zip.Deflater#getTotalOut()
 	 */
 	public void test_getTotalOut() {
-		// test method java.util.zip.deflater.getTotalOut()
 		// the getTotalOut should equal the sum of value returned by deflate()
 		byte outPutBuf[] = new byte[5];
 		byte byteArray[] = { 5, 2, 3, 7, 8 };
@@ -379,9 +329,7 @@
 		while (!defl.finished()) {
             x += defl.deflate(outPutBuf);
         }
-		assertTrue(
-				"The total number of bytes from deflate() did not equal getTotalOut",
-				x == defl.getTotalOut());
+        assertEquals(x, defl.getTotalOut());
 		defl.end();
 
 		x = 0;
@@ -394,25 +342,22 @@
 		while (!defl.finished()) {
             x += defl.deflate(outPutBuf);
         }
-		assertTrue(
-				"The total number of bytes from deflateBII() did not equal getTotalOut",
-				x == defl.getTotalOut());
+        assertEquals(x, defl.getTotalOut());
 	}
 
 	/**
 	 * @tests java.util.zip.Deflater#needsInput()
 	 */
 	public void test_needsInput() {
-		// test method of java.util.zip.deflater.needsInput()
 		Deflater defl = new Deflater();
 		assertTrue(
 				"needsInput give the wrong boolean value as a result of no input buffer",
 				defl.needsInput());
 		byte byteArray[] = { 1, 2, 3 };
 		defl.setInput(byteArray);
-		assertTrue(
+		assertFalse(
 				"needsInput give wrong boolean value as a result of a full input buffer",
-				!defl.needsInput());
+				defl.needsInput());
 		byte[] outPutBuf = new byte[50];
 		while (!defl.needsInput()) {
             defl.deflate(outPutBuf);
@@ -430,9 +375,9 @@
 		// needsInput should NOT return true after finish() has been
 		// called.
 		if (System.getProperty("java.vendor").startsWith("IBM")) {
-            assertTrue(
+            assertFalse(
 					"needsInput gave wrong boolean value as a result of finish() being called",
-					!defl.needsInput());
+					defl.needsInput());
         }
 		defl.end();
 	}
@@ -441,7 +386,6 @@
 	 * @tests java.util.zip.Deflater#reset()
 	 */
 	public void test_reset() {
-		// test method of java.util.zip.deflater.reset()
 		byte outPutBuf[] = new byte[100];
 		byte outPutInf[] = new byte[100];
 		byte curArray[] = new byte[5];
@@ -467,17 +411,11 @@
             }
 
 			if (i == 0) {
-                assertTrue(
-						"The total number of bytes from deflate did not equal getTotalOut",
-						x == defl.getTotalOut());
+                assertEquals(x, defl.getTotalOut());
             } else if (i == 1) {
-                assertTrue(
-						"The total number of bytes from deflate should still be the same ("
-								+ x + ")", x == orgValue);
+                assertEquals(x, orgValue);
             } else {
-                assertTrue(
-						"The total number of bytes from deflate should be doubled ("
-								+ orgValue * 2 + ")", x == orgValue * 2);
+                assertEquals(x, orgValue * 2);
             }
 
 			if (i == 0) {
@@ -500,17 +438,9 @@
             }
 
 			for (int j = 0; j < curArray.length; j++) {
-                assertTrue(
-						"Test "
-								+ i
-								+ ": Final decompressed data does not equal the original data",
-						curArray[j] == outPutInf[j]);
+                assertEquals(curArray[j], outPutInf[j]);
             }
-			assertTrue(
-					"Test "
-							+ i
-							+ ": Final decompressed data contained more bytes than original",
-					outPutInf[curArray.length] == 0);
+            assertEquals(0, outPutInf[curArray.length]);
 		}
 	}
 
@@ -518,7 +448,6 @@
 	 * @tests java.util.zip.Deflater#setDictionary(byte[])
 	 */
 	public void test_setDictionary$B() {
-		// test method of java.util.zip.deflater.setDictionary(byte[])
 		// This test is very close to getAdler()
 		byte dictionaryArray[] = { 'e', 'r', 't', 'a', 'b', 2, 3 };
 		byte byteArray[] = { 4, 5, 3, 2, 'a', 'b', 6, 7, 8, 9, 0, 's', '3',
@@ -536,9 +465,7 @@
 		Adler32 adl = new Adler32();
 		adl.update(dictionaryArray);
 		long realAdler = adl.getValue();
-		assertTrue(
-				"Dictionary is set, getAdler() should equal the adler value of the dictionaryArray",
-				deflAdler == realAdler);
+        assertEquals(deflAdler, realAdler);
 
 		defl.setInput(byteArray);
 		defl.finish();
@@ -552,8 +479,7 @@
 		// Deflate is finished and there were bytes deflated that did not occur
 		// in the dictionaryArray, therefore a new dictionary was automatically
 		// set.
-		assertTrue("getAdler() returned " + deflAdler + " should be "
-				+ realAdler, deflAdler == realAdler);
+        assertEquals(realAdler, deflAdler);
 		defl.end();
 	}
 
@@ -561,7 +487,6 @@
 	 * @tests java.util.zip.Deflater#setDictionary(byte[], int, int)
 	 */
 	public void test_setDictionary$BII() {
-		// test method of java.util.zip.deflater.setDictionary(byte)
 		// This test is very close to getAdler()
 		byte dictionaryArray[] = { 'e', 'r', 't', 'a', 'b', 2, 3, 'o', 't' };
 		byte byteArray[] = { 4, 5, 3, 2, 'a', 'b', 6, 7, 8, 9, 0, 's', '3',
@@ -582,9 +507,7 @@
 		Adler32 adl = new Adler32();
 		adl.update(dictionaryArray, offSet, length);
 		long realAdler = adl.getValue();
-		assertTrue(
-				"Dictionary is set, getAdler() should equal the adler value of the dictionaryArray",
-				deflAdler == realAdler);
+        assertEquals(deflAdler, realAdler);
 
 		defl.setInput(byteArray);
 		while (!defl.needsInput()) {
@@ -597,8 +520,7 @@
 		// Deflate is finished and there were bytes deflated that did not occur
 		// in the dictionaryArray, therefore a new dictionary was automatically
 		// set.
-		assertTrue("getAdler() returned " + deflAdler + " should be "
-				+ realAdler, deflAdler == realAdler);
+        assertEquals(realAdler, deflAdler);
 		defl.end();
 
 		// boundary check
@@ -627,7 +549,6 @@
 	 * @tests java.util.zip.Deflater#setInput(byte[])
 	 */
 	public void test_setInput$B() {
-		// test method of java.util.zip.Deflater.setInput(byte)
 		byte[] byteArray = { 1, 2, 3 };
 		byte[] outPutBuf = new byte[50];
 		byte[] outPutInf = new byte[50];
@@ -655,21 +576,16 @@
 			fail("Invalid input to be decompressed");
 		}
 		for (int i = 0; i < byteArray.length; i++) {
-            assertTrue(
-					"Final decompressed data does not equal the original data",
-					byteArray[i] == outPutInf[i]);
+            assertEquals(byteArray[i], outPutInf[i]);
         }
-		assertTrue(
-				"Inflater.getTotalOut should have been equal to the length of the input",
-				infl.getTotalOut() == byteArray.length);
+		assertEquals(byteArray.length, infl.getTotalOut());
 		infl.end();
 	}
 
 	/**
 	 * @tests java.util.zip.Deflater#setInput(byte[], int, int)
 	 */
-	public void test_setInput$BII() {
-		// test methods of java.util.zip.Deflater.setInput(byte,int,int)
+	public void test_setInput$BII() throws Exception {
 		byte[] byteArray = { 1, 2, 3, 4, 5 };
 		byte[] outPutBuf = new byte[50];
 		byte[] outPutInf = new byte[50];
@@ -678,8 +594,7 @@
 
 		Deflater defl = new Deflater();
 		defl.setInput(byteArray, offSet, length);
-		assertTrue("the array buffer in setInput() is empty", !defl
-				.needsInput());
+		assertFalse("the array buffer in setInput() is empty", defl.needsInput());
 		// The second setInput() should be ignored since needsInput() return
 		// false
 		defl.setInput(byteArray, offSet, length);
@@ -690,22 +605,14 @@
 		defl.end();
 
 		Inflater infl = new Inflater();
-		try {
-			infl.setInput(outPutBuf);
-			while (!infl.finished()) {
-                infl.inflate(outPutInf);
-            }
-		} catch (DataFormatException e) {
-			fail("Invalid input to be decompressed");
+		infl.setInput(outPutBuf);
+		while (!infl.finished()) {
+		    infl.inflate(outPutInf);
 		}
 		for (int i = 0; i < length; i++) {
-            assertTrue(
-					"Final decompressed data does not equal the original data",
-					byteArray[i + offSet] == outPutInf[i]);
+            assertEquals(byteArray[i + offSet], outPutInf[i]);
         }
-		assertTrue(
-				"Inflater.getTotalOut should have been equal to the length of the input",
-				infl.getTotalOut() == length);
+		assertEquals(length, infl.getTotalOut());
 		infl.end();
 
 		// boundary check
@@ -731,18 +638,12 @@
 	/**
 	 * @tests java.util.zip.Deflater#setLevel(int)
 	 */
-	public void test_setLevelI() {
-		// test methods of java.util.zip.deflater.setLevel(int)
+	public void test_setLevelI() throws Exception {
 		// Very similar to test_Constructor(int)
 		byte[] byteArray = new byte[100];
-		try {
-			InputStream inFile = Support_Resources
-					.getStream("hyts_checkInput.txt");
-			inFile.read(byteArray);
-			inFile.close();
-		} catch (IOException e) {
-			fail("Unexpected IOException " + e + " during test");
-		}
+		InputStream inFile = Support_Resources.getStream("hyts_checkInput.txt");
+		inFile.read(byteArray);
+		inFile.close();
 
 		byte[] outPutBuf;
 		int totalOut;
@@ -771,9 +672,7 @@
 			while (!defl.finished()) {
                 defl.deflate(outPutBuf);
             }
-			assertTrue(
-					"getTotalOut() not equal comparing two Deflaters with same compression level.",
-					defl.getTotalOut() == totalOut);
+			assertEquals(totalOut, defl.getTotalOut());
 			defl.end();
 		}
 
@@ -798,17 +697,11 @@
 	/**
 	 * @tests java.util.zip.Deflater#setStrategy(int)
 	 */
-	public void test_setStrategyI() {
-		// test method of java.util.zip.deflater.setStrategy(int)
+	public void test_setStrategyI() throws Exception {
 		byte[] byteArray = new byte[100];
-		try {
-			InputStream inFile = Support_Resources
-					.getStream("hyts_checkInput.txt");
+			InputStream inFile = Support_Resources.getStream("hyts_checkInput.txt");
 			inFile.read(byteArray);
 			inFile.close();
-		} catch (IOException e) {
-			fail("Unexpected IOException " + e + " during test.");
-		}
 
 		for (int i = 0; i < 3; i++) {
 			byte outPutBuf[] = new byte[500];
@@ -865,18 +758,11 @@
 	/**
 	 * @tests java.util.zip.Deflater#Deflater()
 	 */
-	public void test_Constructor() {
-		// test methods of java.util.zip.Deflater()
+	public void test_Constructor() throws Exception {
 		byte[] byteArray = new byte[100];
-		try {
-
-			InputStream inFile = Support_Resources
-					.getStream("hyts_checkInput.txt");
-			inFile.read(byteArray);
-			inFile.close();
-		} catch (IOException e) {
-			fail("Unexpected IOException " + e + " during test");
-		}
+		InputStream inFile = Support_Resources.getStream("hyts_checkInput.txt");
+		inFile.read(byteArray);
+		inFile.close();
 
 		Deflater defl = new Deflater();
 		byte[] outPutBuf = new byte[500];
@@ -903,17 +789,14 @@
 		while (!mdefl.finished()) {
             mdefl.deflate(outPutBuf);
         }
-		assertTrue(
-				"getTotalOut() not equal comparing two Deflaters with same compression level.",
-				mdefl.getTotalOut() == totalOut);
+		assertEquals(totalOut, mdefl.getTotalOut());
 		mdefl.end();
 	}
 
 	/**
 	 * @tests java.util.zip.Deflater#Deflater(int, boolean)
 	 */
-	public void test_ConstructorIZ() {
-		// test methods of java.util.zip.deflater(int,bool)
+	public void test_ConstructorIZ() throws Exception {
 		byte byteArray[] = { 4, 5, 3, 2, 'a', 'b', 6, 7, 8, 9, 0, 's', '3',
 				'w', 'r' };
 
@@ -941,9 +824,7 @@
 		while (!defl.finished()) {
             defl.deflate(outPutBuf);
         }
-		assertTrue(
-				"getTotalOut() not equal comparing two Deflaters with same compression level.",
-				defl.getTotalOut() == totalOut);
+		assertEquals(totalOut, defl.getTotalOut());
 		defl.end();
 
 		outPutBuf = new byte[500];
@@ -963,21 +844,14 @@
 
 		byte outPutInf[] = new byte[500];
 		Inflater infl = new Inflater(true);
-		try {
-			while (!infl.finished()) {
-				if (infl.needsInput()) {
-                    infl.setInput(outPutBuf);
-                }
-				infl.inflate(outPutInf);
-			}
-		} catch (DataFormatException e) {
-			fail(
-					"invalid input to inflate - called in test constructorIZ");
+		while (!infl.finished()) {
+		    if (infl.needsInput()) {
+		        infl.setInput(outPutBuf);
+		    }
+		    infl.inflate(outPutInf);
 		}
 		for (int i = 0; i < byteArray.length; i++) {
-            assertTrue(
-					"Final decompressed data does not equal the original data",
-					byteArray[i] == outPutInf[i]);
+            assertEquals(byteArray[i], outPutInf[i]);
         }
 		assertEquals("final decompressed data contained more bytes than original - construcotrIZ",
 				0, outPutInf[byteArray.length]);
@@ -1003,15 +877,13 @@
 			Deflater boundDefl = new Deflater();
 			// Level must be between 0-9
 			boundDefl.setLevel(-2);
-			fail(
-					"IllegalArgumentException not thrown when setting level to a number < 0.");
+			fail("IllegalArgumentException not thrown when setting level to a number < 0.");
 		} catch (IllegalArgumentException e) {
 		}
 		try {
 			Deflater boundDefl = new Deflater();
 			boundDefl.setLevel(10);
-			fail(
-					"IllegalArgumentException not thrown when setting level to a number > 9.");
+			fail("IllegalArgumentException not thrown when setting level to a number > 9.");
 		} catch (IllegalArgumentException e) {
 		}
 	}
@@ -1019,17 +891,11 @@
 	/**
 	 * @tests java.util.zip.Deflater#Deflater(int)
 	 */
-	public void test_ConstructorI() {
-		// test methods of java.util.zip.Deflater(int)
-		byte[] byteArray = new byte[100];
-		try {
-			InputStream inFile = Support_Resources
-					.getStream("hyts_checkInput.txt");
-			inFile.read(byteArray);
-			inFile.close();
-		} catch (IOException e) {
-			fail("Unexpected IOException " + e + " during test");
-		}
+	public void test_ConstructorI() throws Exception {
+	    byte[] byteArray = new byte[100];
+        InputStream inFile = Support_Resources.getStream("hyts_checkInput.txt");
+        inFile.read(byteArray);
+        inFile.close();
 
 		byte outPutBuf[] = new byte[500];
 		Deflater defl = new Deflater(3);
@@ -1057,27 +923,23 @@
 		while (!defl.finished()) {
             defl.deflate(outPutBuf);
         }
-		assertTrue(
-				"getTotalOut() not equal comparing two Deflaters with same compression level.",
-				defl.getTotalOut() == totalOut);
+		assertEquals(totalOut, defl.getTotalOut());
 		defl.end();
 
 		// testing boundaries
 		try {
-			Deflater boundDefl = new Deflater();
-			// Level must be between 0-9
-			boundDefl.setLevel(-2);
-			fail(
-					"IllegalArgumentException not thrown when setting level to a number < 0.");
-		} catch (IllegalArgumentException e) {
+            Deflater boundDefl = new Deflater();
+            // Level must be between 0-9
+            boundDefl.setLevel(-2);
+            fail("IllegalArgumentException not thrown when setting level to a number < 0.");
+        } catch (IllegalArgumentException e) {
 		}
 		try {
-			Deflater boundDefl = new Deflater();
-			boundDefl.setLevel(10);
-			fail(
-					"IllegalArgumentException not thrown when setting level to a number > 9.");
-		} catch (IllegalArgumentException e) {
-		}
+            Deflater boundDefl = new Deflater();
+            boundDefl.setLevel(10);
+            fail("IllegalArgumentException not thrown when setting level to a number > 9.");
+        } catch (IllegalArgumentException e) {
+        }
 	}
 
 	private void helper_end_test(Deflater defl, String desc) {
@@ -1146,30 +1008,10 @@
 		}
 
 		// Methods that should be allowed to be called after end() is called
-		try {
-			defl.needsInput();
-		} catch (Exception e) {
-			fail("Test 1: No exception should have been thrown: " + e
-					+ " in test_" + desc);
-		}
-		try {
-			defl.setStrategy(1);
-		} catch (IllegalStateException e) {
-			fail("Test 2: No exception should have been thrown: " + e
-					+ " in test_" + desc);
-		}
-		try {
-			defl.setLevel(1);
-		} catch (IllegalStateException e) {
-			fail("Test 3: No exception should have been thrown: " + e
-					+ " in test_" + desc);
-		}
-		try {
-			defl.end();
-		} catch (Exception e) {
-			fail("Test 4: No exception should have been thrown: " + e
-					+ " in test_" + desc);
-		}
+		defl.needsInput();
+		defl.setStrategy(1);
+		defl.setLevel(1);
+		defl.end();
 
 		// Methods where exceptions should be thrown
 		String vendor = System.getProperty("java.vendor");



Mime
View raw message