mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Code cleanup: import static.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package net.sf.briar.db;
|
||||
|
||||
import static net.sf.briar.db.DatabaseConstants.RETRANSMIT_THRESHOLD;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import java.io.File;
|
||||
@@ -705,7 +706,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testRetransmission() throws Exception {
|
||||
BatchId[] ids = new BatchId[DatabaseConstants.RETRANSMIT_THRESHOLD + 5];
|
||||
BatchId[] ids = new BatchId[RETRANSMIT_THRESHOLD + 5];
|
||||
for(int i = 0; i < ids.length; i++) {
|
||||
ids[i] = new BatchId(TestUtils.getRandomId());
|
||||
}
|
||||
@@ -724,7 +725,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// The contact acks the batches in reverse order. The first
|
||||
// RETRANSMIT_THRESHOLD - 1 acks should not trigger any retransmissions
|
||||
for(int i = 0; i < DatabaseConstants.RETRANSMIT_THRESHOLD - 1; i++) {
|
||||
for(int i = 0; i < RETRANSMIT_THRESHOLD - 1; i++) {
|
||||
db.removeAckedBatch(txn, contactId, ids[ids.length - i - 1]);
|
||||
Collection<BatchId> lost = db.getLostBatches(txn, contactId);
|
||||
assertEquals(Collections.emptyList(), lost);
|
||||
@@ -732,7 +733,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// The next ack should trigger the retransmission of the remaining
|
||||
// five outstanding batches
|
||||
int index = ids.length - DatabaseConstants.RETRANSMIT_THRESHOLD;
|
||||
int index = ids.length - RETRANSMIT_THRESHOLD;
|
||||
db.removeAckedBatch(txn, contactId, ids[index]);
|
||||
Collection<BatchId> lost = db.getLostBatches(txn, contactId);
|
||||
for(int i = 0; i < index; i++) {
|
||||
@@ -745,7 +746,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testNoRetransmission() throws Exception {
|
||||
BatchId[] ids = new BatchId[DatabaseConstants.RETRANSMIT_THRESHOLD * 2];
|
||||
BatchId[] ids = new BatchId[RETRANSMIT_THRESHOLD * 2];
|
||||
for(int i = 0; i < ids.length; i++) {
|
||||
ids[i] = new BatchId(TestUtils.getRandomId());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.sf.briar.plugins.file;
|
||||
|
||||
import static net.sf.briar.api.transport.TransportConstants.MIN_CONNECTION_LENGTH;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import java.io.File;
|
||||
@@ -15,7 +16,6 @@ import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.plugins.simplex.SimplexPluginCallback;
|
||||
import net.sf.briar.api.plugins.simplex.SimplexTransportWriter;
|
||||
import net.sf.briar.api.transport.TransportConstants;
|
||||
import net.sf.briar.plugins.ImmediateExecutor;
|
||||
import net.sf.briar.plugins.file.RemovableDriveMonitor.Callback;
|
||||
|
||||
@@ -360,10 +360,10 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
||||
|
||||
File f = new File(testDir, "abcdefgh.dat");
|
||||
OutputStream out = new FileOutputStream(f);
|
||||
out.write(new byte[TransportConstants.MIN_CONNECTION_LENGTH]);
|
||||
out.write(new byte[MIN_CONNECTION_LENGTH]);
|
||||
out.flush();
|
||||
out.close();
|
||||
assertEquals(TransportConstants.MIN_CONNECTION_LENGTH, f.length());
|
||||
assertEquals(MIN_CONNECTION_LENGTH, f.length());
|
||||
plugin.driveInserted(testDir);
|
||||
|
||||
context.assertIsSatisfied();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.sf.briar.protocol;
|
||||
|
||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Collection;
|
||||
@@ -9,7 +11,6 @@ import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.FormatException;
|
||||
import net.sf.briar.api.protocol.Ack;
|
||||
import net.sf.briar.api.protocol.PacketFactory;
|
||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
import net.sf.briar.api.serial.ReaderFactory;
|
||||
@@ -103,12 +104,12 @@ public class AckReaderTest extends BriarTestCase {
|
||||
w.writeStructId(Types.ACK);
|
||||
w.writeListStart();
|
||||
while(out.size() + serial.getSerialisedUniqueIdLength()
|
||||
< ProtocolConstants.MAX_PACKET_LENGTH) {
|
||||
< MAX_PACKET_LENGTH) {
|
||||
w.writeBytes(TestUtils.getRandomId());
|
||||
}
|
||||
if(tooBig) w.writeBytes(TestUtils.getRandomId());
|
||||
w.writeListEnd();
|
||||
assertEquals(tooBig, out.size() > ProtocolConstants.MAX_PACKET_LENGTH);
|
||||
assertEquals(tooBig, out.size() > MAX_PACKET_LENGTH);
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.sf.briar.protocol;
|
||||
|
||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -7,12 +9,11 @@ import java.util.Collections;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.api.FormatException;
|
||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.protocol.UnverifiedBatch;
|
||||
import net.sf.briar.api.serial.StructReader;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
import net.sf.briar.api.serial.ReaderFactory;
|
||||
import net.sf.briar.api.serial.StructReader;
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
import net.sf.briar.api.serial.WriterFactory;
|
||||
import net.sf.briar.serial.SerialModule;
|
||||
@@ -50,7 +51,7 @@ public class BatchReaderTest extends BriarTestCase {
|
||||
context.mock(UnverifiedBatchFactory.class);
|
||||
BatchReader batchReader = new BatchReader(messageReader, batchFactory);
|
||||
|
||||
byte[] b = createBatch(ProtocolConstants.MAX_PACKET_LENGTH + 1);
|
||||
byte[] b = createBatch(MAX_PACKET_LENGTH + 1);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
Reader reader = readerFactory.createReader(in);
|
||||
reader.addStructReader(Types.BATCH, batchReader);
|
||||
@@ -74,7 +75,7 @@ public class BatchReaderTest extends BriarTestCase {
|
||||
will(returnValue(batch));
|
||||
}});
|
||||
|
||||
byte[] b = createBatch(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||
byte[] b = createBatch(MAX_PACKET_LENGTH);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
Reader reader = readerFactory.createReader(in);
|
||||
reader.addStructReader(Types.BATCH, batchReader);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.sf.briar.protocol;
|
||||
|
||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Collection;
|
||||
@@ -9,7 +11,6 @@ import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.FormatException;
|
||||
import net.sf.briar.api.protocol.Offer;
|
||||
import net.sf.briar.api.protocol.PacketFactory;
|
||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
import net.sf.briar.api.serial.ReaderFactory;
|
||||
@@ -103,12 +104,12 @@ public class OfferReaderTest extends BriarTestCase {
|
||||
w.writeStructId(Types.OFFER);
|
||||
w.writeListStart();
|
||||
while(out.size() + serial.getSerialisedUniqueIdLength()
|
||||
< ProtocolConstants.MAX_PACKET_LENGTH) {
|
||||
< MAX_PACKET_LENGTH) {
|
||||
w.writeBytes(TestUtils.getRandomId());
|
||||
}
|
||||
if(tooBig) w.writeBytes(TestUtils.getRandomId());
|
||||
w.writeListEnd();
|
||||
assertEquals(tooBig, out.size() > ProtocolConstants.MAX_PACKET_LENGTH);
|
||||
assertEquals(tooBig, out.size() > MAX_PACKET_LENGTH);
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.sf.briar.protocol;
|
||||
|
||||
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.BitSet;
|
||||
@@ -7,7 +9,6 @@ import java.util.BitSet;
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.api.FormatException;
|
||||
import net.sf.briar.api.protocol.PacketFactory;
|
||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||
import net.sf.briar.api.protocol.Request;
|
||||
import net.sf.briar.api.protocol.Types;
|
||||
import net.sf.briar.api.serial.Reader;
|
||||
@@ -125,12 +126,12 @@ public class RequestReaderTest extends BriarTestCase {
|
||||
// Allow one byte for the REQUEST tag, one byte for the padding length
|
||||
// as a uint7, one byte for the BYTES tag, and five bytes for the
|
||||
// length of the byte array as an int32
|
||||
int size = ProtocolConstants.MAX_PACKET_LENGTH - 8;
|
||||
int size = MAX_PACKET_LENGTH - 8;
|
||||
if(tooBig) size++;
|
||||
assertTrue(size > Short.MAX_VALUE);
|
||||
w.writeUint7((byte) 0);
|
||||
w.writeBytes(new byte[size]);
|
||||
assertEquals(tooBig, out.size() > ProtocolConstants.MAX_PACKET_LENGTH);
|
||||
assertEquals(tooBig, out.size() > MAX_PACKET_LENGTH);
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package net.sf.briar.transport;
|
||||
|
||||
import static net.sf.briar.util.ByteUtils.MAX_32_BIT_UNSIGNED;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.api.transport.ConnectionWindow;
|
||||
import net.sf.briar.util.ByteUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -45,13 +46,11 @@ public class ConnectionWindowImplTest extends BriarTestCase {
|
||||
} catch(IllegalArgumentException expected) {}
|
||||
// Values greater than 2^32 - 1 should never be allowed
|
||||
Set<Long> unseen = new HashSet<Long>();
|
||||
for(int i = 0; i < 32; i++) {
|
||||
unseen.add(ByteUtils.MAX_32_BIT_UNSIGNED - i);
|
||||
}
|
||||
for(int i = 0; i < 32; i++) unseen.add(MAX_32_BIT_UNSIGNED - i);
|
||||
w = new ConnectionWindowImpl(unseen);
|
||||
w.setSeen(ByteUtils.MAX_32_BIT_UNSIGNED);
|
||||
w.setSeen(MAX_32_BIT_UNSIGNED);
|
||||
try {
|
||||
w.setSeen(ByteUtils.MAX_32_BIT_UNSIGNED + 1);
|
||||
w.setSeen(MAX_32_BIT_UNSIGNED + 1);
|
||||
fail();
|
||||
} catch(IllegalArgumentException expected) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user