mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Miscellaneous code cleanups.
This commit is contained in:
@@ -6,8 +6,7 @@ import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@@ -27,8 +26,7 @@ import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.StringUtils.fromHexString;
|
||||
import static org.briarproject.bramble.util.StringUtils.toHexString;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
@NotNullByDefault
|
||||
class AccountManagerImpl implements AccountManager {
|
||||
|
||||
private static final Logger LOG =
|
||||
@@ -104,7 +102,7 @@ class AccountManagerImpl implements AccountManager {
|
||||
}
|
||||
|
||||
// Locking: stateChangeLock
|
||||
protected boolean storeEncryptedDatabaseKey(String hex) {
|
||||
boolean storeEncryptedDatabaseKey(String hex) {
|
||||
LOG.info("Storing database key in file");
|
||||
// Create the directory if necessary
|
||||
if (databaseConfig.getDatabaseKeyDirectory().mkdirs())
|
||||
|
||||
@@ -191,6 +191,7 @@ class ContactExchangeTaskImpl extends Thread implements ContactExchangeTask {
|
||||
streamWriter.sendEndOfStream();
|
||||
// Skip any remaining records from the incoming stream
|
||||
try {
|
||||
//noinspection InfiniteLoopStatement
|
||||
while (true) recordReader.readRecord();
|
||||
} catch (EOFException expected) {
|
||||
LOG.info("End of stream");
|
||||
|
||||
@@ -15,7 +15,7 @@ class AsciiArmour {
|
||||
int length = wrapped.length();
|
||||
for (int i = 0; i < length; i += lineLength) {
|
||||
int end = Math.min(i + lineLength, length);
|
||||
s.append(wrapped.substring(i, end));
|
||||
s.append(wrapped, i, end);
|
||||
s.append("\r\n");
|
||||
}
|
||||
return s.toString();
|
||||
|
||||
@@ -159,6 +159,7 @@ public class MessageEncrypter {
|
||||
printUsage();
|
||||
System.exit(1);
|
||||
}
|
||||
//noinspection IfCanBeSwitch
|
||||
if (args[0].equals("generate")) {
|
||||
if (args.length != 3) {
|
||||
printUsage();
|
||||
|
||||
@@ -242,7 +242,7 @@ interface Database<T> {
|
||||
* bytes. This is based on the minimum of the space available on the device
|
||||
* where the database is stored and the database's configured size.
|
||||
*/
|
||||
long getFreeSpace() throws DbException;
|
||||
long getFreeSpace();
|
||||
|
||||
/**
|
||||
* Returns the group with the given ID.
|
||||
|
||||
@@ -339,6 +339,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected void open(String driverClass, boolean reopen, SecretKey key,
|
||||
@Nullable MigrationListener listener) throws DbException {
|
||||
// Load the JDBC driver
|
||||
@@ -768,7 +769,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
for (Entry<ContactId, Boolean> e : visibility.entrySet()) {
|
||||
ContactId c = e.getKey();
|
||||
boolean offered = removeOfferedMessage(txn, c, m.getId());
|
||||
boolean seen = offered || (sender != null && c.equals(sender));
|
||||
boolean seen = offered || c.equals(sender);
|
||||
addStatus(txn, m.getId(), c, m.getGroupId(), m.getTimestamp(),
|
||||
raw.length, state, e.getValue(), messageShared,
|
||||
false, seen);
|
||||
|
||||
@@ -17,7 +17,7 @@ class Migration40_41 implements Migration<Connection> {
|
||||
|
||||
private final DatabaseTypes dbTypes;
|
||||
|
||||
public Migration40_41(DatabaseTypes databaseTypes) {
|
||||
Migration40_41(DatabaseTypes databaseTypes) {
|
||||
this.dbTypes = databaseTypes;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.briarproject.bramble.keyagreement;
|
||||
|
||||
class AbortException extends Exception {
|
||||
|
||||
boolean receivedAbort;
|
||||
final boolean receivedAbort;
|
||||
|
||||
AbortException() {
|
||||
this(false);
|
||||
|
||||
@@ -20,6 +20,7 @@ interface BluetoothConnectionLimiter {
|
||||
* Returns true if a contact connection can be opened. This method does not
|
||||
* need to be called for key agreement connections.
|
||||
*/
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
boolean canOpenContactConnection();
|
||||
|
||||
/**
|
||||
|
||||
@@ -80,6 +80,7 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
locals.add(new InetSocketAddress(local, 0));
|
||||
}
|
||||
}
|
||||
//noinspection Java8ListSort
|
||||
sort(locals, ADDRESS_COMPARATOR);
|
||||
return locals;
|
||||
}
|
||||
|
||||
@@ -85,6 +85,7 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
/**
|
||||
* Returns true if connections to the given address can be attempted.
|
||||
*/
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
protected abstract boolean isConnectable(InetSocketAddress remote);
|
||||
|
||||
TcpPlugin(Executor ioExecutor, Backoff backoff,
|
||||
|
||||
@@ -13,7 +13,7 @@ abstract class Frame {
|
||||
|
||||
static final byte ACK_FLAG = (byte) 128, FIN_FLAG = 64;
|
||||
|
||||
protected final byte[] buf;
|
||||
final byte[] buf;
|
||||
|
||||
Frame(byte[] buf) {
|
||||
this.buf = buf;
|
||||
|
||||
@@ -101,6 +101,7 @@ class Receiver implements ReadHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("StatementWithEmptyBody")
|
||||
private void handleData(byte[] b) throws IOException {
|
||||
windowLock.lock();
|
||||
try {
|
||||
@@ -124,6 +125,7 @@ class Receiver implements ReadHandler {
|
||||
finalSequenceNumber = sequenceNumber;
|
||||
// Remove any data frames with higher sequence numbers
|
||||
Iterator<Data> it = dataFrames.iterator();
|
||||
//noinspection Java8CollectionRemoveIf
|
||||
while (it.hasNext()) {
|
||||
Data d1 = it.next();
|
||||
if (d1.getSequenceNumber() >= finalSequenceNumber)
|
||||
@@ -148,6 +150,7 @@ class Receiver implements ReadHandler {
|
||||
|
||||
private static class SequenceNumberComparator implements Comparator<Data> {
|
||||
|
||||
@SuppressWarnings("UseCompareMethod")
|
||||
@Override
|
||||
public int compare(Data d1, Data d2) {
|
||||
long s1 = d1.getSequenceNumber(), s2 = d2.getSequenceNumber();
|
||||
|
||||
@@ -52,6 +52,7 @@ class ReceiverInputStream extends InputStream {
|
||||
return len;
|
||||
}
|
||||
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
private boolean receive() throws IOException {
|
||||
if (length != 0) throw new AssertionError();
|
||||
if (data != null && data.isLastFrame()) {
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
||||
|
||||
@ThreadSafe
|
||||
@NotNullByDefault
|
||||
@@ -96,7 +97,7 @@ class Sender {
|
||||
}
|
||||
// If any older data frames are outstanding, retransmit the oldest
|
||||
if (foundIndex > 0) {
|
||||
fastRetransmit = outstanding.poll();
|
||||
fastRetransmit = requireNonNull(outstanding.poll());
|
||||
fastRetransmit.lastTransmitted = now;
|
||||
fastRetransmit.retransmitted = true;
|
||||
outstanding.add(fastRetransmit);
|
||||
@@ -191,7 +192,7 @@ class Sender {
|
||||
writeHandler.handleWrite(d.getBuffer());
|
||||
}
|
||||
|
||||
void flush() throws IOException, InterruptedException {
|
||||
void flush() throws InterruptedException {
|
||||
windowLock.lock();
|
||||
try {
|
||||
while (dataWaiting || !outstanding.isEmpty())
|
||||
|
||||
@@ -44,6 +44,7 @@ public class DevReportServer {
|
||||
TokenBucket bucket = new TokenBucket();
|
||||
bucket.start();
|
||||
try {
|
||||
//noinspection InfiniteLoopStatement
|
||||
while (true) {
|
||||
Socket s = ss.accept();
|
||||
System.out.println("Incoming connection");
|
||||
@@ -103,6 +104,7 @@ public class DevReportServer {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
//noinspection InfiniteLoopStatement
|
||||
while (true) {
|
||||
// If the bucket isn't full, add a token
|
||||
if (semaphore.availablePermits() < MAX_TOKENS) {
|
||||
@@ -134,6 +136,8 @@ public class DevReportServer {
|
||||
try {
|
||||
socket.setSoTimeout(SOCKET_TIMEOUT_MS);
|
||||
in = getInputStream(socket);
|
||||
// Directory may already exist
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
reportDir.mkdirs();
|
||||
reportFile = createTempFile(FILE_PREFIX, FILE_SUFFIX,
|
||||
reportDir);
|
||||
@@ -153,7 +157,8 @@ public class DevReportServer {
|
||||
System.out.println("Saved " + length + " bytes");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
if (reportFile != null) reportFile.delete();
|
||||
if (reportFile != null && !reportFile.delete())
|
||||
System.err.println("Failed to delete report");
|
||||
} finally {
|
||||
tryToClose(in);
|
||||
tryToClose(out);
|
||||
|
||||
@@ -111,17 +111,15 @@ class DevReporterImpl implements DevReporter, EventListener {
|
||||
LOG.info("Sending reports to developers");
|
||||
for (File f : reports) {
|
||||
OutputStream out = null;
|
||||
InputStream in = null;
|
||||
try {
|
||||
Socket s = connectToDevelopers();
|
||||
out = getOutputStream(s);
|
||||
in = new FileInputStream(f);
|
||||
InputStream in = new FileInputStream(f);
|
||||
copyAndClose(in, out);
|
||||
f.delete();
|
||||
if (!f.delete()) LOG.warning("Failed to delete report");
|
||||
} catch (IOException e) {
|
||||
LOG.log(WARNING, "Failed to send reports", e);
|
||||
tryToClose(out, LOG, WARNING);
|
||||
tryToClose(in, LOG, WARNING);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ class SocksSocket extends Socket {
|
||||
"Address type not supported"
|
||||
};
|
||||
|
||||
@SuppressWarnings("MismatchedReadAndWriteOfArray")
|
||||
private static final byte[] UNSPECIFIED_ADDRESS = new byte[4];
|
||||
|
||||
private final SocketAddress proxy;
|
||||
|
||||
@@ -45,7 +45,7 @@ class SocksSocketFactory extends SocketFactory {
|
||||
|
||||
@Override
|
||||
public Socket createSocket(InetAddress address, int port,
|
||||
InetAddress localAddress, int localPort) throws IOException {
|
||||
InetAddress localAddress, int localPort) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.IoUtils.tryToClose;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
|
||||
@Immutable
|
||||
@@ -43,15 +44,16 @@ class UnixSecureRandomProvider extends AbstractSecureRandomProvider {
|
||||
}
|
||||
|
||||
protected void writeSeed() {
|
||||
DataOutputStream out = null;
|
||||
try {
|
||||
DataOutputStream out = new DataOutputStream(
|
||||
new FileOutputStream(outputDevice));
|
||||
out = new DataOutputStream(new FileOutputStream(outputDevice));
|
||||
writeToEntropyPool(out);
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
// On some devices /dev/urandom isn't writable - this isn't fatal
|
||||
logException(LOG, WARNING, e);
|
||||
} finally {
|
||||
tryToClose(out, LOG, WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.logging.Logger;
|
||||
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.IoUtils.tryToClose;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
|
||||
public class UnixSecureRandomSpi extends SecureRandomSpi {
|
||||
@@ -34,15 +35,16 @@ public class UnixSecureRandomSpi extends SecureRandomSpi {
|
||||
|
||||
@Override
|
||||
protected void engineSetSeed(byte[] seed) {
|
||||
DataOutputStream out = null;
|
||||
try {
|
||||
DataOutputStream out = new DataOutputStream(
|
||||
new FileOutputStream(outputDevice));
|
||||
out = new DataOutputStream(new FileOutputStream(outputDevice));
|
||||
out.write(seed);
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
// On some devices /dev/urandom isn't writable - this isn't fatal
|
||||
logException(LOG, WARNING, e);
|
||||
} finally {
|
||||
tryToClose(out, LOG, WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import static org.junit.Assert.assertEquals;
|
||||
public class EllipticCurveMultiplicationTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testMultiplierProducesSameResultsAsDefault() throws Exception {
|
||||
public void testMultiplierProducesSameResultsAsDefault() {
|
||||
// Instantiate the default implementation of the curve
|
||||
X9ECParameters defaultX9Parameters =
|
||||
TeleTrusTNamedCurves.getByName("brainpoolp256r1");
|
||||
|
||||
@@ -64,7 +64,7 @@ public class KeyAgreementTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRfc7748TestVector() throws Exception {
|
||||
public void testRfc7748TestVector() {
|
||||
// Private keys need to be clamped because curve25519-java does the
|
||||
// clamping at key generation time, not multiplication time
|
||||
byte[] aPriv = Curve25519KeyParser.clamp(fromHexString(ALICE_PRIVATE));
|
||||
|
||||
@@ -23,7 +23,7 @@ public class KeyEncodingAndParsingTest extends BrambleTestCase {
|
||||
new CryptoComponentImpl(new TestSecureRandomProvider(), null);
|
||||
|
||||
@Test
|
||||
public void testAgreementPublicKeyLength() throws Exception {
|
||||
public void testAgreementPublicKeyLength() {
|
||||
// Generate 10 agreement key pairs
|
||||
for (int i = 0; i < 10; i++) {
|
||||
KeyPair keyPair = crypto.generateAgreementKeyPair();
|
||||
@@ -70,7 +70,7 @@ public class KeyEncodingAndParsingTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAgreementKeyParserByFuzzing() throws Exception {
|
||||
public void testAgreementKeyParserByFuzzing() {
|
||||
KeyParser parser = crypto.getAgreementKeyParser();
|
||||
// Generate a key pair to get the proper public key length
|
||||
KeyPair p = crypto.generateAgreementKeyPair();
|
||||
@@ -92,7 +92,7 @@ public class KeyEncodingAndParsingTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSignaturePublicKeyLength() throws Exception {
|
||||
public void testSignaturePublicKeyLength() {
|
||||
// Generate 10 signature key pairs
|
||||
for (int i = 0; i < 10; i++) {
|
||||
KeyPair keyPair = crypto.generateSignatureKeyPair();
|
||||
@@ -159,7 +159,7 @@ public class KeyEncodingAndParsingTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSignatureKeyParserByFuzzing() throws Exception {
|
||||
public void testSignatureKeyParserByFuzzing() {
|
||||
KeyParser parser = crypto.getSignatureKeyParser();
|
||||
// Generate a key pair to get the proper public key length
|
||||
KeyPair p = crypto.generateSignatureKeyPair();
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.junit.Assert.assertEquals;
|
||||
public class ScryptKdfTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testPasswordAffectsKey() throws Exception {
|
||||
public void testPasswordAffectsKey() {
|
||||
PasswordBasedKdf kdf = new ScryptKdf(new SystemClock());
|
||||
byte[] salt = getRandomBytes(32);
|
||||
Set<Bytes> keys = new HashSet<>();
|
||||
@@ -31,7 +31,7 @@ public class ScryptKdfTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaltAffectsKey() throws Exception {
|
||||
public void testSaltAffectsKey() {
|
||||
PasswordBasedKdf kdf = new ScryptKdf(new SystemClock());
|
||||
String password = getRandomString(16);
|
||||
Set<Bytes> keys = new HashSet<>();
|
||||
@@ -43,7 +43,7 @@ public class ScryptKdfTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCostParameterAffectsKey() throws Exception {
|
||||
public void testCostParameterAffectsKey() {
|
||||
PasswordBasedKdf kdf = new ScryptKdf(new SystemClock());
|
||||
String password = getRandomString(16);
|
||||
byte[] salt = getRandomBytes(32);
|
||||
@@ -55,7 +55,7 @@ public class ScryptKdfTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCalibration() throws Exception {
|
||||
public void testCalibration() {
|
||||
Clock clock = new ArrayClock(
|
||||
0, 50, // Duration for cost 256
|
||||
0, 100, // Duration for cost 512
|
||||
@@ -68,7 +68,7 @@ public class ScryptKdfTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCalibrationChoosesMinCost() throws Exception {
|
||||
public void testCalibrationChoosesMinCost() {
|
||||
Clock clock = new ArrayClock(
|
||||
0, 2000 // Duration for cost 256 is already too high
|
||||
);
|
||||
|
||||
@@ -25,7 +25,7 @@ public class TagEncodingTest extends BrambleMockTestCase {
|
||||
private final long streamNumber = 1234567890;
|
||||
|
||||
@Test
|
||||
public void testKeyAffectsTag() throws Exception {
|
||||
public void testKeyAffectsTag() {
|
||||
Set<Bytes> set = new HashSet<>();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
byte[] tag = new byte[TAG_LENGTH];
|
||||
@@ -37,7 +37,7 @@ public class TagEncodingTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProtocolVersionAffectsTag() throws Exception {
|
||||
public void testProtocolVersionAffectsTag() {
|
||||
Set<Bytes> set = new HashSet<>();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
byte[] tag = new byte[TAG_LENGTH];
|
||||
@@ -48,7 +48,7 @@ public class TagEncodingTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreamNumberAffectsTag() throws Exception {
|
||||
public void testStreamNumberAffectsTag() {
|
||||
Set<Bytes> set = new HashSet<>();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
byte[] tag = new byte[TAG_LENGTH];
|
||||
|
||||
@@ -14,8 +14,7 @@ class TestAuthenticatedCipher implements AuthenticatedCipher {
|
||||
private boolean encrypt = false;
|
||||
|
||||
@Override
|
||||
public void init(boolean encrypt, SecretKey key, byte[] iv)
|
||||
throws GeneralSecurityException {
|
||||
public void init(boolean encrypt, SecretKey key, byte[] iv) {
|
||||
this.encrypt = encrypt;
|
||||
}
|
||||
|
||||
|
||||
@@ -557,10 +557,10 @@ public class BdfReaderImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testNestedListWithinDepthLimit() throws Exception {
|
||||
// A list containing a list containing a list containing a list...
|
||||
String lists = "";
|
||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT; i++) lists += "60";
|
||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT; i++) lists += "80";
|
||||
setContents(lists);
|
||||
StringBuilder lists = new StringBuilder();
|
||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT; i++) lists.append("60");
|
||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT; i++) lists.append("80");
|
||||
setContents(lists.toString());
|
||||
r.readList();
|
||||
assertTrue(r.eof());
|
||||
}
|
||||
@@ -568,23 +568,23 @@ public class BdfReaderImplTest extends BrambleTestCase {
|
||||
@Test(expected = FormatException.class)
|
||||
public void testNestedListOutsideDepthLimit() throws Exception {
|
||||
// A list containing a list containing a list containing a list...
|
||||
String lists = "";
|
||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT + 1; i++) lists += "60";
|
||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT + 1; i++) lists += "80";
|
||||
setContents(lists);
|
||||
StringBuilder lists = new StringBuilder();
|
||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT + 1; i++) lists.append("60");
|
||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT + 1; i++) lists.append("80");
|
||||
setContents(lists.toString());
|
||||
r.readList();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedDictionaryWithinDepthLimit() throws Exception {
|
||||
// A dictionary containing a dictionary containing a dictionary...
|
||||
String dicts = "";
|
||||
StringBuilder dicts = new StringBuilder();
|
||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT; i++)
|
||||
dicts += "70" + "41" + "03" + "666F6F";
|
||||
dicts += "11";
|
||||
dicts.append("70" + "41" + "03" + "666F6F");
|
||||
dicts.append("11");
|
||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT; i++)
|
||||
dicts += "80";
|
||||
setContents(dicts);
|
||||
dicts.append("80");
|
||||
setContents(dicts.toString());
|
||||
r.readDictionary();
|
||||
assertTrue(r.eof());
|
||||
}
|
||||
@@ -592,13 +592,13 @@ public class BdfReaderImplTest extends BrambleTestCase {
|
||||
@Test(expected = FormatException.class)
|
||||
public void testNestedDictionaryOutsideDepthLimit() throws Exception {
|
||||
// A dictionary containing a dictionary containing a dictionary...
|
||||
String dicts = "";
|
||||
StringBuilder dicts = new StringBuilder();
|
||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT + 1; i++)
|
||||
dicts += "70" + "41" + "03" + "666F6F";
|
||||
dicts += "11";
|
||||
dicts.append("70" + "41" + "03" + "666F6F");
|
||||
dicts.append("11");
|
||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT + 1; i++)
|
||||
dicts += "80";
|
||||
setContents(dicts);
|
||||
dicts.append("80");
|
||||
setContents(dicts.toString());
|
||||
r.readDictionary();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@SuppressWarnings("TryFinallyCanBeTryWithResources")
|
||||
public abstract class BasicDatabaseTest extends BrambleTestCase {
|
||||
|
||||
private static final int BATCH_SIZE = 100;
|
||||
@@ -47,7 +48,7 @@ public abstract class BasicDatabaseTest extends BrambleTestCase {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
testDir.mkdirs();
|
||||
assertTrue(testDir.mkdirs());
|
||||
Class.forName(getDriverName());
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,7 @@ public class BasicH2Test extends BasicDatabaseTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutdownDatabase(File db, boolean encrypt)
|
||||
throws SQLException {
|
||||
protected void shutdownDatabase(File db, boolean encrypt) {
|
||||
// The DB is closed automatically when the connection is closed
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public abstract class DatabaseMigrationTest extends BrambleMockTestCase {
|
||||
protected final Clock clock = new SystemClock();
|
||||
|
||||
abstract Database<Connection> createDatabase(
|
||||
List<Migration<Connection>> migrations) throws Exception;
|
||||
List<Migration<Connection>> migrations);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
@@ -29,7 +29,8 @@ public abstract class DatabasePerformanceComparisonTest
|
||||
* How many blocks of each condition to compare.
|
||||
*/
|
||||
private static final int COMPARISON_BLOCKS = 10;
|
||||
private SecretKey databaseKey = getSecretKey();
|
||||
|
||||
private final SecretKey databaseKey = getSecretKey();
|
||||
|
||||
abstract Database<Connection> createDatabase(boolean conditionA,
|
||||
DatabaseConfig databaseConfig, MessageFactory messageFactory,
|
||||
|
||||
@@ -20,10 +20,11 @@ import javax.annotation.Nullable;
|
||||
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
||||
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
||||
import static org.briarproject.bramble.util.IoUtils.copyAndClose;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public abstract class DatabaseTraceTest extends DatabasePerformanceTest {
|
||||
|
||||
private SecretKey databaseKey = getSecretKey();
|
||||
private final SecretKey databaseKey = getSecretKey();
|
||||
|
||||
abstract Database<Connection> createDatabase(DatabaseConfig databaseConfig,
|
||||
MessageFactory messageFactory, Clock clock);
|
||||
@@ -39,7 +40,8 @@ public abstract class DatabaseTraceTest extends DatabasePerformanceTest {
|
||||
populateDatabase(db);
|
||||
db.close();
|
||||
File traceFile = getTraceFile();
|
||||
if (traceFile != null) traceFile.delete();
|
||||
if (traceFile != null && traceFile.exists())
|
||||
assertTrue(traceFile.delete());
|
||||
db = openDatabase();
|
||||
task.run(db);
|
||||
db.close();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.briarproject.bramble.db;
|
||||
|
||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.MessageFactory;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.junit.Ignore;
|
||||
@@ -8,9 +9,8 @@ import org.junit.Ignore;
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Ignore
|
||||
@NotNullByDefault
|
||||
public class H2DatabaseTraceTest extends DatabaseTraceTest {
|
||||
|
||||
@Override
|
||||
@@ -18,7 +18,6 @@ public class H2DatabaseTraceTest extends DatabaseTraceTest {
|
||||
MessageFactory messageFactory, Clock clock) {
|
||||
return new H2Database(databaseConfig, messageFactory, clock) {
|
||||
@Override
|
||||
@Nonnull
|
||||
String getUrl() {
|
||||
return super.getUrl() + ";TRACE_LEVEL_FILE=3";
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@SuppressWarnings("TryFinallyCanBeTryWithResources")
|
||||
public class H2TransactionIsolationTest extends BrambleTestCase {
|
||||
|
||||
private static final String DROP_TABLE = "DROP TABLE foo IF EXISTS";
|
||||
@@ -47,7 +48,7 @@ public class H2TransactionIsolationTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
public void tearDown() {
|
||||
deleteTestDirectory(testDir);
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,6 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
// All our transports use a maximum latency of 30 seconds
|
||||
private static final int MAX_LATENCY = 30 * 1000;
|
||||
|
||||
|
||||
private final SecretKey key = getSecretKey();
|
||||
private final File testDir = getTestDirectory();
|
||||
private final GroupId groupId;
|
||||
|
||||
@@ -25,7 +25,7 @@ public abstract class SingleDatabasePerformanceTest
|
||||
abstract Database<Connection> createDatabase(DatabaseConfig databaseConfig,
|
||||
MessageFactory messageFactory, Clock clock);
|
||||
|
||||
private SecretKey databaseKey = getSecretKey();
|
||||
private final SecretKey databaseKey = getSecretKey();
|
||||
|
||||
@Override
|
||||
protected void benchmark(String name,
|
||||
|
||||
@@ -29,7 +29,7 @@ import static org.junit.Assert.assertThat;
|
||||
public class KeyAgreementProtocolTest extends BrambleTestCase {
|
||||
|
||||
@Rule
|
||||
public JUnitRuleMockery context = new JUnitRuleMockery() {{
|
||||
public final JUnitRuleMockery context = new JUnitRuleMockery() {{
|
||||
// So we can mock concrete classes like KeyAgreementTransport
|
||||
setImposteriser(ClassImposteriser.INSTANCE);
|
||||
}};
|
||||
|
||||
@@ -327,6 +327,7 @@ public class LanTcpPluginTest extends BrambleTestCase {
|
||||
assertEquals(0, comparator.compare(linkLocal, linkLocal));
|
||||
}
|
||||
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
private boolean systemHasLocalIpv4Address() throws Exception {
|
||||
for (NetworkInterface i : list(getNetworkInterfaces())) {
|
||||
for (InetAddress a : list(i.getInetAddresses())) {
|
||||
|
||||
@@ -165,7 +165,7 @@ public class SyncRecordReaderImplTest extends BrambleMockTestCase {
|
||||
return new Record(PROTOCOL_VERSION, ACK, createPayload());
|
||||
}
|
||||
|
||||
private Record createEmptyAck() throws Exception {
|
||||
private Record createEmptyAck() {
|
||||
return new Record(PROTOCOL_VERSION, ACK, new byte[0]);
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ public class SyncRecordReaderImplTest extends BrambleMockTestCase {
|
||||
return new Record(PROTOCOL_VERSION, OFFER, createPayload());
|
||||
}
|
||||
|
||||
private Record createEmptyOffer() throws Exception {
|
||||
private Record createEmptyOffer() {
|
||||
return new Record(PROTOCOL_VERSION, OFFER, new byte[0]);
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ public class SyncRecordReaderImplTest extends BrambleMockTestCase {
|
||||
return new Record(PROTOCOL_VERSION, REQUEST, createPayload());
|
||||
}
|
||||
|
||||
private Record createEmptyRequest() throws Exception {
|
||||
private Record createEmptyRequest() {
|
||||
return new Record(PROTOCOL_VERSION, REQUEST, new byte[0]);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.jmock.api.Invocation;
|
||||
public class RunAction implements Action {
|
||||
|
||||
@Override
|
||||
public Object invoke(Invocation invocation) throws Throwable {
|
||||
public Object invoke(Invocation invocation) {
|
||||
Runnable task = (Runnable) invocation.getParameter(0);
|
||||
task.run();
|
||||
return null;
|
||||
|
||||
@@ -10,7 +10,6 @@ public class RunTransactionAction implements Action {
|
||||
|
||||
private final Transaction txn;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public RunTransactionAction(Transaction txn) {
|
||||
this.txn = txn;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.briarproject.bramble.test;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
@@ -7,13 +9,12 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static java.util.Collections.sort;
|
||||
import static org.briarproject.bramble.test.UTest.Result.INCONCLUSIVE;
|
||||
import static org.briarproject.bramble.test.UTest.Result.LARGER;
|
||||
import static org.briarproject.bramble.test.UTest.Result.SMALLER;
|
||||
|
||||
@NotNullByDefault
|
||||
public class UTest {
|
||||
|
||||
public enum Result {
|
||||
@@ -158,8 +159,7 @@ public class UTest {
|
||||
private static List<Double> readFile(String filename) {
|
||||
List<Double> values = new ArrayList<>();
|
||||
try {
|
||||
BufferedReader in;
|
||||
in = new BufferedReader(new FileReader(filename));
|
||||
BufferedReader in = new BufferedReader(new FileReader(filename));
|
||||
String s;
|
||||
while ((s = in.readLine()) != null) values.add(new Double(s));
|
||||
in.close();
|
||||
@@ -185,8 +185,9 @@ public class UTest {
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UseCompareMethod")
|
||||
@Override
|
||||
public int compareTo(@Nonnull Value v) {
|
||||
public int compareTo(Value v) {
|
||||
if (value < v.value) return -1;
|
||||
if (value > v.value) return 1;
|
||||
return 0;
|
||||
|
||||
@@ -33,11 +33,13 @@ public class ByteUtilsTest extends BrambleTestCase {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testReadUint16ValidatesArguments1() {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
readUint16(new byte[1], 0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testReadUint16ValidatesArguments2() {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
readUint16(new byte[2], 1);
|
||||
}
|
||||
|
||||
@@ -55,11 +57,13 @@ public class ByteUtilsTest extends BrambleTestCase {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testReadUint32ValidatesArguments1() {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
readUint32(new byte[3], 0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testReadUint32ValidatesArguments2() {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
readUint32(new byte[4], 1);
|
||||
}
|
||||
|
||||
@@ -79,11 +83,13 @@ public class ByteUtilsTest extends BrambleTestCase {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testReadUint64ValidatesArguments1() {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
readUint64(new byte[7], 0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testReadUint64ValidatesArguments2() {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
readUint64(new byte[8], 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user