Replaced assertTrue(Arrays.equals()) with assertArrayEquals().

This commit is contained in:
akwizgran
2011-10-05 17:07:52 +01:00
parent c054e1c00e
commit 8940dc83cb
11 changed files with 41 additions and 37 deletions

View File

@@ -1,11 +1,12 @@
package net.sf.briar;
import static org.junit.Assert.assertArrayEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.KeyPair;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collection;
import java.util.Collections;
@@ -249,6 +250,6 @@ public class ProtocolIntegrationTest extends TestCase {
assertEquals(m1.getGroup(), m2.getGroup());
assertEquals(m1.getAuthor(), m2.getAuthor());
assertEquals(m1.getTimestamp(), m2.getTimestamp());
assertTrue(Arrays.equals(m1.getBytes(), m2.getBytes()));
assertArrayEquals(m1.getBytes(), m2.getBytes());
}
}

View File

@@ -1,6 +1,7 @@
package net.sf.briar.crypto;
import java.util.Arrays;
import static org.junit.Assert.assertArrayEquals;
import java.util.Random;
import junit.framework.TestCase;
@@ -16,10 +17,10 @@ public class SharedSecretTest extends TestCase {
random.nextBytes(secret);
secret[SharedSecret.IV_BYTES] = (byte) 0;
SharedSecret s = new SharedSecret(secret);
assertTrue(Arrays.equals(secret, s.getBytes()));
assertArrayEquals(secret, s.getBytes());
secret[SharedSecret.IV_BYTES] = (byte) 1;
s = new SharedSecret(secret);
assertTrue(Arrays.equals(secret, s.getBytes()));
assertArrayEquals(secret, s.getBytes());
// The Alice flag must be either 0 or 1
secret[SharedSecret.IV_BYTES] = (byte) 2;
try {

View File

@@ -1,8 +1,9 @@
package net.sf.briar.db;
import static org.junit.Assert.assertArrayEquals;
import java.io.File;
import java.sql.Connection;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@@ -135,10 +136,10 @@ public class H2DatabaseTest extends TestCase {
assertTrue(db.containsSubscription(txn, groupId));
assertTrue(db.containsMessage(txn, messageId));
byte[] raw1 = db.getMessage(txn, messageId);
assertTrue(Arrays.equals(raw, raw1));
assertArrayEquals(raw, raw1);
assertTrue(db.containsMessage(txn, privateMessageId));
raw1 = db.getMessage(txn, privateMessageId);
assertTrue(Arrays.equals(raw, raw1));
assertArrayEquals(raw, raw1);
// Delete the records
db.removeMessage(txn, messageId);
db.removeMessage(txn, privateMessageId);
@@ -1242,7 +1243,7 @@ public class H2DatabaseTest extends TestCase {
// The message is sendable so it should be returned
byte[] b = db.getMessageIfSendable(txn, contactId, messageId);
assertTrue(Arrays.equals(raw, b));
assertArrayEquals(raw, b);
db.commitTransaction(txn);
db.close();

View File

@@ -1,7 +1,8 @@
package net.sf.briar.protocol;
import static org.junit.Assert.assertArrayEquals;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.Random;
import junit.framework.TestCase;
@@ -41,7 +42,7 @@ public class ConsumersTest extends TestCase {
dc.write(data, 1, data.length - 2);
dc.write(data[data.length - 1]);
byte[] dig1 = messageDigest.digest();
assertTrue(Arrays.equals(dig, dig1));
assertArrayEquals(dig, dig1);
}
@Test
@@ -67,6 +68,6 @@ public class ConsumersTest extends TestCase {
cc.write(data[0]);
cc.write(data, 1, data.length - 2);
cc.write(data[data.length - 1]);
assertTrue(Arrays.equals(data, cc.getCopy()));
assertArrayEquals(data, cc.getCopy());
}
}

View File

@@ -1,9 +1,10 @@
package net.sf.briar.serial;
import static org.junit.Assert.assertArrayEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -146,17 +147,17 @@ public class ReaderImplTest extends TestCase {
@Test
public void testReadBytes() throws Exception {
setContents("F603010203" + "93010203" + "F600" + "90");
assertTrue(Arrays.equals(new byte[] {1, 2, 3}, r.readBytes()));
assertTrue(Arrays.equals(new byte[] {1, 2, 3}, r.readBytes()));
assertTrue(Arrays.equals(new byte[] {}, r.readBytes()));
assertTrue(Arrays.equals(new byte[] {}, r.readBytes()));
assertArrayEquals(new byte[] {1, 2, 3}, r.readBytes());
assertArrayEquals(new byte[] {1, 2, 3}, r.readBytes());
assertArrayEquals(new byte[] {}, r.readBytes());
assertArrayEquals(new byte[] {}, r.readBytes());
assertTrue(r.eof());
}
@Test
public void testReadBytesMaxLength() throws Exception {
setContents("93010203" + "93010203");
assertTrue(Arrays.equals(new byte[] {1, 2, 3}, r.readBytes(3)));
assertArrayEquals(new byte[] {1, 2, 3}, r.readBytes(3));
try {
r.readBytes(2);
fail();
@@ -328,7 +329,7 @@ public class ReaderImplTest extends TestCase {
assertFalse(r.hasMapEnd());
assertEquals((byte) 123, r.readIntAny());
assertFalse(r.hasMapEnd());
assertTrue(Arrays.equals(new byte[] {}, r.readBytes()));
assertArrayEquals(new byte[] {}, r.readBytes());
assertFalse(r.hasMapEnd());
assertTrue(r.hasNull());
r.readNull();

View File

@@ -1,9 +1,9 @@
package net.sf.briar.transport;
import static net.sf.briar.api.transport.TransportConstants.IV_LENGTH;
import static org.junit.Assert.assertArrayEquals;
import java.io.ByteArrayInputStream;
import java.util.Arrays;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
@@ -107,6 +107,6 @@ public class ConnectionDecrypterImplTest extends TestCase {
out.write(decrypted1);
out.write(decryptedMac1);
byte[] actual = out.toByteArray();
assertTrue(Arrays.equals(expected, actual));
assertArrayEquals(expected, actual);
}
}

View File

@@ -1,9 +1,9 @@
package net.sf.briar.transport;
import static net.sf.briar.api.transport.TransportConstants.IV_LENGTH;
import static org.junit.Assert.assertArrayEquals;
import java.io.ByteArrayOutputStream;
import java.util.Arrays;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
@@ -91,7 +91,7 @@ public class ConnectionEncrypterImplTest extends TestCase {
e.writeMac(plaintextMac);
byte[] actual = out.toByteArray();
// Check that the actual ciphertext matches the expected ciphertext
assertTrue(Arrays.equals(expected, actual));
assertArrayEquals(expected, actual);
assertEquals(Long.MAX_VALUE - actual.length, e.getRemainingCapacity());
}
}

View File

@@ -1,9 +1,9 @@
package net.sf.briar.transport;
import static net.sf.briar.api.transport.TransportConstants.MAX_FRAME_LENGTH;
import static org.junit.Assert.assertArrayEquals;
import java.io.ByteArrayInputStream;
import java.util.Arrays;
import net.sf.briar.TestUtils;
import net.sf.briar.api.FormatException;
@@ -142,10 +142,10 @@ public class ConnectionReaderImplTest extends TransportTest {
ConnectionReader r = new ConnectionReaderImpl(d, mac, macKey);
byte[] read = new byte[123];
TestUtils.readFully(r.getInputStream(), read);
assertTrue(Arrays.equals(new byte[123], read));
assertArrayEquals(new byte[123], read);
byte[] read1 = new byte[1234];
TestUtils.readFully(r.getInputStream(), read1);
assertTrue(Arrays.equals(new byte[1234], read1));
assertArrayEquals(new byte[1234], read1);
}
@Test

View File

@@ -1,10 +1,10 @@
package net.sf.briar.transport;
import static net.sf.briar.api.transport.TransportConstants.MAX_FRAME_LENGTH;
import static org.junit.Assert.assertArrayEquals;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.util.Arrays;
import net.sf.briar.api.transport.ConnectionWriter;
@@ -42,7 +42,7 @@ public class ConnectionWriterImplTest extends TransportTest {
ConnectionWriter w = new ConnectionWriterImpl(e, mac, macKey);
w.getOutputStream().write(0);
w.getOutputStream().flush();
assertTrue(Arrays.equals(frame, out.toByteArray()));
assertArrayEquals(frame, out.toByteArray());
}
@Test
@@ -100,6 +100,6 @@ public class ConnectionWriterImplTest extends TransportTest {
w.getOutputStream().write(new byte[1234]);
w.getOutputStream().flush();
byte[] actual = out.toByteArray();
assertTrue(Arrays.equals(expected, actual));
assertArrayEquals(expected, actual);
}
}

View File

@@ -1,12 +1,12 @@
package net.sf.briar.transport;
import static net.sf.briar.api.transport.TransportConstants.IV_LENGTH;
import static org.junit.Assert.assertArrayEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Random;
import javax.crypto.Cipher;
@@ -86,7 +86,7 @@ public class FrameReadWriteTest extends TestCase {
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
byte[] recoveredIv = new byte[IV_LENGTH];
assertEquals(IV_LENGTH, in.read(recoveredIv));
assertTrue(Arrays.equals(encryptedIv, recoveredIv));
assertArrayEquals(encryptedIv, recoveredIv);
// Read the frames back
ConnectionDecrypter decrypter = new ConnectionDecrypterImpl(in,
recoveredIv, ivCipher, frameCipher, ivKey, frameKey);
@@ -101,7 +101,7 @@ public class FrameReadWriteTest extends TestCase {
offset += read;
}
assertEquals(recovered.length, offset);
assertTrue(Arrays.equals(frame, recovered));
assertArrayEquals(frame, recovered);
byte[] recovered1 = new byte[frame1.length];
offset = 0;
while(offset < recovered1.length) {
@@ -110,6 +110,6 @@ public class FrameReadWriteTest extends TestCase {
offset += read;
}
assertEquals(recovered1.length, offset);
assertTrue(Arrays.equals(frame1, recovered1));
assertArrayEquals(frame1, recovered1);
}
}

View File

@@ -1,7 +1,6 @@
package net.sf.briar.util;
import java.util.Arrays;
import static org.junit.Assert.assertArrayEquals;
import junit.framework.TestCase;
import org.junit.Test;
@@ -38,8 +37,8 @@ public class StringUtilsTest extends TestCase {
fail();
} catch(IllegalArgumentException expected) {}
byte[] b = StringUtils.fromHexString("0102037F80");
assertTrue(Arrays.equals(new byte[] {1, 2, 3, 127, -128}, b));
assertArrayEquals(new byte[] {1, 2, 3, 127, -128}, b);
b = StringUtils.fromHexString("0a0b0c0d0e0f");
assertTrue(Arrays.equals(new byte[] {10, 11, 12, 13, 14, 15}, b));
assertArrayEquals(new byte[] {10, 11, 12, 13, 14, 15}, b);
}
}