Archive tests - change some assertTrues to assertEquals where more appropriate
git-svn-id: https://svn.apache.org/repos/asf/harmony/enhanced/java/trunk@1027985 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java b/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java
index 8b4a0a9..549213e 100644
--- a/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java
+++ b/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarFileTest.java
@@ -367,9 +367,10 @@
// try to read class file header
is.read(b, 0, 1024);
jf.close();
- assertTrue("Invalid bytes were red", b[0] == (byte) 0xCA
- && b[1] == (byte) 0xFE && b[2] == (byte) 0xBA
- && b[3] == (byte) 0xBE);
+ assertEquals("Invalid bytes were read", (byte) 0xCA, b[0]);
+ assertEquals("Invalid bytes were read", (byte) 0xFE, b[1]);
+ assertEquals("Invalid bytes were read", (byte) 0xBA, b[2]);
+ assertEquals("Invalid bytes were read", (byte) 0xBE, b[3]);
}
/**
diff --git a/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java b/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java
index 46880e3..31349f5 100644
--- a/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java
+++ b/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java
@@ -142,9 +142,9 @@
"the checkSum value of the compressed and decompressed data does not equal",
2074883667L, inGZIP.getChecksum().getValue());
for (int i = 0; i < orgBuf.length; i++) {
- assertTrue(
+ assertEquals(
"the decompressed data does not equal the original data decompressed",
- orgBuf[i] == outBuf[i]);
+ orgBuf[i], outBuf[i]);
// System.out.println(orgBuf[i] + " " + outBuf[i]);
}
int r = 0;
@@ -180,7 +180,7 @@
}
assertEquals("Should return -1", -1, gin2.read());
gin2.close();
- assertTrue("Incorrectly decompressed", total == test.length);
+ assertEquals("Incorrectly decompressed", test.length, total);
gin2 = new GZIPInputStream(new ByteArrayInputStream(comp), 512);
total = 0;
@@ -189,7 +189,7 @@
}
assertEquals("Should return -1", -1, gin2.read());
gin2.close();
- assertTrue("Incorrectly decompressed", total == test.length);
+ assertEquals("Incorrectly decompressed", test.length, total);
gin2 = new GZIPInputStream(new ByteArrayInputStream(comp), 516);
total = 0;
@@ -198,7 +198,7 @@
}
assertEquals("Should return -1", -1, gin2.read());
gin2.close();
- assertTrue("Incorrectly decompressed", total == test.length);
+ assertEquals("Incorrectly decompressed", test.length, total);
comp[40] = 0;
gin2 = new GZIPInputStream(new ByteArrayInputStream(comp), 512);
diff --git a/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java b/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java
index 336e7ab..98419ff 100644
--- a/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java
+++ b/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java
@@ -184,9 +184,9 @@
inflatIP.close();
for (int j = 0; j < orgBuffer.length; j++) {
- assertTrue(
+ assertEquals(
"original compressed data did not equal decompressed data",
- buffer[j] == orgBuffer[j]);
+ orgBuffer[j], buffer[j]);
}
}
@@ -433,9 +433,9 @@
inflatIP2.close();
for (int j = 2; j < orgBuffer.length; j++) {
- assertTrue(
+ assertEquals(
"original compressed data did not equal decompressed data",
- buffer[j - 2] == orgBuffer[j]);
+ orgBuffer[j], buffer[j - 2]);
}
}
diff --git a/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java b/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java
index c6364f9..e80b41b 100644
--- a/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java
+++ b/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java
@@ -83,9 +83,9 @@
fail("Invalid input to be decompressed");
}
for (int i = 0; i < byteArray.length; i++) {
- assertTrue(
+ assertEquals(
"Final decompressed data does not equal the original data",
- byteArray[i] == outPutInf[i]);
+ outPutInf[i], byteArray[i]);
}
assertEquals("final decompressed data contained more bytes than original - finished()",
0, outPutInf[byteArray.length]);
@@ -105,9 +105,9 @@
Adler32 adl = new Adler32();
adl.update(dictionaryArray);
long checkSumR = adl.getValue();
- assertTrue(
+ assertEquals(
"the checksum value returned by getAdler() is not the same as the checksum returned by creating the adler32 instance",
- checkSumR == inflateDiction.getAdler());
+ inflateDiction.getAdler(), checkSumR);
}
}
@@ -159,9 +159,9 @@
fail("Input to inflate is invalid or corrupted - getTotalIn");
}
// System.out.print(deflate.getTotalOut() + " " + inflate.getTotalIn());
- assertTrue(
+ assertEquals(
"the total byte in outPutBuf did not equal the byte returned in getTotalIn",
- inflate.getTotalIn() == deflate.getTotalOut());
+ deflate.getTotalOut(), inflate.getTotalIn());
Inflater inflate2 = new Inflater();
int offSet = 0;// seems only can start as 0
@@ -178,9 +178,9 @@
fail("Input to inflate is invalid or corrupted - getTotalIn");
}
// System.out.print(inflate2.getTotalIn() + " " + length);
- assertTrue(
+ assertEquals(
"total byte dictated by length did not equal byte returned in getTotalIn",
- inflate2.getTotalIn() == length);
+ length, inflate2.getTotalIn());
}
/**
@@ -217,12 +217,12 @@
fail("Input to inflate is invalid or corrupted - getTotalIn");
}
- assertTrue(
+ assertEquals(
"the sum of the bytes returned from inflate does not equal the bytes of getTotalOut()",
- y == inflate.getTotalOut());
- assertTrue(
+ inflate.getTotalOut(), y);
+ assertEquals(
"the total number of bytes to be compressed does not equal the total bytes decompressed",
- inflate.getTotalOut() == deflate.getTotalIn());
+ deflate.getTotalIn(), inflate.getTotalOut());
// testing inflate(byte,int,int)
inflate.reset();
@@ -241,12 +241,12 @@
System.out
.println("Input to inflate is invalid or corrupted - getTotalIn");
}
- assertTrue(
+ assertEquals(
"the sum of the bytes returned from inflate does not equal the bytes of getTotalOut()",
- y == inflate.getTotalOut());
- assertTrue(
+ y, inflate.getTotalOut());
+ assertEquals(
"the total number of bytes to be compressed does not equal the total bytes decompressed",
- inflate.getTotalOut() == deflate.getTotalIn());
+ deflate.getTotalIn(), inflate.getTotalOut());
}
/**
@@ -269,9 +269,9 @@
fail("Invalid input to be decompressed");
}
for (int i = 0; i < byteArray.length; i++) {
- assertTrue(
+ assertEquals(
"Final decompressed data does not equal the original data",
- byteArray[i] == outPutInf[i]);
+ byteArray[i], outPutInf[i]);
}
assertEquals("final decompressed data contained more bytes than original - inflateB",
0, outPutInf[byteArray.length]);
@@ -288,12 +288,12 @@
while (!(defEmpty.finished())) {
x += defEmpty.deflate(outPutBuf, x, outPutBuf.length - x);
}
- assertTrue(
+ assertEquals(
"the total number of byte from deflate did not equal getTotalOut - inflate(byte)",
- x == defEmpty.getTotalOut());
- assertTrue(
+ x, defEmpty.getTotalOut());
+ assertEquals(
"the number of input byte from the array did not correspond with getTotalIn - inflate(byte)",
- defEmpty.getTotalIn() == emptyArray.length);
+ emptyArray.length, defEmpty.getTotalIn());
Inflater infEmpty = new Inflater();
try {
while (!(infEmpty.finished())) {
@@ -306,9 +306,9 @@
fail("Invalid input to be decompressed");
}
for (int i = 0; i < emptyArray.length; i++) {
- assertTrue(
+ assertEquals(
"Final decompressed data does not equal the original data",
- emptyArray[i] == outPutInf[i]);
+ emptyArray[i], outPutInf[i]);
assertEquals("Final decompressed data does not equal zero",
0, outPutInf[i]);
}
@@ -373,9 +373,9 @@
fail("Invalid input to be decompressed");
}
for (int i = 0; i < byteArray.length; i++) {
- assertTrue(
+ assertEquals(
"Final decompressed data does not equal the original data",
- byteArray[i] == outPutInf[i]);
+ byteArray[i], outPutInf[i]);
}
assertEquals("final decompressed data contained more bytes than original - inflateB",
0, outPutInf[byteArray.length]);
@@ -603,9 +603,9 @@
fail("Invalid input to be decompressed");
}
for (int i = 0; i < byteArray.length; i++) {
- assertTrue(
+ assertEquals(
"Final decompressed data does not equal the original data",
- byteArray[i] == outPutInf[i]);
+ byteArray[i], outPutInf[i]);
}
assertEquals("final decompressed data contained more bytes than original - reset",
0, outPutInf[byteArray.length]);
@@ -625,9 +625,9 @@
fail("Invalid input to be decompressed");
}
for (int i = 0; i < byteArray.length; i++) {
- assertTrue(
+ assertEquals(
"Final decompressed data does not equal the original data",
- byteArray[i] == outPutInf[i]);
+ byteArray[i], outPutInf[i]);
}
assertEquals("final decompressed data contained more bytes than original - reset",
0, outPutInf[byteArray.length]);
@@ -711,9 +711,9 @@
int length = 6;
Inflater inflate = new Inflater();
inflate.setInput(byteArray, offSet, length);
- assertTrue(
+ assertEquals(
"setInputBII did not deliver the right number of bytes to the input buffer",
- inflate.getRemaining() == length);
+ length, inflate.getRemaining());
// boundary check
inflate.reset();
int r = 0;
diff --git a/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipEntryTest.java b/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipEntryTest.java
index be5d0c6..5a94df5 100644
--- a/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipEntryTest.java
+++ b/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipEntryTest.java
@@ -120,7 +120,7 @@
*/
public void test_getCrc() {
// Test for method long java.util.zip.ZipEntry.getCrc()
- assertTrue("Failed to get Crc", zentry.getCrc() == orgCrc);
+ assertEquals("Failed to get Crc", orgCrc, zentry.getCrc());
}
/**
@@ -133,8 +133,8 @@
byte[] ba = { 'T', 'E', 'S', 'T' };
zentry = new ZipEntry("test.tst");
zentry.setExtra(ba);
- assertTrue("Incorrect Extra Information Returned.",
- zentry.getExtra() == ba);
+ assertEquals("Incorrect Extra Information Returned.",
+ ba, zentry.getExtra());
}
/**
@@ -143,11 +143,11 @@
public void test_getMethod() {
// Test for method int java.util.zip.ZipEntry.getMethod()
zentry = zfile.getEntry("File1.txt");
- assertTrue("Incorrect compression method returned",
- zentry.getMethod() == java.util.zip.ZipEntry.STORED);
+ assertEquals("Incorrect compression method returned",
+ java.util.zip.ZipEntry.STORED, zentry.getMethod());
zentry = zfile.getEntry("File3.txt");
- assertTrue("Incorrect compression method returned",
- zentry.getMethod() == java.util.zip.ZipEntry.DEFLATED);
+ assertEquals("Incorrect compression method returned",
+ java.util.zip.ZipEntry.DEFLATED, zentry.getMethod());
zentry = new ZipEntry("test.tst");
assertEquals("Incorrect Method Returned.", -1, zentry.getMethod());
}
@@ -166,7 +166,7 @@
*/
public void test_getSize() {
// Test for method long java.util.zip.ZipEntry.getSize()
- assertTrue("Incorrect size returned", zentry.getSize() == orgSize);
+ assertEquals("Incorrect size returned", orgSize, zentry.getSize());
}
/**
@@ -174,7 +174,7 @@
*/
public void test_getTime() {
// Test for method long java.util.zip.ZipEntry.getTime()
- assertTrue("Failed to get time", zentry.getTime() == orgTime);
+ assertEquals("Failed to get time", orgTime, zentry.getTime());
}
/**
@@ -225,8 +225,8 @@
public void test_setCompressedSizeJ() {
// Test for method void java.util.zip.ZipEntry.setCompressedSize(long)
zentry.setCompressedSize(orgCompressedSize + 10);
- assertTrue("Set compressed size failed",
- zentry.getCompressedSize() == (orgCompressedSize + 10));
+ assertEquals("Set compressed size failed",
+ (orgCompressedSize + 10), zentry.getCompressedSize());
zentry.setCompressedSize(0);
assertEquals("Set compressed size failed",
0, zentry.getCompressedSize());
@@ -234,8 +234,8 @@
assertEquals("Set compressed size failed",
-25, zentry.getCompressedSize());
zentry.setCompressedSize(4294967296l);
- assertTrue("Set compressed size failed",
- zentry.getCompressedSize() == 4294967296l);
+ assertEquals("Set compressed size failed",
+ 4294967296l, zentry.getCompressedSize());
}
/**
@@ -244,7 +244,7 @@
public void test_setCrcJ() {
// Test for method void java.util.zip.ZipEntry.setCrc(long)
zentry.setCrc(orgCrc + 100);
- assertTrue("Failed to set Crc", zentry.getCrc() == (orgCrc + 100));
+ assertEquals("Failed to set Crc", (orgCrc + 100), zentry.getCrc());
zentry.setCrc(0);
assertEquals("Failed to set Crc", 0, zentry.getCrc());
try {
@@ -311,11 +311,11 @@
// Test for method void java.util.zip.ZipEntry.setMethod(int)
zentry = zfile.getEntry("File3.txt");
zentry.setMethod(ZipEntry.STORED);
- assertTrue("Failed to set compression method",
- zentry.getMethod() == ZipEntry.STORED);
+ assertEquals("Failed to set compression method",
+ ZipEntry.STORED, zentry.getMethod());
zentry.setMethod(ZipEntry.DEFLATED);
- assertTrue("Failed to set compression method",
- zentry.getMethod() == ZipEntry.DEFLATED);
+ assertEquals("Failed to set compression method",
+ ZipEntry.DEFLATED, zentry.getMethod());
try {
int error = 1;
zentry = new ZipEntry("test.tst");
@@ -331,7 +331,7 @@
public void test_setSizeJ() {
// Test for method void java.util.zip.ZipEntry.setSize(long)
zentry.setSize(orgSize + 10);
- assertTrue("Set size failed", zentry.getSize() == (orgSize + 10));
+ assertEquals("Set size failed", (orgSize + 10), zentry.getSize());
zentry.setSize(0);
assertEquals("Set size failed", 0, zentry.getSize());
try {
@@ -357,31 +357,31 @@
public void test_setTimeJ() {
// Test for method void java.util.zip.ZipEntry.setTime(long)
zentry.setTime(orgTime + 10000);
- assertTrue("Test 1: Failed to set time: " + zentry.getTime(), zentry
- .getTime() == (orgTime + 10000));
+ assertEquals("Test 1: Failed to set time: " + zentry.getTime(), (orgTime + 10000),
+ zentry.getTime());
zentry.setTime(orgTime - 10000);
- assertTrue("Test 2: Failed to set time: " + zentry.getTime(), zentry
- .getTime() == (orgTime - 10000));
+ assertEquals("Test 2: Failed to set time: " + zentry.getTime(), (orgTime - 10000),
+ zentry.getTime());
TimeZone zone = TimeZone.getDefault();
try {
TimeZone.setDefault(TimeZone.getTimeZone("EST"));
zentry.setTime(0);
- assertTrue("Test 3: Failed to set time: " + zentry.getTime(),
- zentry.getTime() == 315550800000L);
+ assertEquals("Test 3: Failed to set time: " + zentry.getTime(),
+ 315550800000L, zentry.getTime());
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
- assertTrue("Test 3a: Failed to set time: " + zentry.getTime(),
- zentry.getTime() == 315532800000L);
+ assertEquals("Test 3a: Failed to set time: " + zentry.getTime(),
+ 315532800000L, zentry.getTime());
zentry.setTime(0);
TimeZone.setDefault(TimeZone.getTimeZone("EST"));
- assertTrue("Test 3b: Failed to set time: " + zentry.getTime(),
- zentry.getTime() == 315550800000L);
+ assertEquals("Test 3b: Failed to set time: " + zentry.getTime(),
+ 315550800000L, zentry.getTime());
zentry.setTime(-25);
- assertTrue("Test 4: Failed to set time: " + zentry.getTime(),
- zentry.getTime() == 315550800000L);
+ assertEquals("Test 4: Failed to set time: " + zentry.getTime(),
+ 315550800000L, zentry.getTime());
zentry.setTime(4354837200000L);
- assertTrue("Test 5: Failed to set time: " + zentry.getTime(),
- zentry.getTime() == 315550800000L);
+ assertEquals("Test 5: Failed to set time: " + zentry.getTime(),
+ 315550800000L, zentry.getTime());
} finally {
TimeZone.setDefault(zone);
}
@@ -411,10 +411,10 @@
.getCompressedSize());
assertEquals("ZipEntry Created With Incorrect Comment.", "Testing", zentry2
.getComment());
- assertTrue("ZipEntry Created With Incorrect Crc.",
- zentry2.getCrc() == orgCrc);
- assertTrue("ZipEntry Created With Incorrect Time.",
- zentry2.getTime() == orgTime);
+ assertEquals("ZipEntry Created With Incorrect Crc.",
+ orgCrc, zentry2.getCrc());
+ assertEquals("ZipEntry Created With Incorrect Time.",
+ orgTime, zentry2.getTime());
}
/**
@@ -423,8 +423,8 @@
public void test_clone() {
// Test for method java.util.zip.ZipEntry.clone()
Object obj = zentry.clone();
- assertTrue("toString()", obj.toString().equals(zentry.toString()));
- assertTrue("hashCode()", obj.hashCode() == zentry.hashCode());
+ assertEquals("toString()", zentry.toString(), obj.toString());
+ assertEquals("hashCode()", zentry.hashCode(), obj.hashCode());
// One constructor
ZipEntry zeInput = new ZipEntry("InputZIP");
diff --git a/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipFileTest.java b/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipFileTest.java
index 08f2472..ff0d8dc 100644
--- a/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipFileTest.java
+++ b/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipFileTest.java
@@ -155,7 +155,7 @@
++c;
enumer.nextElement();
}
- assertTrue("Incorrect number of entries returned: " + c, c == 6);
+ assertEquals("Incorrect number of entries returned: " + c, 6, c);
Enumeration<? extends ZipEntry> enumeration = zfile.entries();
zfile.close();
@@ -255,8 +255,8 @@
*/
public void test_getName() {
// Test for method java.lang.String java.util.zip.ZipFile.getName()
- assertTrue("Returned incorrect name: " + zfile.getName(), zfile
- .getName().equals(tempFileName));
+ assertEquals("Returned incorrect name: " + zfile.getName(), tempFileName,
+ zfile.getName());
}
/**
diff --git a/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java b/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java
index 2efe8ae..32e6d8e 100644
--- a/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java
+++ b/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java
@@ -191,7 +191,7 @@
zentry = zis.getNextEntry();
zentry = zis.getNextEntry();
long s = zis.skip(1025);
- assertTrue("invalid skip: " + s, s == 1025);
+ assertEquals("invalid skip: " + s, 1025, s);
ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(zipBytes));
zis.getNextEntry();
diff --git a/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java b/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java
index 7adfeff..31c6766 100644
--- a/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java
+++ b/classlib/modules/archive/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java
@@ -109,9 +109,8 @@
zis = new ZipInputStream(new ByteArrayInputStream(bos.toByteArray()));
ZipEntry ze2 = zis.getNextEntry();
zis.closeEntry();
- assertTrue("Failed to write correct entry", ze.getName().equals(
- ze2.getName())
- && ze.getCrc() == ze2.getCrc());
+ assertEquals("Failed to write correct entry", ze.getName(), ze2.getName());
+ assertEquals("Failed to write correct entry", ze.getCrc(), ze2.getCrc());
try {
zos.putNextEntry(ze);
fail("Entry with incorrect setting failed to throw exception");
@@ -192,8 +191,7 @@
count += r;
}
zis.closeEntry();
- assertTrue("Write failed to write correct bytes", new String(b)
- .equals(data));
+ assertEquals("Write failed to write correct bytes", new String(b), data);
File f = File.createTempFile("testZip", "tst");
f.deleteOnExit();