Whitespace-only code formatting changes.

This commit is contained in:
akwizgran
2015-11-30 09:38:25 +00:00
parent 1950c13ffb
commit 027ae8340f
202 changed files with 2993 additions and 2993 deletions

View File

@@ -34,7 +34,7 @@ public class LockFairnessTest extends BriarTestCase {
// Release the lock
lock.readLock().unlock();
}
} catch(InterruptedException e) {
} catch (InterruptedException e) {
fail();
}
firstReaderHasFinished.countDown();
@@ -57,7 +57,7 @@ public class LockFairnessTest extends BriarTestCase {
// Release the lock
lock.readLock().unlock();
}
} catch(InterruptedException e) {
} catch (InterruptedException e) {
fail();
}
secondReaderHasFinished.countDown();
@@ -90,7 +90,7 @@ public class LockFairnessTest extends BriarTestCase {
// Allow the other threads to acquire the lock
firstReaderHasLock.countDown();
// Wait for both other threads to wait for the lock
while(lock.getQueueLength() < 2) Thread.sleep(10);
while (lock.getQueueLength() < 2) Thread.sleep(10);
// No other thread should have acquired the lock
assertFalse(secondReaderHasHeldLock.get());
assertFalse(writerHasHeldLock.get());
@@ -98,7 +98,7 @@ public class LockFairnessTest extends BriarTestCase {
// Release the lock
lock.readLock().unlock();
}
} catch(InterruptedException e) {
} catch (InterruptedException e) {
fail();
}
firstReaderHasFinished.countDown();
@@ -121,7 +121,7 @@ public class LockFairnessTest extends BriarTestCase {
} finally {
lock.writeLock().unlock();
}
} catch(InterruptedException e) {
} catch (InterruptedException e) {
fail();
}
writerHasFinished.countDown();
@@ -136,7 +136,7 @@ public class LockFairnessTest extends BriarTestCase {
// Wait for the first reader to acquire the lock
assertTrue(firstReaderHasLock.await(10, SECONDS));
// Wait for the writer to wait for the lock
while(lock.getQueueLength() < 1) Thread.sleep(10);
while (lock.getQueueLength() < 1) Thread.sleep(10);
// Acquire the lock
lock.readLock().lock();
try {
@@ -146,7 +146,7 @@ public class LockFairnessTest extends BriarTestCase {
} finally {
lock.readLock().unlock();
}
} catch(InterruptedException e) {
} catch (InterruptedException e) {
fail();
}
secondReaderHasFinished.countDown();

View File

@@ -16,7 +16,7 @@ public class TestUtils {
private static final Random random = new Random();
public static void delete(File f) {
if(f.isDirectory()) for(File child : f.listFiles()) delete(child);
if (f.isDirectory()) for (File child : f.listFiles()) delete(child);
f.delete();
}
@@ -47,7 +47,7 @@ public class TestUtils {
public static String createRandomString(int length) {
char[] c = new char[length];
for(int i = 0; i < length; i++)
for (int i = 0; i < length; i++)
c[i] = (char) ('a' + random.nextInt(26));
return new String(c);
}

View File

@@ -40,13 +40,13 @@ public class EllipticCurvePerformanceTest {
"brainpoolp256r1", "brainpoolp384r1", "brainpoolp512r1");
public static void main(String[] args) {
for(String name : SEC_NAMES) {
for (String name : SEC_NAMES) {
ECDomainParameters params =
convertParams(SECNamedCurves.getByName(name));
runTest(name + " default", params);
runTest(name + " constant", constantTime(params));
}
for(String name : BRAINPOOL_NAMES) {
for (String name : BRAINPOOL_NAMES) {
ECDomainParameters params =
convertParams(TeleTrusTNamedCurves.getByName(name));
runTest(name + " default", params);
@@ -71,7 +71,7 @@ public class EllipticCurvePerformanceTest {
(ECPublicKeyParameters) keyPair2.getPublic();
// Time some ECDH key agreements
List<Long> samples = new ArrayList<Long>();
for(int i = 0; i < SAMPLES; i++) {
for (int i = 0; i < SAMPLES; i++) {
ECDHCBasicAgreement agreement = new ECDHCBasicAgreement();
long start = System.nanoTime();
agreement.init(private1);
@@ -82,7 +82,7 @@ public class EllipticCurvePerformanceTest {
// Time some signatures
List<byte[]> signatures = new ArrayList<byte[]>();
samples.clear();
for(int i = 0; i < SAMPLES; i++) {
for (int i = 0; i < SAMPLES; i++) {
Digest digest = new SHA256Digest();
DSAKCalculator calculator = new HMacDSAKCalculator(digest);
DSADigestSigner signer = new DSADigestSigner(new ECDSASigner(
@@ -96,7 +96,7 @@ public class EllipticCurvePerformanceTest {
long signatureMedian = median(samples);
// Time some signature verifications
samples.clear();
for(int i = 0; i < SAMPLES; i++) {
for (int i = 0; i < SAMPLES; i++) {
Digest digest = new SHA256Digest();
DSAKCalculator calculator = new HMacDSAKCalculator(digest);
DSADigestSigner signer = new DSADigestSigner(new ECDSASigner(
@@ -104,7 +104,7 @@ public class EllipticCurvePerformanceTest {
long start = System.nanoTime();
signer.init(false, public1);
signer.update(new byte[BYTES_TO_SIGN], 0, BYTES_TO_SIGN);
if(!signer.verifySignature(signatures.get(i)))
if (!signer.verifySignature(signatures.get(i)))
throw new AssertionError();
samples.add(System.nanoTime() - start);
}
@@ -117,9 +117,9 @@ public class EllipticCurvePerformanceTest {
private static long median(List<Long> list) {
int size = list.size();
if(size == 0) throw new IllegalArgumentException();
if (size == 0) throw new IllegalArgumentException();
Collections.sort(list);
if(size % 2 == 1) return list.get(size / 2);
if (size % 2 == 1) return list.get(size / 2);
return list.get(size / 2 - 1) + list.get(size / 2) / 2;
}

View File

@@ -23,7 +23,7 @@ public class FortunaGeneratorTest extends BriarTestCase {
public void testIncrementCounter() {
FortunaGenerator f = new FortunaGenerator(new byte[32]);
// Increment the counter until it reaches 255
for(int i = 1; i < 255; i++) f.incrementCounter();
for (int i = 1; i < 255; i++) f.incrementCounter();
byte[] expected = new byte[16];
expected[0] = (byte) 255;
assertArrayEquals(expected, f.getCounter());
@@ -33,7 +33,7 @@ public class FortunaGeneratorTest extends BriarTestCase {
expected[1] = 1;
assertArrayEquals(expected, f.getCounter());
// Increment the counter until it carries into the next byte
for(int i = 256; i < 65536; i++) f.incrementCounter();
for (int i = 256; i < 65536; i++) f.incrementCounter();
expected[0] = 0;
expected[1] = 0;
expected[2] = 1;
@@ -49,15 +49,15 @@ public class FortunaGeneratorTest extends BriarTestCase {
// One byte longer than a block, with an offset of one
byte[] out2 = new byte[49];
new FortunaGenerator(seed).nextBytes(out2, 1, 48);
for(int i = 0; i < 48; i++) assertEquals(out1[i], out2[i + 1]);
for (int i = 0; i < 48; i++) assertEquals(out1[i], out2[i + 1]);
// One byte shorter than a block
byte[] out3 = new byte[47];
new FortunaGenerator(seed).nextBytes(out3, 0, 47);
for(int i = 0; i < 47; i++) assertEquals(out1[i], out3[i]);
for (int i = 0; i < 47; i++) assertEquals(out1[i], out3[i]);
// Less than a block, with an offset greater than a block
byte[] out4 = new byte[32];
new FortunaGenerator(seed).nextBytes(out4, 17, 15);
for(int i = 0; i < 15; i++) assertEquals(out1[i], out4[i + 17]);
for (int i = 0; i < 15; i++) assertEquals(out1[i], out4[i + 17]);
}
@Test

View File

@@ -29,9 +29,9 @@ public class KeyDerivationTest extends BriarTestCase {
keys.add(crypto.deriveFrameKey(secret, 0, false));
keys.add(crypto.deriveTagKey(secret, true));
keys.add(crypto.deriveTagKey(secret, false));
for(int i = 0; i < 4; i++) {
for (int i = 0; i < 4; i++) {
byte[] keyI = keys.get(i).getBytes();
for(int j = 0; j < 4; j++) {
for (int j = 0; j < 4; j++) {
byte[] keyJ = keys.get(j).getBytes();
assertEquals(i == j, Arrays.equals(keyI, keyJ));
}
@@ -42,14 +42,14 @@ public class KeyDerivationTest extends BriarTestCase {
public void testSecretAffectsDerivation() {
Random r = new Random();
List<byte[]> secrets = new ArrayList<byte[]>();
for(int i = 0; i < 20; i++) {
for (int i = 0; i < 20; i++) {
byte[] b = new byte[32];
r.nextBytes(b);
secrets.add(crypto.deriveNextSecret(b, 0));
}
for(int i = 0; i < 20; i++) {
for (int i = 0; i < 20; i++) {
byte[] secretI = secrets.get(i);
for(int j = 0; j < 20; j++) {
for (int j = 0; j < 20; j++) {
byte[] secretJ = secrets.get(j);
assertEquals(i == j, Arrays.equals(secretI, secretJ));
}
@@ -59,11 +59,11 @@ public class KeyDerivationTest extends BriarTestCase {
@Test
public void testStreamNumberAffectsDerivation() {
List<byte[]> secrets = new ArrayList<byte[]>();
for(int i = 0; i < 20; i++)
for (int i = 0; i < 20; i++)
secrets.add(crypto.deriveNextSecret(secret, i));
for(int i = 0; i < 20; i++) {
for (int i = 0; i < 20; i++) {
byte[] secretI = secrets.get(i);
for(int j = 0; j < 20; j++) {
for (int j = 0; j < 20; j++) {
byte[] secretJ = secrets.get(j);
assertEquals(i == j, Arrays.equals(secretI, secretJ));
}

View File

@@ -63,19 +63,19 @@ public class KeyEncodingAndParsingTest extends BriarTestCase {
Random random = new Random();
byte[] pubFuzz = new byte[pubLength];
byte[] privFuzz = new byte[privLength];
for(int i = 0; i < 1000; i++) {
for (int i = 0; i < 1000; i++) {
random.nextBytes(pubFuzz);
try {
parser.parsePublicKey(pubFuzz);
} catch(GeneralSecurityException expected) {
} catch(Exception e) {
} catch (GeneralSecurityException expected) {
} catch (Exception e) {
fail();
}
random.nextBytes(privFuzz);
try {
parser.parsePrivateKey(privFuzz);
} catch(GeneralSecurityException expected) {
} catch(Exception e) {
} catch (GeneralSecurityException expected) {
} catch (Exception e) {
fail();
}
}
@@ -126,19 +126,19 @@ public class KeyEncodingAndParsingTest extends BriarTestCase {
Random random = new Random();
byte[] pubFuzz = new byte[pubLength];
byte[] privFuzz = new byte[privLength];
for(int i = 0; i < 1000; i++) {
for (int i = 0; i < 1000; i++) {
random.nextBytes(pubFuzz);
try {
parser.parsePublicKey(pubFuzz);
} catch(GeneralSecurityException expected) {
} catch(Exception e) {
} catch (GeneralSecurityException expected) {
} catch (Exception e) {
fail();
}
random.nextBytes(privFuzz);
try {
parser.parsePrivateKey(privFuzz);
} catch(GeneralSecurityException expected) {
} catch(Exception e) {
} catch (GeneralSecurityException expected) {
} catch (Exception e) {
fail();
}
}

View File

@@ -17,14 +17,14 @@ class TestAuthenticatedCipher implements AuthenticatedCipher {
public int process(byte[] input, int inputOff, int len, byte[] output,
int outputOff) throws GeneralSecurityException {
if(encrypt) {
if (encrypt) {
System.arraycopy(input, inputOff, output, outputOff, len);
for(int i = 0; i < MAC_LENGTH; i++)
for (int i = 0; i < MAC_LENGTH; i++)
output[outputOff + len + i] = 0;
return len + MAC_LENGTH;
} else {
for(int i = 0; i < MAC_LENGTH; i++)
if(input[inputOff + len - MAC_LENGTH + i] != 0)
for (int i = 0; i < MAC_LENGTH; i++)
if (input[inputOff + len - MAC_LENGTH + i] != 0)
throw new GeneralSecurityException();
System.arraycopy(input, inputOff, output, outputOff,
len - MAC_LENGTH);

View File

@@ -131,39 +131,39 @@ public class ReaderImplTest extends BriarTestCase {
try {
r.readInteger();
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
setContents("21" + "80" + "22" + "FF80");
assertEquals(Byte.MIN_VALUE, r.readInteger());
try {
r.readInteger();
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
// INTEGER_32 could be encoded as INTEGER_16
setContents("22" + "7FFF" + "24" + "00007FFF");
assertEquals(Short.MAX_VALUE, r.readInteger());
try {
r.readInteger();
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
setContents("22" + "8000" + "24" + "FFFF8000");
assertEquals(Short.MIN_VALUE, r.readInteger());
try {
r.readInteger();
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
// INTEGER_64 could be encoded as INTEGER_32
setContents("24" + "7FFFFFFF" + "28" + "000000007FFFFFFF");
assertEquals(Integer.MAX_VALUE, r.readInteger());
try {
r.readInteger();
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
setContents("24" + "80000000" + "28" + "FFFFFFFF80000000");
assertEquals(Integer.MIN_VALUE, r.readInteger());
try {
r.readInteger();
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
}
@Test
@@ -214,7 +214,7 @@ public class ReaderImplTest extends BriarTestCase {
try {
r.readString(2);
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
}
@Test
@@ -254,7 +254,7 @@ public class ReaderImplTest extends BriarTestCase {
try {
r.readString(Byte.MAX_VALUE);
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
}
@Test
@@ -292,7 +292,7 @@ public class ReaderImplTest extends BriarTestCase {
try {
r.readString(Short.MAX_VALUE);
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
}
@Test
@@ -317,7 +317,7 @@ public class ReaderImplTest extends BriarTestCase {
try {
r.readString(Integer.MAX_VALUE);
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
// STRING_32 could be encoded as STRING_16
String longest16 = TestUtils.createRandomString(Short.MAX_VALUE);
String long16Hex = StringUtils.toHexString(longest16.getBytes("UTF-8"));
@@ -326,7 +326,7 @@ public class ReaderImplTest extends BriarTestCase {
try {
r.readString(Integer.MAX_VALUE);
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
}
@Test
@@ -351,7 +351,7 @@ public class ReaderImplTest extends BriarTestCase {
try {
r.readRaw(2);
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
}
@Test
@@ -391,7 +391,7 @@ public class ReaderImplTest extends BriarTestCase {
try {
r.readRaw(Byte.MAX_VALUE);
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
}
@Test
@@ -429,7 +429,7 @@ public class ReaderImplTest extends BriarTestCase {
try {
r.readRaw(Short.MAX_VALUE);
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
}
@Test
@@ -454,7 +454,7 @@ public class ReaderImplTest extends BriarTestCase {
try {
r.readRaw(Integer.MAX_VALUE);
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
// RAW_32 could be encoded as RAW_16
byte[] longest16 = new byte[Short.MAX_VALUE];
String long16Hex = StringUtils.toHexString(longest16);
@@ -463,7 +463,7 @@ public class ReaderImplTest extends BriarTestCase {
try {
r.readRaw(Integer.MAX_VALUE);
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
}
@Test

View File

@@ -146,7 +146,7 @@ public class WriterImplTest extends BriarTestCase {
@Test
public void testWriteList() throws IOException {
List<Object> l = new ArrayList<Object>();
for(int i = 0; i < 3; i++) l.add(i);
for (int i = 0; i < 3; i++) l.add(i);
w.writeList(l);
// LIST tag, elements as integers, END tag
checkContents("60" + "21" + "00" + "21" + "01" + "21" + "02" + "80");
@@ -167,7 +167,7 @@ public class WriterImplTest extends BriarTestCase {
public void testWriteMap() throws IOException {
// Use LinkedHashMap to get predictable iteration order
Map<String, Object> m = new LinkedHashMap<String, Object>();
for(int i = 0; i < 4; i++) m.put(String.valueOf(i), i);
for (int i = 0; i < 4; i++) m.put(String.valueOf(i), i);
w.writeMap(m);
// MAP tag, keys as strings and values as integers, END tag
checkContents("70" + "41" + "01" + "30" + "21" + "00" +

View File

@@ -74,7 +74,7 @@ public class BasicH2Test extends BriarTestCase {
String[] oldNames = new String[BATCH_SIZE];
String[] newNames = new String[BATCH_SIZE];
Random random = new Random();
for(int i = 0; i < BATCH_SIZE; i++) {
for (int i = 0; i < BATCH_SIZE; i++) {
random.nextBytes(ids[i]);
oldNames[i] = TestUtils.createRandomString(50);
newNames[i] = TestUtils.createRandomString(50);
@@ -84,20 +84,20 @@ public class BasicH2Test extends BriarTestCase {
// Update the names as a batch
updateBatch(ids, newNames);
// Check that the new names can be retrieved using the IDs
for(int i = 0; i < BATCH_SIZE; i++) {
for (int i = 0; i < BATCH_SIZE; i++) {
assertTrue(rowExists(ids[i]));
assertEquals(newNames[i], getName(ids[i]));
}
// Delete the rows as a batch
boolean[] deleted = deleteBatch(ids);
// Check that the rows no longer exist
for(int i = 0; i < BATCH_SIZE; i++) {
for (int i = 0; i < BATCH_SIZE; i++) {
assertTrue(deleted[i]);
assertFalse(rowExists(ids[i]));
}
// Deleting the rows again should have no effect
deleted = deleteBatch(ids);
for(int i = 0; i < BATCH_SIZE; i++) assertFalse(deleted[i]);
for (int i = 0; i < BATCH_SIZE; i++) assertFalse(deleted[i]);
}
@Test
@@ -146,7 +146,7 @@ public class BasicH2Test extends BriarTestCase {
Statement s = connection.createStatement();
s.executeUpdate(CREATE_TABLE);
s.close();
} catch(SQLException e) {
} catch (SQLException e) {
connection.close();
throw e;
}
@@ -156,13 +156,13 @@ public class BasicH2Test extends BriarTestCase {
String sql = "INSERT INTO foo (uniqueId, name) VALUES (?, ?)";
try {
PreparedStatement ps = connection.prepareStatement(sql);
if(id == null) ps.setNull(1, BINARY);
if (id == null) ps.setNull(1, BINARY);
else ps.setBytes(1, id);
ps.setString(2, name);
int affected = ps.executeUpdate();
assertEquals(1, affected);
ps.close();
} catch(SQLException e) {
} catch (SQLException e) {
connection.close();
throw e;
}
@@ -180,7 +180,7 @@ public class BasicH2Test extends BriarTestCase {
rs.close();
ps.close();
return found;
} catch(SQLException e) {
} catch (SQLException e) {
connection.close();
throw e;
}
@@ -199,7 +199,7 @@ public class BasicH2Test extends BriarTestCase {
rs.close();
ps.close();
return name;
} catch(SQLException e) {
} catch (SQLException e) {
connection.close();
throw e;
}
@@ -209,12 +209,12 @@ public class BasicH2Test extends BriarTestCase {
String sql = "UPDATE foo SET name = ? WHERE uniqueId = ?";
try {
PreparedStatement ps = connection.prepareStatement(sql);
if(id == null) ps.setNull(2, BINARY);
if (id == null) ps.setNull(2, BINARY);
else ps.setBytes(2, id);
ps.setString(1, name);
assertEquals(1, ps.executeUpdate());
ps.close();
} catch(SQLException e) {
} catch (SQLException e) {
connection.close();
throw e;
}
@@ -224,12 +224,12 @@ public class BasicH2Test extends BriarTestCase {
String sql = "DELETE FROM foo WHERE uniqueId = ?";
try {
PreparedStatement ps = connection.prepareStatement(sql);
if(id == null) ps.setNull(1, BINARY);
if (id == null) ps.setNull(1, BINARY);
else ps.setBytes(1, id);
int affected = ps.executeUpdate();
ps.close();
return affected == 1;
} catch(SQLException e) {
} catch (SQLException e) {
connection.close();
throw e;
}
@@ -240,19 +240,19 @@ public class BasicH2Test extends BriarTestCase {
String sql = "INSERT INTO foo (uniqueId, name) VALUES (?, ?)";
try {
PreparedStatement ps = connection.prepareStatement(sql);
for(int i = 0; i < ids.length; i++) {
if(ids[i] == null) ps.setNull(1, BINARY);
for (int i = 0; i < ids.length; i++) {
if (ids[i] == null) ps.setNull(1, BINARY);
else ps.setBytes(1, ids[i]);
ps.setString(2, names[i]);
ps.addBatch();
}
int[] batchAffected = ps.executeBatch();
assertEquals(ids.length, batchAffected.length);
for(int i = 0; i < batchAffected.length; i++) {
for (int i = 0; i < batchAffected.length; i++) {
assertEquals(1, batchAffected[i]);
}
ps.close();
} catch(SQLException e) {
} catch (SQLException e) {
connection.close();
throw e;
}
@@ -263,18 +263,18 @@ public class BasicH2Test extends BriarTestCase {
String sql = "UPDATE foo SET name = ? WHERE uniqueId = ?";
try {
PreparedStatement ps = connection.prepareStatement(sql);
for(int i = 0; i < ids.length; i++) {
if(ids[i] == null) ps.setNull(2, BINARY);
for (int i = 0; i < ids.length; i++) {
if (ids[i] == null) ps.setNull(2, BINARY);
else ps.setBytes(2, ids[i]);
ps.setString(1, names[i]);
ps.addBatch();
}
int[] batchAffected = ps.executeBatch();
assertEquals(ids.length, batchAffected.length);
for(int i = 0; i < batchAffected.length; i++)
for (int i = 0; i < batchAffected.length; i++)
assertEquals(1, batchAffected[i]);
ps.close();
} catch(SQLException e) {
} catch (SQLException e) {
connection.close();
throw e;
}
@@ -284,19 +284,19 @@ public class BasicH2Test extends BriarTestCase {
String sql = "DELETE FROM foo WHERE uniqueId = ?";
try {
PreparedStatement ps = connection.prepareStatement(sql);
for(int i = 0; i < ids.length; i++) {
if(ids[i] == null) ps.setNull(1, BINARY);
for (int i = 0; i < ids.length; i++) {
if (ids[i] == null) ps.setNull(1, BINARY);
else ps.setBytes(1, ids[i]);
ps.addBatch();
}
int[] batchAffected = ps.executeBatch();
assertEquals(ids.length, batchAffected.length);
boolean[] ret = new boolean[ids.length];
for(int i = 0; i < batchAffected.length; i++)
for (int i = 0; i < batchAffected.length; i++)
ret[i] = batchAffected[i] == 1;
ps.close();
return ret;
} catch(SQLException e) {
} catch (SQLException e) {
connection.close();
throw e;
}
@@ -315,7 +315,7 @@ public class BasicH2Test extends BriarTestCase {
rs.close();
ps.close();
return name;
} catch(SQLException e) {
} catch (SQLException e) {
connection.close();
throw e;
}
@@ -327,11 +327,11 @@ public class BasicH2Test extends BriarTestCase {
try {
PreparedStatement ps = connection.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while(rs.next()) names.add(rs.getString(1));
while (rs.next()) names.add(rs.getString(1));
rs.close();
ps.close();
return names;
} catch(SQLException e) {
} catch (SQLException e) {
connection.close();
throw e;
}
@@ -339,7 +339,7 @@ public class BasicH2Test extends BriarTestCase {
@After
public void tearDown() throws Exception {
if(connection != null) connection.close();
if (connection != null) connection.close();
TestUtils.deleteTestDirectory(testDir);
}
}

View File

@@ -39,7 +39,7 @@ public class DatabaseCleanerImplTest extends BriarTestCase {
// Start the cleaner - it should schedule itself with the timer
cleaner.startCleaning(callback, 10);
// Call the cleaner's run method six times
for(int i = 0; i < 6; i++) cleaner.run();
for (int i = 0; i < 6; i++) cleaner.run();
// Stop the cleaner - it should cancel the timer
cleaner.stopCleaning();
// The database should have been cleaned three times

View File

@@ -332,137 +332,137 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
try {
db.addEndpoint(endpoint);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
db.generateAck(contactId, 123);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
db.generateBatch(contactId, 123, 456);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
db.generateOffer(contactId, 123, 456);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
db.generateRetentionAck(contactId);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
db.generateRetentionUpdate(contactId, 123);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
db.generateSubscriptionAck(contactId);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
db.generateSubscriptionUpdate(contactId, 123);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
db.generateTransportAcks(contactId);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
db.generateTransportUpdates(contactId, 123);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
db.getContact(contactId);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
db.getInboxGroupId(contactId);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
db.incrementStreamCounter(contactId, transportId, 0);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
Ack a = new Ack(Arrays.asList(messageId));
db.receiveAck(contactId, a);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
db.receiveMessage(contactId, message);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
Offer o = new Offer(Arrays.asList(messageId));
db.receiveOffer(contactId, o);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
RetentionAck a = new RetentionAck(0);
db.receiveRetentionAck(contactId, a);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
RetentionUpdate u = new RetentionUpdate(0, 1);
db.receiveRetentionUpdate(contactId, u);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
SubscriptionAck a = new SubscriptionAck(0);
db.receiveSubscriptionAck(contactId, a);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
SubscriptionUpdate u = new SubscriptionUpdate(
Collections.<Group>emptyList(), 1);
db.receiveSubscriptionUpdate(contactId, u);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
TransportAck a = new TransportAck(transportId, 0);
db.receiveTransportAck(contactId, a);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
TransportUpdate u = new TransportUpdate(transportId,
transportProperties, 1);
db.receiveTransportUpdate(contactId, u);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
db.removeContact(contactId);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
db.setReorderingWindow(contactId, transportId, 0, 0, new byte[4]);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
try {
db.setInboxGroup(contactId, group);
fail();
} catch(NoSuchContactException expected) {}
} catch (NoSuchContactException expected) {}
context.assertIsSatisfied();
}
@@ -493,17 +493,17 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
try {
db.addContact(author, localAuthorId);
fail();
} catch(NoSuchLocalAuthorException expected) {}
} catch (NoSuchLocalAuthorException expected) {}
try {
db.getLocalAuthor(localAuthorId);
fail();
} catch(NoSuchLocalAuthorException expected) {}
} catch (NoSuchLocalAuthorException expected) {}
try {
db.removeLocalAuthor(localAuthorId);
fail();
} catch(NoSuchLocalAuthorException expected) {}
} catch (NoSuchLocalAuthorException expected) {}
context.assertIsSatisfied();
}
@@ -531,27 +531,27 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
try {
db.getGroup(groupId);
fail();
} catch(NoSuchSubscriptionException expected) {}
} catch (NoSuchSubscriptionException expected) {}
try {
db.getMessageHeaders(groupId);
fail();
} catch(NoSuchSubscriptionException expected) {}
} catch (NoSuchSubscriptionException expected) {}
try {
db.getVisibility(groupId);
fail();
} catch(NoSuchSubscriptionException expected) {}
} catch (NoSuchSubscriptionException expected) {}
try {
db.removeGroup(group);
fail();
} catch(NoSuchSubscriptionException expected) {}
} catch (NoSuchSubscriptionException expected) {}
try {
db.setVisibility(groupId, Collections.<ContactId>emptyList());
fail();
} catch(NoSuchSubscriptionException expected) {}
} catch (NoSuchSubscriptionException expected) {}
context.assertIsSatisfied();
}
@@ -603,42 +603,42 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
try {
db.addEndpoint(endpoint);
fail();
} catch(NoSuchTransportException expected) {}
} catch (NoSuchTransportException expected) {}
try {
db.getConfig(transportId);
fail();
} catch(NoSuchTransportException expected) {}
} catch (NoSuchTransportException expected) {}
try {
db.getLocalProperties(transportId);
fail();
} catch(NoSuchTransportException expected) {}
} catch (NoSuchTransportException expected) {}
try {
db.mergeConfig(transportId, new TransportConfig());
fail();
} catch(NoSuchTransportException expected) {}
} catch (NoSuchTransportException expected) {}
try {
db.mergeLocalProperties(transportId, new TransportProperties());
fail();
} catch(NoSuchTransportException expected) {}
} catch (NoSuchTransportException expected) {}
try {
db.incrementStreamCounter(contactId, transportId, 0);
fail();
} catch(NoSuchTransportException expected) {}
} catch (NoSuchTransportException expected) {}
try {
db.removeTransport(transportId);
fail();
} catch(NoSuchTransportException expected) {}
} catch (NoSuchTransportException expected) {}
try {
db.setReorderingWindow(contactId, transportId, 0, 0, new byte[4]);
fail();
} catch(NoSuchTransportException expected) {}
} catch (NoSuchTransportException expected) {}
context.assertIsSatisfied();
}

View File

@@ -418,7 +418,7 @@ public class H2DatabaseTest extends BriarTestCase {
// Allowing enough capacity for both messages should return both
Collection<MessageId> ids = new HashSet<MessageId>();
for(MessageId id : db.getOldMessages(txn, size * 2)) ids.add(id);
for (MessageId id : db.getOldMessages(txn, size * 2)) ids.add(id);
assertEquals(2, ids.size());
assertTrue(ids.contains(messageId));
assertTrue(ids.contains(messageId1));
@@ -430,7 +430,7 @@ public class H2DatabaseTest extends BriarTestCase {
@Test
public void testGetFreeSpace() throws Exception {
byte[] largeBody = new byte[ONE_MEGABYTE];
for(int i = 0; i < largeBody.length; i++) largeBody[i] = (byte) i;
for (int i = 0; i < largeBody.length; i++) largeBody[i] = (byte) i;
Message message = new TestMessage(messageId, null, group, author,
contentType, subject, timestamp, largeBody);
Database<Connection> db = open(false);
@@ -470,9 +470,9 @@ public class H2DatabaseTest extends BriarTestCase {
try {
closing.countDown();
db.close();
if(!transactionFinished.get()) error.set(true);
if (!transactionFinished.get()) error.set(true);
closed.countDown();
} catch(Exception e) {
} catch (Exception e) {
error.set(true);
}
}
@@ -507,9 +507,9 @@ public class H2DatabaseTest extends BriarTestCase {
try {
closing.countDown();
db.close();
if(!transactionFinished.get()) error.set(true);
if (!transactionFinished.get()) error.set(true);
closed.countDown();
} catch(Exception e) {
} catch (Exception e) {
error.set(true);
}
}
@@ -903,12 +903,12 @@ public class H2DatabaseTest extends BriarTestCase {
Collection<MessageHeader> headers = db.getMessageHeaders(txn, groupId);
assertEquals(2, headers.size());
boolean firstFound = false, secondFound = false;
for(MessageHeader header : headers) {
if(messageId.equals(header.getId())) {
for (MessageHeader header : headers) {
if (messageId.equals(header.getId())) {
assertHeadersMatch(message, header);
assertTrue(header.isRead());
firstFound = true;
} else if(messageId1.equals(header.getId())) {
} else if (messageId1.equals(header.getId())) {
assertHeadersMatch(message1, header);
assertFalse(header.isRead());
secondFound = true;
@@ -926,10 +926,10 @@ public class H2DatabaseTest extends BriarTestCase {
private void assertHeadersMatch(Message m, MessageHeader h) {
assertEquals(m.getId(), h.getId());
if(m.getParent() == null) assertNull(h.getParent());
if (m.getParent() == null) assertNull(h.getParent());
else assertEquals(m.getParent(), h.getParent());
assertEquals(m.getGroup().getId(), h.getGroupId());
if(m.getAuthor() == null) assertNull(h.getAuthor());
if (m.getAuthor() == null) assertNull(h.getAuthor());
else assertEquals(m.getAuthor(), h.getAuthor());
assertEquals(m.getContentType(), h.getContentType());
assertEquals(m.getTimestamp(), h.getTimestamp());
@@ -965,16 +965,16 @@ public class H2DatabaseTest extends BriarTestCase {
Collection<MessageHeader> headers = db.getMessageHeaders(txn, groupId);
assertEquals(3, headers.size());
boolean firstFound = false, secondFound = false, thirdFound = false;
for(MessageHeader header : headers) {
if(messageId.equals(header.getId())) {
for (MessageHeader header : headers) {
if (messageId.equals(header.getId())) {
assertHeadersMatch(message, header);
assertEquals(Author.Status.VERIFIED, header.getAuthorStatus());
firstFound = true;
} else if(messageId1.equals(header.getId())) {
} else if (messageId1.equals(header.getId())) {
assertHeadersMatch(message1, header);
assertEquals(Author.Status.UNKNOWN, header.getAuthorStatus());
secondFound = true;
} else if(messageId2.equals(header.getId())) {
} else if (messageId2.equals(header.getId())) {
assertHeadersMatch(message2, header);
assertEquals(Author.Status.ANONYMOUS, header.getAuthorStatus());
thirdFound = true;
@@ -1075,7 +1075,7 @@ public class H2DatabaseTest extends BriarTestCase {
public void testMultipleSubscriptionsAndUnsubscriptions() throws Exception {
// Create some groups
List<Group> groups = new ArrayList<Group>();
for(int i = 0; i < 100; i++) {
for (int i = 0; i < 100; i++) {
GroupId id = new GroupId(TestUtils.getRandomId());
String name = "Group " + i;
groups.add(new Group(id, name, new byte[GROUP_SALT_LENGTH]));
@@ -1087,16 +1087,16 @@ public class H2DatabaseTest extends BriarTestCase {
// Add a contact and subscribe to the groups
db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
for(Group g : groups) db.addGroup(txn, g);
for (Group g : groups) db.addGroup(txn, g);
// Make the groups visible to the contact
Collections.shuffle(groups);
for(Group g : groups) db.addVisibility(txn, contactId, g.getId());
for (Group g : groups) db.addVisibility(txn, contactId, g.getId());
// Make some of the groups invisible to the contact and remove them all
Collections.shuffle(groups);
for(Group g : groups) {
if(Math.random() < 0.5)
for (Group g : groups) {
if (Math.random() < 0.5)
db.removeVisibility(txn, contactId, g.getId());
db.removeGroup(txn, g.getId());
}
@@ -1156,24 +1156,24 @@ public class H2DatabaseTest extends BriarTestCase {
Collection<TemporarySecret> secrets = db.getSecrets(txn);
assertEquals(3, secrets.size());
boolean foundFirst = false, foundSecond = false, foundThird = false;
for(TemporarySecret s : secrets) {
for (TemporarySecret s : secrets) {
assertEquals(contactId, s.getContactId());
assertEquals(transportId, s.getTransportId());
assertEquals(epoch, s.getEpoch());
assertEquals(alice, s.getAlice());
if(s.getPeriod() == 0) {
if (s.getPeriod() == 0) {
assertArrayEquals(secret1, s.getSecret());
assertEquals(outgoing1, s.getOutgoingStreamCounter());
assertEquals(centre1, s.getWindowCentre());
assertArrayEquals(bitmap1, s.getWindowBitmap());
foundFirst = true;
} else if(s.getPeriod() == 1) {
} else if (s.getPeriod() == 1) {
assertArrayEquals(secret2, s.getSecret());
assertEquals(outgoing2, s.getOutgoingStreamCounter());
assertEquals(centre2, s.getWindowCentre());
assertArrayEquals(bitmap2, s.getWindowBitmap());
foundSecond = true;
} else if(s.getPeriod() == 2) {
} else if (s.getPeriod() == 2) {
assertArrayEquals(secret3, s.getSecret());
assertEquals(outgoing3, s.getOutgoingStreamCounter());
assertEquals(centre3, s.getWindowCentre());
@@ -1193,24 +1193,24 @@ public class H2DatabaseTest extends BriarTestCase {
assertEquals(3, secrets.size());
foundSecond = foundThird = false;
boolean foundFourth = false;
for(TemporarySecret s : secrets) {
for (TemporarySecret s : secrets) {
assertEquals(contactId, s.getContactId());
assertEquals(transportId, s.getTransportId());
assertEquals(epoch, s.getEpoch());
assertEquals(alice, s.getAlice());
if(s.getPeriod() == 1) {
if (s.getPeriod() == 1) {
assertArrayEquals(secret2, s.getSecret());
assertEquals(outgoing2, s.getOutgoingStreamCounter());
assertEquals(centre2, s.getWindowCentre());
assertArrayEquals(bitmap2, s.getWindowBitmap());
foundSecond = true;
} else if(s.getPeriod() == 2) {
} else if (s.getPeriod() == 2) {
assertArrayEquals(secret3, s.getSecret());
assertEquals(outgoing3, s.getOutgoingStreamCounter());
assertEquals(centre3, s.getWindowCentre());
assertArrayEquals(bitmap3, s.getWindowBitmap());
foundThird = true;
} else if(s.getPeriod() == 3) {
} else if (s.getPeriod() == 3) {
assertArrayEquals(secret4, s.getSecret());
assertEquals(outgoing4, s.getOutgoingStreamCounter());
assertEquals(centre4, s.getWindowCentre());
@@ -1387,13 +1387,13 @@ public class H2DatabaseTest extends BriarTestCase {
Collection<Endpoint> endpoints = db.getEndpoints(txn);
assertEquals(2, endpoints.size());
boolean foundFirst = false, foundSecond = false;
for(Endpoint ep : endpoints) {
for (Endpoint ep : endpoints) {
assertEquals(contactId, ep.getContactId());
if(ep.getTransportId().equals(transportId1)) {
if (ep.getTransportId().equals(transportId1)) {
assertEquals(epoch1, ep.getEpoch());
assertEquals(alice1, ep.getAlice());
foundFirst = true;
} else if(ep.getTransportId().equals(transportId2)) {
} else if (ep.getTransportId().equals(transportId2)) {
assertEquals(epoch2, ep.getEpoch());
assertEquals(alice2, ep.getAlice());
foundSecond = true;
@@ -1530,7 +1530,7 @@ public class H2DatabaseTest extends BriarTestCase {
// Add some offered messages and count them
List<MessageId> ids = new ArrayList<MessageId>();
for(int i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++) {
MessageId m = new MessageId(TestUtils.getRandomId());
db.addOfferedMessage(txn, contactId, m);
ids.add(m);
@@ -1595,7 +1595,7 @@ public class H2DatabaseTest extends BriarTestCase {
// Ask for a nonexistent message - an exception should be thrown
db.getRawMessage(txn, messageId);
fail();
} catch(DbException expected) {
} catch (DbException expected) {
// It should be possible to abort the transaction without error
db.abortTransaction(txn);
}
@@ -1606,7 +1606,7 @@ public class H2DatabaseTest extends BriarTestCase {
private Database<Connection> open(boolean resume) throws Exception {
Database<Connection> db = new H2Database(new TestDatabaseConfig(testDir,
MAX_SIZE), new TestFileUtils(), new SystemClock());
if(!resume) TestUtils.deleteTestDirectory(testDir);
if (!resume) TestUtils.deleteTestDirectory(testDir);
db.open();
return db;
}

View File

@@ -13,7 +13,7 @@ public class ShutdownManagerImplTest extends BriarTestCase {
public void testAddAndRemove() {
ShutdownManager s = createShutdownManager();
Set<Integer> handles = new HashSet<Integer>();
for(int i = 0; i < 100; i++) {
for (int i = 0; i < 100; i++) {
int handle = s.addShutdownHook(new Runnable() {
public void run() {}
});
@@ -21,9 +21,9 @@ public class ShutdownManagerImplTest extends BriarTestCase {
assertTrue(handles.add(handle));
}
// The hooks should be removable
for(int handle : handles) assertTrue(s.removeShutdownHook(handle));
for (int handle : handles) assertTrue(s.removeShutdownHook(handle));
// The hooks should no longer be removable
for(int handle : handles) assertFalse(s.removeShutdownHook(handle));
for (int handle : handles) assertFalse(s.removeShutdownHook(handle));
}
protected ShutdownManager createShutdownManager() {

View File

@@ -14,12 +14,12 @@ public class WindowsShutdownManagerImplTest extends ShutdownManagerImplTest {
public void testManagerWaitsForHooksToRun() {
WindowsShutdownManagerImpl s = new WindowsShutdownManagerImpl();
SlowHook[] hooks = new SlowHook[10];
for(int i = 0; i < hooks.length; i++) {
for (int i = 0; i < hooks.length; i++) {
hooks[i] = new SlowHook();
s.addShutdownHook(hooks[i]);
}
s.runShutdownHooks();
for(int i = 0; i < hooks.length; i++) assertTrue(hooks[i].finished);
for (int i = 0; i < hooks.length; i++) assertTrue(hooks[i].finished);
}
private static class SlowHook implements Runnable {
@@ -30,7 +30,7 @@ public class WindowsShutdownManagerImplTest extends ShutdownManagerImplTest {
try {
Thread.sleep(100);
finished = true;
} catch(InterruptedException e) {
} catch (InterruptedException e) {
fail();
}
}

View File

@@ -75,7 +75,7 @@ public class ConstantsTest extends BriarTestCase {
@Test
public void testAgreementPublicKeys() throws Exception {
// Generate 10 agreement key pairs
for(int i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++) {
KeyPair keyPair = crypto.generateSignatureKeyPair();
// Check the length of the public key
byte[] publicKey = keyPair.getPublic().getEncoded();
@@ -88,7 +88,7 @@ public class ConstantsTest extends BriarTestCase {
Random random = new Random();
Signature sig = crypto.getSignature();
// Generate 10 signature key pairs
for(int i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++) {
KeyPair keyPair = crypto.generateSignatureKeyPair();
// Check the length of the public key
byte[] publicKey = keyPair.getPublic().getEncoded();
@@ -166,7 +166,7 @@ public class ConstantsTest extends BriarTestCase {
public void testPropertiesFitIntoTransportUpdate() throws Exception {
// Create the maximum number of properties with the maximum length
TransportProperties p = new TransportProperties();
for(int i = 0; i < MAX_PROPERTIES_PER_TRANSPORT; i++) {
for (int i = 0; i < MAX_PROPERTIES_PER_TRANSPORT; i++) {
String key = TestUtils.createRandomString(MAX_PROPERTY_LENGTH);
String value = TestUtils.createRandomString(MAX_PROPERTY_LENGTH);
p.put(key, value);
@@ -187,7 +187,7 @@ public class ConstantsTest extends BriarTestCase {
public void testGroupsFitIntoSubscriptionUpdate() throws Exception {
// Create the maximum number of maximum-length groups
Collection<Group> groups = new ArrayList<Group>();
for(int i = 0; i < MAX_SUBSCRIPTIONS; i++) {
for (int i = 0; i < MAX_SUBSCRIPTIONS; i++) {
String name = TestUtils.createRandomString(MAX_GROUP_NAME_LENGTH);
groups.add(groupFactory.createGroup(name));
}
@@ -207,7 +207,7 @@ public class ConstantsTest extends BriarTestCase {
PacketWriter writer = packetWriterFactory.createPacketWriter(out);
int maxMessages = writer.getMaxMessagesForAck(length);
Collection<MessageId> ids = new ArrayList<MessageId>();
for(int i = 0; i < maxMessages; i++)
for (int i = 0; i < maxMessages; i++)
ids.add(new MessageId(TestUtils.getRandomId()));
writer.writeAck(new Ack(ids));
// Check the size of the serialised ack
@@ -220,7 +220,7 @@ public class ConstantsTest extends BriarTestCase {
PacketWriter writer = packetWriterFactory.createPacketWriter(out);
int maxMessages = writer.getMaxMessagesForRequest(length);
Collection<MessageId> ids = new ArrayList<MessageId>();
for(int i = 0; i < maxMessages; i++)
for (int i = 0; i < maxMessages; i++)
ids.add(new MessageId(TestUtils.getRandomId()));
writer.writeRequest(new Request(ids));
// Check the size of the serialised request
@@ -233,7 +233,7 @@ public class ConstantsTest extends BriarTestCase {
PacketWriter writer = packetWriterFactory.createPacketWriter(out);
int maxMessages = writer.getMaxMessagesForOffer(length);
Collection<MessageId> ids = new ArrayList<MessageId>();
for(int i = 0; i < maxMessages; i++)
for (int i = 0; i < maxMessages; i++)
ids.add(new MessageId(TestUtils.getRandomId()));
writer.writeOffer(new Offer(ids));
// Check the size of the serialised offer

View File

@@ -40,7 +40,7 @@ public class ConsumersTest extends BriarTestCase {
try {
cc.write((byte) 0);
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
}
@Test

View File

@@ -46,7 +46,7 @@ public class PacketReaderImplTest extends BriarTestCase {
try {
reader.readAck();
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
}
@Test
@@ -67,7 +67,7 @@ public class PacketReaderImplTest extends BriarTestCase {
try {
reader.readAck();
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
}
@Test
@@ -79,7 +79,7 @@ public class PacketReaderImplTest extends BriarTestCase {
try {
reader.readOffer();
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
}
@Test
@@ -100,7 +100,7 @@ public class PacketReaderImplTest extends BriarTestCase {
try {
reader.readOffer();
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
}
@Test
@@ -112,7 +112,7 @@ public class PacketReaderImplTest extends BriarTestCase {
try {
reader.readRequest();
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
}
@Test
@@ -133,7 +133,7 @@ public class PacketReaderImplTest extends BriarTestCase {
try {
reader.readRequest();
fail();
} catch(FormatException expected) {}
} catch (FormatException expected) {}
}
private byte[] createAck(boolean tooBig) throws Exception {
@@ -142,11 +142,11 @@ public class PacketReaderImplTest extends BriarTestCase {
Writer w = writerFactory.createWriter(out);
w.writeListStart();
w.writeListStart();
while(out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2
while (out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2
< HEADER_LENGTH + MAX_PAYLOAD_LENGTH) {
w.writeRaw(TestUtils.getRandomId());
}
if(tooBig) w.writeRaw(TestUtils.getRandomId());
if (tooBig) w.writeRaw(TestUtils.getRandomId());
w.writeListEnd();
w.writeListEnd();
assertEquals(tooBig, out.size() > HEADER_LENGTH + MAX_PAYLOAD_LENGTH);
@@ -176,11 +176,11 @@ public class PacketReaderImplTest extends BriarTestCase {
Writer w = writerFactory.createWriter(out);
w.writeListStart();
w.writeListStart();
while(out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2
while (out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2
< HEADER_LENGTH + MAX_PAYLOAD_LENGTH) {
w.writeRaw(TestUtils.getRandomId());
}
if(tooBig) w.writeRaw(TestUtils.getRandomId());
if (tooBig) w.writeRaw(TestUtils.getRandomId());
w.writeListEnd();
w.writeListEnd();
assertEquals(tooBig, out.size() > HEADER_LENGTH + MAX_PAYLOAD_LENGTH);
@@ -210,11 +210,11 @@ public class PacketReaderImplTest extends BriarTestCase {
Writer w = writerFactory.createWriter(out);
w.writeListStart();
w.writeListStart();
while(out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2
while (out.size() + UNIQUE_ID_LENGTH + LIST_END_LENGTH * 2
< HEADER_LENGTH + MAX_PAYLOAD_LENGTH) {
w.writeRaw(TestUtils.getRandomId());
}
if(tooBig) w.writeRaw(TestUtils.getRandomId());
if (tooBig) w.writeRaw(TestUtils.getRandomId());
w.writeListEnd();
w.writeListEnd();
assertEquals(tooBig, out.size() > HEADER_LENGTH + MAX_PAYLOAD_LENGTH);

View File

@@ -240,7 +240,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
private volatile boolean messageAdded = false;
public void eventOccurred(Event e) {
if(e instanceof MessageAddedEvent) messageAdded = true;
if (e instanceof MessageAddedEvent) messageAdded = true;
}
}
}

View File

@@ -75,7 +75,7 @@ public class ConnectionRegistryImplTest extends BriarTestCase {
try {
c.unregisterConnection(contactId, transportId);
fail();
} catch(IllegalArgumentException expected) {}
} catch (IllegalArgumentException expected) {}
// Register both contacts with one transport, one contact with both -
// this should broadcast two ContactConnectedEvents
c.registerConnection(contactId, transportId);

View File

@@ -20,7 +20,7 @@ public abstract class DuplexClientTest extends DuplexTest {
assert plugin != null;
// Start the plugin
System.out.println("Starting plugin");
if(!plugin.start()) {
if (!plugin.start()) {
System.out.println("Plugin failed to start");
return;
}
@@ -28,14 +28,14 @@ public abstract class DuplexClientTest extends DuplexTest {
// Try to connect to the server
System.out.println("Creating connection");
DuplexTransportConnection d = plugin.createConnection(contactId);
if(d == null) {
if (d == null) {
System.out.println("Connection failed");
return;
} else {
System.out.println("Connection created");
receiveChallengeSendResponse(d);
}
if(!plugin.supportsInvitations()) {
if (!plugin.supportsInvitations()) {
System.out.println("Skipping invitation test");
return;
}
@@ -43,7 +43,7 @@ public abstract class DuplexClientTest extends DuplexTest {
System.out.println("Creating invitation connection");
PseudoRandom r = getPseudoRandom(123);
d = plugin.createInvitationConnection(r, CONNECTION_TIMEOUT);
if(d == null) {
if (d == null) {
System.out.println("Connection failed");
return;
} else {

View File

@@ -21,18 +21,18 @@ public abstract class DuplexServerTest extends DuplexTest {
assert plugin != null;
// Start the plugin
System.out.println("Starting plugin");
if(!plugin.start()) {
if (!plugin.start()) {
System.out.println("Plugin failed to start");
return;
}
try {
// Wait for a connection
System.out.println("Waiting for connection");
if(!callback.latch.await(120, SECONDS)) {
if (!callback.latch.await(120, SECONDS)) {
System.out.println("No connection received");
return;
}
if(!plugin.supportsInvitations()) {
if (!plugin.supportsInvitations()) {
System.out.println("Skipping invitation test");
return;
}
@@ -40,7 +40,7 @@ public abstract class DuplexServerTest extends DuplexTest {
System.out.println("Creating invitation connection");
DuplexTransportConnection d = plugin.createInvitationConnection(
getPseudoRandom(123), CONNECTION_TIMEOUT);
if(d == null) {
if (d == null) {
System.out.println("Connection failed");
return;
} else {

View File

@@ -31,10 +31,10 @@ abstract class DuplexTest {
out.flush();
System.out.println("Sent challenge: " + CHALLENGE);
Scanner in = new Scanner(r.getInputStream());
if(in.hasNextLine()) {
if (in.hasNextLine()) {
String response = in.nextLine();
System.out.println("Received response: " + response);
if(RESPONSE.equals(response)) {
if (RESPONSE.equals(response)) {
System.out.println("Correct response");
} else {
System.out.println("Incorrect response");
@@ -44,12 +44,12 @@ abstract class DuplexTest {
}
r.dispose(false, true);
w.dispose(false);
} catch(IOException e) {
} catch (IOException e) {
e.printStackTrace();
try {
r.dispose(true, true);
w.dispose(true);
} catch(IOException e1) {
} catch (IOException e1) {
e1.printStackTrace();
}
}
@@ -61,10 +61,10 @@ abstract class DuplexTest {
TransportConnectionWriter w = d.getWriter();
try {
Scanner in = new Scanner(r.getInputStream());
if(in.hasNextLine()) {
if (in.hasNextLine()) {
String challenge = in.nextLine();
System.out.println("Received challenge: " + challenge);
if(CHALLENGE.equals(challenge)) {
if (CHALLENGE.equals(challenge)) {
PrintStream out = new PrintStream(w.getOutputStream());
out.println(RESPONSE);
@@ -78,12 +78,12 @@ abstract class DuplexTest {
}
r.dispose(false, true);
w.dispose(false);
} catch(IOException e) {
} catch (IOException e) {
e.printStackTrace();
try {
r.dispose(true, true);
w.dispose(true);
} catch(IOException e1) {
} catch (IOException e1) {
e1.printStackTrace();
}
}

View File

@@ -32,7 +32,7 @@ public class BluetoothClientTest extends DuplexClientTest {
}
public static void main(String[] args) throws Exception {
if(args.length != 1) {
if (args.length != 1) {
System.err.println("Please specify the server's Bluetooth address");
System.exit(1);
}

View File

@@ -29,7 +29,7 @@ public class PollingRemovableDriveMonitorTest extends BriarTestCase {
private AtomicBoolean firstCall = new AtomicBoolean(true);
public Collection<File> findRemovableDrives() throws IOException {
if(firstCall.getAndSet(false)) return Collections.emptyList();
if (firstCall.getAndSet(false)) return Collections.emptyList();
else return Arrays.asList(file1, file2);
}
};
@@ -68,7 +68,7 @@ public class PollingRemovableDriveMonitorTest extends BriarTestCase {
private AtomicBoolean firstCall = new AtomicBoolean(true);
public Collection<File> findRemovableDrives() throws IOException {
if(firstCall.getAndSet(false)) return Collections.emptyList();
if (firstCall.getAndSet(false)) return Collections.emptyList();
else throw new IOException();
}
};

View File

@@ -27,7 +27,7 @@ public class UnixRemovableDriveMonitorTest extends BriarTestCase {
@Test
public void testNonexistentDir() throws Exception {
if(!(OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer())) {
if (!(OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer())) {
System.err.println("WARNING: Skipping test, can't run on this OS");
return;
}
@@ -48,7 +48,7 @@ public class UnixRemovableDriveMonitorTest extends BriarTestCase {
@Test
public void testOneCallbackPerFile() throws Exception {
if(!(OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer())) {
if (!(OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer())) {
System.err.println("WARNING: Skipping test, can't run on this OS");
return;
}

View File

@@ -35,7 +35,7 @@ public class LanTcpClientTest extends DuplexClientTest {
}
public static void main(String[] args) throws Exception {
if(args.length != 2) {
if (args.length != 2) {
System.err.println("Please specify the server's address and port");
System.exit(1);
}

View File

@@ -69,13 +69,13 @@ public class LanTcpPluginTest extends BriarTestCase {
private byte[] makeAddress(int... parts) {
byte[] b = new byte[parts.length];
for(int i = 0; i < parts.length; i++) b[i] = (byte) parts[i];
for (int i = 0; i < parts.length; i++) b[i] = (byte) parts[i];
return b;
}
@Test
public void testIncomingConnection() throws Exception {
if(!systemHasLocalIpv4Address()) {
if (!systemHasLocalIpv4Address()) {
System.err.println("WARNING: Skipping test, no local IPv4 address");
return;
}
@@ -107,7 +107,7 @@ public class LanTcpPluginTest extends BriarTestCase {
@Test
public void testOutgoingConnection() throws Exception {
if(!systemHasLocalIpv4Address()) {
if (!systemHasLocalIpv4Address()) {
System.err.println("WARNING: Skipping test, no local IPv4 address");
return;
}
@@ -131,7 +131,7 @@ public class LanTcpPluginTest extends BriarTestCase {
try {
ss.accept();
latch.countDown();
} catch(IOException e) {
} catch (IOException e) {
error.set(true);
}
}
@@ -155,10 +155,10 @@ public class LanTcpPluginTest extends BriarTestCase {
}
private boolean systemHasLocalIpv4Address() throws Exception {
for(NetworkInterface i : Collections.list(
for (NetworkInterface i : Collections.list(
NetworkInterface.getNetworkInterfaces())) {
for(InetAddress a : Collections.list(i.getInetAddresses())) {
if(a instanceof Inet4Address)
for (InetAddress a : Collections.list(i.getInetAddresses())) {
if (a instanceof Inet4Address)
return a.isLinkLocalAddress() || a.isSiteLocalAddress();
}
}

View File

@@ -29,13 +29,13 @@ public class LinuxSeedProviderTest extends BriarTestCase {
@Test
public void testSeedAppearsSane() {
if(!(OsUtils.isLinux())) {
if (!(OsUtils.isLinux())) {
System.err.println("WARNING: Skipping test, can't run on this OS");
return;
}
Set<Bytes> seeds = new HashSet<Bytes>();
LinuxSeedProvider p = new LinuxSeedProvider();
for(int i = 0; i < 1000; i++) {
for (int i = 0; i < 1000; i++) {
byte[] seed = p.getSeed();
assertEquals(SEED_BYTES, seed.length);
assertTrue(seeds.add(new Bytes(seed)));
@@ -44,7 +44,7 @@ public class LinuxSeedProviderTest extends BriarTestCase {
@Test
public void testEntropyIsWrittenToPool() throws Exception {
if(!(OsUtils.isLinux())) {
if (!(OsUtils.isLinux())) {
System.err.println("WARNING: Skipping test, can't run on this OS");
return;
}
@@ -62,7 +62,7 @@ public class LinuxSeedProviderTest extends BriarTestCase {
@Test
public void testSeedIsReadFromPool() throws Exception {
if(!(OsUtils.isLinux())) {
if (!(OsUtils.isLinux())) {
System.err.println("WARNING: Skipping test, can't run on this OS");
return;
}

View File

@@ -43,13 +43,13 @@ public class KeyManagerImplTest extends BriarTestCase {
secret2 = new byte[32];
secret3 = new byte[32];
secret4 = new byte[32];
for(int i = 0; i < secret0.length; i++) secret0[i] = 1;
for(int i = 0; i < secret1.length; i++) secret1[i] = 2;
for(int i = 0; i < secret2.length; i++) secret2[i] = 3;
for(int i = 0; i < secret3.length; i++) secret3[i] = 4;
for(int i = 0; i < secret4.length; i++) secret4[i] = 5;
for (int i = 0; i < secret0.length; i++) secret0[i] = 1;
for (int i = 0; i < secret1.length; i++) secret1[i] = 2;
for (int i = 0; i < secret2.length; i++) secret2[i] = 3;
for (int i = 0; i < secret3.length; i++) secret3[i] = 4;
for (int i = 0; i < secret4.length; i++) secret4[i] = 5;
initialSecret = new byte[32];
for(int i = 0; i < initialSecret.length; i++) initialSecret[i] = 123;
for (int i = 0; i < initialSecret.length; i++) initialSecret[i] = 123;
}
@Test

View File

@@ -51,11 +51,11 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
secret2 = new byte[32];
secret3 = new byte[32];
secret4 = new byte[32];
for(int i = 0; i < secret0.length; i++) secret0[i] = 1;
for(int i = 0; i < secret1.length; i++) secret1[i] = 2;
for(int i = 0; i < secret2.length; i++) secret2[i] = 3;
for(int i = 0; i < secret3.length; i++) secret3[i] = 4;
for(int i = 0; i < secret4.length; i++) secret4[i] = 5;
for (int i = 0; i < secret0.length; i++) secret0[i] = 1;
for (int i = 0; i < secret1.length; i++) secret1[i] = 2;
for (int i = 0; i < secret2.length; i++) secret2[i] = 3;
for (int i = 0; i < secret3.length; i++) secret3[i] = 4;
for (int i = 0; i < secret4.length; i++) secret4[i] = 5;
key0 = new byte[32];
key1 = new byte[32];
key2 = new byte[32];
@@ -66,13 +66,13 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
k2 = new SecretKey(key2);
k3 = new SecretKey(key3);
k4 = new SecretKey(key4);
for(int i = 0; i < key0.length; i++) key0[i] = 1;
for(int i = 0; i < key1.length; i++) key1[i] = 2;
for(int i = 0; i < key2.length; i++) key2[i] = 3;
for(int i = 0; i < key3.length; i++) key3[i] = 4;
for(int i = 0; i < key4.length; i++) key4[i] = 5;
for (int i = 0; i < key0.length; i++) key0[i] = 1;
for (int i = 0; i < key1.length; i++) key1[i] = 2;
for (int i = 0; i < key2.length; i++) key2[i] = 3;
for (int i = 0; i < key3.length; i++) key3[i] = 4;
for (int i = 0; i < key4.length; i++) key4[i] = 5;
initialSecret = new byte[32];
for(int i = 0; i < initialSecret.length; i++) initialSecret[i] = 123;
for (int i = 0; i < initialSecret.length; i++) initialSecret[i] = 123;
}
@Test
@@ -154,7 +154,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 0
oneOf(crypto).deriveTagKey(secret0, false);
will(returnValue(k0));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
with((long) i));
will(new EncodeTagAction());
@@ -162,7 +162,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -170,7 +170,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -179,7 +179,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 0
oneOf(crypto).deriveTagKey(secret0, false);
will(returnValue(k0));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
with((long) i));
will(new EncodeTagAction());
@@ -187,7 +187,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -195,7 +195,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -256,7 +256,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 0
oneOf(crypto).deriveTagKey(secret0, false);
will(returnValue(k0));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
with((long) i));
will(new EncodeTagAction());
@@ -264,7 +264,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -272,7 +272,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -284,7 +284,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 0
oneOf(crypto).deriveTagKey(secret0, false);
will(returnValue(k0));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
with((long) i));
will(new EncodeTagAction());
@@ -292,7 +292,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -300,7 +300,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -369,7 +369,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 0
oneOf(crypto).deriveTagKey(secret0, false);
will(returnValue(k0));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
with((long) i));
will(new EncodeTagAction());
@@ -377,7 +377,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -385,7 +385,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -402,7 +402,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 0
oneOf(crypto).deriveTagKey(secret0, false);
will(returnValue(k0));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
with((long) i));
will(new EncodeTagAction());
@@ -410,7 +410,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -418,7 +418,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the updated tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 1; i < 17; i++) {
for (int i = 1; i < 17; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -478,7 +478,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 0
oneOf(crypto).deriveTagKey(secret0, false);
will(returnValue(k0));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
with((long) i));
will(new EncodeTagAction());
@@ -486,7 +486,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -494,7 +494,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -506,7 +506,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should remove the tags for period 0
oneOf(crypto).deriveTagKey(secret0, false);
will(returnValue(k0));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k0),
with((long) i));
will(new EncodeTagAction());
@@ -514,7 +514,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -522,7 +522,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -581,7 +581,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -589,7 +589,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -597,7 +597,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 3
oneOf(crypto).deriveTagKey(secret3, false);
will(returnValue(k3));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k3),
with((long) i));
will(new EncodeTagAction());
@@ -609,7 +609,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 1
oneOf(crypto).deriveTagKey(secret1, false);
will(returnValue(k1));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k1),
with((long) i));
will(new EncodeTagAction());
@@ -617,7 +617,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -625,7 +625,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should remove the tags for period 3
oneOf(crypto).deriveTagKey(secret3, false);
will(returnValue(k3));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k3),
with((long) i));
will(new EncodeTagAction());
@@ -686,7 +686,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -694,7 +694,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 3
oneOf(crypto).deriveTagKey(secret3, false);
will(returnValue(k3));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k3),
with((long) i));
will(new EncodeTagAction());
@@ -702,7 +702,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 4
oneOf(crypto).deriveTagKey(secret4, false);
will(returnValue(k4));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k4),
with((long) i));
will(new EncodeTagAction());
@@ -714,7 +714,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 2
oneOf(crypto).deriveTagKey(secret2, false);
will(returnValue(k2));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k2),
with((long) i));
will(new EncodeTagAction());
@@ -722,7 +722,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should remove the tags for period 3
oneOf(crypto).deriveTagKey(secret3, false);
will(returnValue(k3));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k3),
with((long) i));
will(new EncodeTagAction());
@@ -730,7 +730,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
// The recogniser should derive the tags for period 4
oneOf(crypto).deriveTagKey(secret4, false);
will(returnValue(k4));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(k4),
with((long) i));
will(new EncodeTagAction());

View File

@@ -14,7 +14,7 @@ public class ReorderingWindowTest extends BriarTestCase {
@Test
public void testWindowSliding() {
ReorderingWindow w = new ReorderingWindow();
for(int i = 0; i < 100; i++) {
for (int i = 0; i < 100; i++) {
assertFalse(w.isSeen(i));
w.setSeen(i);
assertTrue(w.isSeen(i));
@@ -24,7 +24,7 @@ public class ReorderingWindowTest extends BriarTestCase {
@Test
public void testWindowJumping() {
ReorderingWindow w = new ReorderingWindow();
for(int i = 0; i < 100; i += 13) {
for (int i = 0; i < 100; i += 13) {
assertFalse(w.isSeen(i));
w.setSeen(i);
assertTrue(w.isSeen(i));
@@ -42,7 +42,7 @@ public class ReorderingWindowTest extends BriarTestCase {
// Centre is 32, highest value in window is 47
w.setSeen(48);
fail();
} catch(IllegalArgumentException expected) {}
} catch (IllegalArgumentException expected) {}
// Centre is max - 1, highest value in window is max
byte[] bitmap = new byte[REORDERING_WINDOW_SIZE / 8];
w = new ReorderingWindow(MAX_32_BIT_UNSIGNED - 1, bitmap);
@@ -52,7 +52,7 @@ public class ReorderingWindowTest extends BriarTestCase {
try {
w.setSeen(MAX_32_BIT_UNSIGNED + 1);
fail();
} catch(IllegalArgumentException expected) {}
} catch (IllegalArgumentException expected) {}
w.setSeen(MAX_32_BIT_UNSIGNED);
assertTrue(w.isSeen(MAX_32_BIT_UNSIGNED));
// Centre should have moved to max + 1
@@ -65,7 +65,7 @@ public class ReorderingWindowTest extends BriarTestCase {
try {
w.setSeen(MAX_32_BIT_UNSIGNED + 1);
fail();
} catch(IllegalArgumentException expected) {}
} catch (IllegalArgumentException expected) {}
}
@Test
@@ -75,7 +75,7 @@ public class ReorderingWindowTest extends BriarTestCase {
try {
w.setSeen(-1);
fail();
} catch(IllegalArgumentException expected) {}
} catch (IllegalArgumentException expected) {}
// Slide the window
w.setSeen(15);
// Centre is 16, lowest value in window is 0
@@ -87,7 +87,7 @@ public class ReorderingWindowTest extends BriarTestCase {
try {
w.setSeen(0);
fail();
} catch(IllegalArgumentException expected) {}
} catch (IllegalArgumentException expected) {}
// Slide the window
w.setSeen(25);
// Centre is 26, lowest value in window is 10
@@ -95,7 +95,7 @@ public class ReorderingWindowTest extends BriarTestCase {
try {
w.setSeen(9);
fail();
} catch(IllegalArgumentException expected) {}
} catch (IllegalArgumentException expected) {}
// Centre should still be 26
assertEquals(26, w.getCentre());
// The bits corresponding to 10, 15, 16 and 25 should be set
@@ -112,7 +112,7 @@ public class ReorderingWindowTest extends BriarTestCase {
try {
w.setSeen(15);
fail();
} catch(IllegalArgumentException expected) {}
} catch (IllegalArgumentException expected) {}
}
@Test
@@ -121,7 +121,7 @@ public class ReorderingWindowTest extends BriarTestCase {
// Centre is 0; window should cover 0 to 15, inclusive, with none seen
Collection<Long> unseen = w.getUnseen();
assertEquals(16, unseen.size());
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
assertTrue(unseen.contains(Long.valueOf(i)));
assertFalse(w.isSeen(i));
}
@@ -130,8 +130,8 @@ public class ReorderingWindowTest extends BriarTestCase {
// Centre is 5; window should cover 0 to 20, inclusive, with two seen
unseen = w.getUnseen();
assertEquals(19, unseen.size());
for(int i = 0; i < 21; i++) {
if(i == 3 || i == 4) {
for (int i = 0; i < 21; i++) {
if (i == 3 || i == 4) {
assertFalse(unseen.contains(Long.valueOf(i)));
assertTrue(w.isSeen(i));
} else {
@@ -143,8 +143,8 @@ public class ReorderingWindowTest extends BriarTestCase {
// Centre is 20; window should cover 4 to 35, inclusive, with two seen
unseen = w.getUnseen();
assertEquals(30, unseen.size());
for(int i = 4; i < 36; i++) {
if(i == 4 || i == 19) {
for (int i = 4; i < 36; i++) {
if (i == 4 || i == 19) {
assertFalse(unseen.contains(Long.valueOf(i)));
assertTrue(w.isSeen(i));
} else {

View File

@@ -91,7 +91,7 @@ public class StreamWriterImplTest extends BriarTestCase {
oneOf(encrypter).writeFrame(with(any(byte[].class)),
with(MAX_PAYLOAD_LENGTH), with(0), with(false));
}});
for(int i = 0; i < MAX_PAYLOAD_LENGTH; i++) w.write(0);
for (int i = 0; i < MAX_PAYLOAD_LENGTH; i++) w.write(0);
context.assertIsSatisfied();
// Clean up

View File

@@ -24,20 +24,20 @@ class TestStreamDecrypter implements StreamDecrypter {
public int readFrame(byte[] payload) throws IOException {
int offset = 0;
while(offset < HEADER_LENGTH) {
while (offset < HEADER_LENGTH) {
int read = in.read(frame, offset, HEADER_LENGTH - offset);
if(read == -1) throw new EOFException();
if (read == -1) throw new EOFException();
offset += read;
}
boolean finalFrame = (frame[0] & 0x80) == 0x80;
int payloadLength = ByteUtils.readUint16(frame, 0) & 0x7FFF;
while(offset < frame.length) {
while (offset < frame.length) {
int read = in.read(frame, offset, frame.length - offset);
if(read == -1) break;
if (read == -1) break;
offset += read;
}
if(!finalFrame && offset < frame.length) throw new EOFException();
if(offset < HEADER_LENGTH + payloadLength + MAC_LENGTH)
if (!finalFrame && offset < frame.length) throw new EOFException();
if (offset < HEADER_LENGTH + payloadLength + MAC_LENGTH)
throw new FormatException();
System.arraycopy(frame, HEADER_LENGTH, payload, 0, payloadLength);
return payloadLength;

View File

@@ -25,16 +25,16 @@ class TestStreamEncrypter implements StreamEncrypter {
public void writeFrame(byte[] payload, int payloadLength,
int paddingLength, boolean finalFrame) throws IOException {
if(writeTag) {
if (writeTag) {
out.write(tag);
writeTag = false;
}
ByteUtils.writeUint16(payloadLength, frame, 0);
if(finalFrame) frame[0] |= 0x80;
if (finalFrame) frame[0] |= 0x80;
System.arraycopy(payload, 0, frame, HEADER_LENGTH, payloadLength);
for(int i = HEADER_LENGTH + payloadLength; i < frame.length; i++)
for (int i = HEADER_LENGTH + payloadLength; i < frame.length; i++)
frame[i] = 0;
if(finalFrame)
if (finalFrame)
out.write(frame, 0, HEADER_LENGTH + payloadLength + MAC_LENGTH);
else out.write(frame, 0, frame.length);
}

View File

@@ -73,9 +73,9 @@ public class TransportIntegrationTest extends BriarTestCase {
private void read(InputStream in, byte[] dest) throws IOException {
int offset = 0;
while(offset < dest.length) {
while (offset < dest.length) {
int read = in.read(dest, offset, dest.length - offset);
if(read == -1) break;
if (read == -1) break;
offset += read;
}
}

View File

@@ -39,7 +39,7 @@ public class TransportTagRecogniserTest extends BriarTestCase {
// Add secret
oneOf(crypto).deriveTagKey(secret, !alice);
will(returnValue(tagKey));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(tagKey),
with((long) i));
will(new EncodeTagAction());
@@ -47,7 +47,7 @@ public class TransportTagRecogniserTest extends BriarTestCase {
// Remove secret
oneOf(crypto).deriveTagKey(secret, !alice);
will(returnValue(tagKey));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(tagKey),
with((long) i));
will(new EncodeTagAction());
@@ -74,7 +74,7 @@ public class TransportTagRecogniserTest extends BriarTestCase {
// Add secret
oneOf(crypto).deriveTagKey(secret, !alice);
will(returnValue(tagKey));
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
oneOf(crypto).encodeTag(with(any(byte[].class)), with(tagKey),
with((long) i));
will(new EncodeTagAction());

View File

@@ -52,11 +52,11 @@ public class ByteUtilsTest extends BriarTestCase {
public void testReadUint() {
byte[] b = new byte[1];
b[0] = (byte) 128;
for(int i = 0; i < 8; i++) {
for (int i = 0; i < 8; i++) {
assertEquals(1 << i, ByteUtils.readUint(b, i + 1));
}
b = new byte[2];
for(int i = 0; i < 65535; i++) {
for (int i = 0; i < 65535; i++) {
ByteUtils.writeUint16(i, b, 0);
assertEquals(i, ByteUtils.readUint(b, 16));
assertEquals(i >> 1, ByteUtils.readUint(b, 15));

View File

@@ -19,11 +19,11 @@ public class StringUtilsTest extends BriarTestCase {
try {
StringUtils.fromHexString("12345");
fail();
} catch(IllegalArgumentException expected) {}
} catch (IllegalArgumentException expected) {}
try {
StringUtils.fromHexString("ABCDEFGH");
fail();
} catch(IllegalArgumentException expected) {}
} catch (IllegalArgumentException expected) {}
byte[] b = StringUtils.fromHexString("0102037F80");
assertArrayEquals(new byte[] {1, 2, 3, 127, -128}, b);
b = StringUtils.fromHexString("0a0b0c0d0e0f");