mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 13:49:53 +01:00
Code cleanup, complain about lack of unit tests.
This commit is contained in:
@@ -10,6 +10,7 @@ import org.briarproject.util.StringUtils;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import static org.briarproject.api.db.Metadata.REMOVE;
|
||||||
import static org.briarproject.data.Types.DICTIONARY;
|
import static org.briarproject.data.Types.DICTIONARY;
|
||||||
import static org.briarproject.data.Types.END;
|
import static org.briarproject.data.Types.END;
|
||||||
import static org.briarproject.data.Types.FALSE;
|
import static org.briarproject.data.Types.FALSE;
|
||||||
@@ -39,7 +40,7 @@ class MetadataParserImpl implements MetadataParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Object parseObject(byte[] b) throws FormatException {
|
private Object parseObject(byte[] b) throws FormatException {
|
||||||
if (b == null) return null;
|
if (b == REMOVE) return null;
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Object o = parseObject(in);
|
Object o = parseObject(in);
|
||||||
if (in.available() > 0) throw new FormatException();
|
if (in.available() > 0) throw new FormatException();
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ class AliceConnector extends Connector {
|
|||||||
Logger.getLogger(AliceConnector.class.getName());
|
Logger.getLogger(AliceConnector.class.getName());
|
||||||
|
|
||||||
AliceConnector(CryptoComponent crypto,
|
AliceConnector(CryptoComponent crypto,
|
||||||
BdfReaderFactory bdfReaderFactory, BdfWriterFactory bdfWriterFactory,
|
BdfReaderFactory bdfReaderFactory,
|
||||||
|
BdfWriterFactory bdfWriterFactory,
|
||||||
StreamReaderFactory streamReaderFactory,
|
StreamReaderFactory streamReaderFactory,
|
||||||
StreamWriterFactory streamWriterFactory,
|
StreamWriterFactory streamWriterFactory,
|
||||||
AuthorFactory authorFactory, GroupFactory groupFactory,
|
AuthorFactory authorFactory, GroupFactory groupFactory,
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ class BobConnector extends Connector {
|
|||||||
Logger.getLogger(BobConnector.class.getName());
|
Logger.getLogger(BobConnector.class.getName());
|
||||||
|
|
||||||
BobConnector(CryptoComponent crypto,
|
BobConnector(CryptoComponent crypto,
|
||||||
BdfReaderFactory bdfReaderFactory, BdfWriterFactory bdfWriterFactory,
|
BdfReaderFactory bdfReaderFactory,
|
||||||
|
BdfWriterFactory bdfWriterFactory,
|
||||||
StreamReaderFactory streamReaderFactory,
|
StreamReaderFactory streamReaderFactory,
|
||||||
StreamWriterFactory streamWriterFactory,
|
StreamWriterFactory streamWriterFactory,
|
||||||
AuthorFactory authorFactory, GroupFactory groupFactory,
|
AuthorFactory authorFactory, GroupFactory groupFactory,
|
||||||
|
|||||||
@@ -83,7 +83,8 @@ abstract class Connector extends Thread {
|
|||||||
private volatile ContactId contactId = null;
|
private volatile ContactId contactId = null;
|
||||||
|
|
||||||
Connector(CryptoComponent crypto,
|
Connector(CryptoComponent crypto,
|
||||||
BdfReaderFactory bdfReaderFactory, BdfWriterFactory bdfWriterFactory,
|
BdfReaderFactory bdfReaderFactory,
|
||||||
|
BdfWriterFactory bdfWriterFactory,
|
||||||
StreamReaderFactory streamReaderFactory,
|
StreamReaderFactory streamReaderFactory,
|
||||||
StreamWriterFactory streamWriterFactory,
|
StreamWriterFactory streamWriterFactory,
|
||||||
AuthorFactory authorFactory, GroupFactory groupFactory,
|
AuthorFactory authorFactory, GroupFactory groupFactory,
|
||||||
@@ -147,8 +148,8 @@ abstract class Connector extends Thread {
|
|||||||
if (LOG.isLoggable(INFO)) LOG.info(pluginName + " sent key");
|
if (LOG.isLoggable(INFO)) LOG.info(pluginName + " sent key");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected byte[] receivePublicKey(BdfReader r) throws GeneralSecurityException,
|
protected byte[] receivePublicKey(BdfReader r)
|
||||||
IOException {
|
throws GeneralSecurityException, IOException {
|
||||||
byte[] b = r.readRaw(MAX_PUBLIC_KEY_LENGTH);
|
byte[] b = r.readRaw(MAX_PUBLIC_KEY_LENGTH);
|
||||||
keyParser.parsePublicKey(b);
|
keyParser.parsePublicKey(b);
|
||||||
if (LOG.isLoggable(INFO)) LOG.info(pluginName + " received key");
|
if (LOG.isLoggable(INFO)) LOG.info(pluginName + " received key");
|
||||||
@@ -221,7 +222,8 @@ abstract class Connector extends Thread {
|
|||||||
return authorFactory.createAuthor(name, publicKey);
|
return authorFactory.createAuthor(name, publicKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendTimestamp(BdfWriter w, long timestamp) throws IOException {
|
protected void sendTimestamp(BdfWriter w, long timestamp)
|
||||||
|
throws IOException {
|
||||||
w.writeInteger(timestamp);
|
w.writeInteger(timestamp);
|
||||||
w.flush();
|
w.flush();
|
||||||
if (LOG.isLoggable(INFO)) LOG.info(pluginName + " sent timestamp");
|
if (LOG.isLoggable(INFO)) LOG.info(pluginName + " sent timestamp");
|
||||||
@@ -236,7 +238,8 @@ abstract class Connector extends Thread {
|
|||||||
|
|
||||||
protected void sendTransportProperties(BdfWriter w) throws IOException {
|
protected void sendTransportProperties(BdfWriter w) throws IOException {
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
for (Entry<TransportId, TransportProperties> e : localProps.entrySet()) {
|
for (Entry<TransportId, TransportProperties> e :
|
||||||
|
localProps.entrySet()) {
|
||||||
w.writeString(e.getKey().getString());
|
w.writeString(e.getKey().getString());
|
||||||
w.writeDictionary(e.getValue());
|
w.writeDictionary(e.getValue());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,8 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
private String remoteName = null;
|
private String remoteName = null;
|
||||||
|
|
||||||
ConnectorGroup(CryptoComponent crypto,
|
ConnectorGroup(CryptoComponent crypto,
|
||||||
BdfReaderFactory bdfReaderFactory, BdfWriterFactory bdfWriterFactory,
|
BdfReaderFactory bdfReaderFactory,
|
||||||
|
BdfWriterFactory bdfWriterFactory,
|
||||||
StreamReaderFactory streamReaderFactory,
|
StreamReaderFactory streamReaderFactory,
|
||||||
StreamWriterFactory streamWriterFactory,
|
StreamWriterFactory streamWriterFactory,
|
||||||
AuthorFactory authorFactory, GroupFactory groupFactory,
|
AuthorFactory authorFactory, GroupFactory groupFactory,
|
||||||
|
|||||||
@@ -107,6 +107,8 @@
|
|||||||
<test name='org.briarproject.crypto.XSalsa20Poly1305AuthenticatedCipherTest'/>
|
<test name='org.briarproject.crypto.XSalsa20Poly1305AuthenticatedCipherTest'/>
|
||||||
<test name='org.briarproject.data.BdfReaderImplTest'/>
|
<test name='org.briarproject.data.BdfReaderImplTest'/>
|
||||||
<test name='org.briarproject.data.BdfWriterImplTest'/>
|
<test name='org.briarproject.data.BdfWriterImplTest'/>
|
||||||
|
<test name='org.briarproject.data.MetadataEncoderImplTest'/>
|
||||||
|
<test name='org.briarproject.data.MetadataParserImplTest'/>
|
||||||
<test name='org.briarproject.db.BasicH2Test'/>
|
<test name='org.briarproject.db.BasicH2Test'/>
|
||||||
<test name='org.briarproject.db.DatabaseComponentImplTest'/>
|
<test name='org.briarproject.db.DatabaseComponentImplTest'/>
|
||||||
<test name='org.briarproject.db.ExponentialBackoffTest'/>
|
<test name='org.briarproject.db.ExponentialBackoffTest'/>
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ public class LockFairnessTest extends BriarTestCase {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
first.start();
|
first.start();
|
||||||
// BdfWriter
|
// Writer
|
||||||
Thread writer = new Thread() {
|
Thread writer = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package org.briarproject.data;
|
||||||
|
|
||||||
|
import org.briarproject.BriarTestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
public class MetadataEncoderImplTest extends BriarTestCase {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnitTestsExist() {
|
||||||
|
fail(); // FIXME: Write tests
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package org.briarproject.data;
|
||||||
|
|
||||||
|
import org.briarproject.BriarTestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
public class MetadataParserImplTest extends BriarTestCase {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnitTestsExist() {
|
||||||
|
fail(); // FIXME: Write tests
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,8 +23,7 @@ public class ConsumersTest extends BriarTestCase {
|
|||||||
messageDigest.update(data);
|
messageDigest.update(data);
|
||||||
byte[] dig = messageDigest.digest();
|
byte[] dig = messageDigest.digest();
|
||||||
// Check that feeding a DigestingConsumer generates the same digest
|
// Check that feeding a DigestingConsumer generates the same digest
|
||||||
org.briarproject.sync.DigestingConsumer
|
DigestingConsumer dc = new DigestingConsumer(messageDigest);
|
||||||
dc = new org.briarproject.sync.DigestingConsumer(messageDigest);
|
|
||||||
dc.write(data[0]);
|
dc.write(data[0]);
|
||||||
dc.write(data, 1, data.length - 2);
|
dc.write(data, 1, data.length - 2);
|
||||||
dc.write(data[data.length - 1]);
|
dc.write(data[data.length - 1]);
|
||||||
@@ -35,8 +34,7 @@ public class ConsumersTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testCountingConsumer() throws Exception {
|
public void testCountingConsumer() throws Exception {
|
||||||
byte[] data = new byte[1234];
|
byte[] data = new byte[1234];
|
||||||
org.briarproject.sync.CountingConsumer
|
CountingConsumer cc = new CountingConsumer(data.length);
|
||||||
cc = new org.briarproject.sync.CountingConsumer(data.length);
|
|
||||||
cc.write(data[0]);
|
cc.write(data[0]);
|
||||||
cc.write(data, 1, data.length - 2);
|
cc.write(data, 1, data.length - 2);
|
||||||
cc.write(data[data.length - 1]);
|
cc.write(data[data.length - 1]);
|
||||||
@@ -54,8 +52,7 @@ public class ConsumersTest extends BriarTestCase {
|
|||||||
byte[] data = new byte[1234];
|
byte[] data = new byte[1234];
|
||||||
new Random().nextBytes(data);
|
new Random().nextBytes(data);
|
||||||
// Check that a CopyingConsumer creates a faithful copy
|
// Check that a CopyingConsumer creates a faithful copy
|
||||||
org.briarproject.sync.CopyingConsumer
|
CopyingConsumer cc = new CopyingConsumer();
|
||||||
cc = new org.briarproject.sync.CopyingConsumer();
|
|
||||||
cc.write(data[0]);
|
cc.write(data[0]);
|
||||||
cc.write(data, 1, data.length - 2);
|
cc.write(data, 1, data.length - 2);
|
||||||
cc.write(data[data.length - 1]);
|
cc.write(data[data.length - 1]);
|
||||||
|
|||||||
@@ -43,9 +43,7 @@ public class PacketReaderImplTest extends BriarTestCase {
|
|||||||
public void testFormatExceptionIfAckIsTooLarge() throws Exception {
|
public void testFormatExceptionIfAckIsTooLarge() throws Exception {
|
||||||
byte[] b = createAck(true);
|
byte[] b = createAck(true);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
org.briarproject.sync.PacketReaderImpl
|
PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null,
|
||||||
reader = new org.briarproject.sync.PacketReaderImpl(
|
|
||||||
bdfReaderFactory, null,
|
|
||||||
null, in);
|
null, in);
|
||||||
try {
|
try {
|
||||||
reader.readAck();
|
reader.readAck();
|
||||||
@@ -59,9 +57,7 @@ public class PacketReaderImplTest extends BriarTestCase {
|
|||||||
public void testNoFormatExceptionIfAckIsMaximumSize() throws Exception {
|
public void testNoFormatExceptionIfAckIsMaximumSize() throws Exception {
|
||||||
byte[] b = createAck(false);
|
byte[] b = createAck(false);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
org.briarproject.sync.PacketReaderImpl
|
PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null,
|
||||||
reader = new org.briarproject.sync.PacketReaderImpl(
|
|
||||||
bdfReaderFactory, null,
|
|
||||||
null, in);
|
null, in);
|
||||||
reader.readAck();
|
reader.readAck();
|
||||||
}
|
}
|
||||||
@@ -70,9 +66,7 @@ public class PacketReaderImplTest extends BriarTestCase {
|
|||||||
public void testEmptyAck() throws Exception {
|
public void testEmptyAck() throws Exception {
|
||||||
byte[] b = createEmptyAck();
|
byte[] b = createEmptyAck();
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
org.briarproject.sync.PacketReaderImpl
|
PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null,
|
||||||
reader = new org.briarproject.sync.PacketReaderImpl(
|
|
||||||
bdfReaderFactory, null,
|
|
||||||
null, in);
|
null, in);
|
||||||
try {
|
try {
|
||||||
reader.readAck();
|
reader.readAck();
|
||||||
@@ -86,9 +80,7 @@ public class PacketReaderImplTest extends BriarTestCase {
|
|||||||
public void testFormatExceptionIfOfferIsTooLarge() throws Exception {
|
public void testFormatExceptionIfOfferIsTooLarge() throws Exception {
|
||||||
byte[] b = createOffer(true);
|
byte[] b = createOffer(true);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
org.briarproject.sync.PacketReaderImpl
|
PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null,
|
||||||
reader = new org.briarproject.sync.PacketReaderImpl(
|
|
||||||
bdfReaderFactory, null,
|
|
||||||
null, in);
|
null, in);
|
||||||
try {
|
try {
|
||||||
reader.readOffer();
|
reader.readOffer();
|
||||||
@@ -102,8 +94,8 @@ public class PacketReaderImplTest extends BriarTestCase {
|
|||||||
public void testNoFormatExceptionIfOfferIsMaximumSize() throws Exception {
|
public void testNoFormatExceptionIfOfferIsMaximumSize() throws Exception {
|
||||||
byte[] b = createOffer(false);
|
byte[] b = createOffer(false);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
org.briarproject.sync.PacketReaderImpl
|
PacketReaderImpl
|
||||||
reader = new org.briarproject.sync.PacketReaderImpl(
|
reader = new PacketReaderImpl(
|
||||||
bdfReaderFactory, null,
|
bdfReaderFactory, null,
|
||||||
null, in);
|
null, in);
|
||||||
reader.readOffer();
|
reader.readOffer();
|
||||||
@@ -113,9 +105,7 @@ public class PacketReaderImplTest extends BriarTestCase {
|
|||||||
public void testEmptyOffer() throws Exception {
|
public void testEmptyOffer() throws Exception {
|
||||||
byte[] b = createEmptyOffer();
|
byte[] b = createEmptyOffer();
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
org.briarproject.sync.PacketReaderImpl
|
PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null,
|
||||||
reader = new org.briarproject.sync.PacketReaderImpl(
|
|
||||||
bdfReaderFactory, null,
|
|
||||||
null, in);
|
null, in);
|
||||||
try {
|
try {
|
||||||
reader.readOffer();
|
reader.readOffer();
|
||||||
@@ -129,9 +119,7 @@ public class PacketReaderImplTest extends BriarTestCase {
|
|||||||
public void testFormatExceptionIfRequestIsTooLarge() throws Exception {
|
public void testFormatExceptionIfRequestIsTooLarge() throws Exception {
|
||||||
byte[] b = createRequest(true);
|
byte[] b = createRequest(true);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
org.briarproject.sync.PacketReaderImpl
|
PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null,
|
||||||
reader = new org.briarproject.sync.PacketReaderImpl(
|
|
||||||
bdfReaderFactory, null,
|
|
||||||
null, in);
|
null, in);
|
||||||
try {
|
try {
|
||||||
reader.readRequest();
|
reader.readRequest();
|
||||||
@@ -145,9 +133,7 @@ public class PacketReaderImplTest extends BriarTestCase {
|
|||||||
public void testNoFormatExceptionIfRequestIsMaximumSize() throws Exception {
|
public void testNoFormatExceptionIfRequestIsMaximumSize() throws Exception {
|
||||||
byte[] b = createRequest(false);
|
byte[] b = createRequest(false);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
org.briarproject.sync.PacketReaderImpl
|
PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null,
|
||||||
reader = new org.briarproject.sync.PacketReaderImpl(
|
|
||||||
bdfReaderFactory, null,
|
|
||||||
null, in);
|
null, in);
|
||||||
reader.readRequest();
|
reader.readRequest();
|
||||||
}
|
}
|
||||||
@@ -156,9 +142,7 @@ public class PacketReaderImplTest extends BriarTestCase {
|
|||||||
public void testEmptyRequest() throws Exception {
|
public void testEmptyRequest() throws Exception {
|
||||||
byte[] b = createEmptyRequest();
|
byte[] b = createEmptyRequest();
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
org.briarproject.sync.PacketReaderImpl
|
PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null,
|
||||||
reader = new org.briarproject.sync.PacketReaderImpl(
|
|
||||||
bdfReaderFactory, null,
|
|
||||||
null, in);
|
null, in);
|
||||||
try {
|
try {
|
||||||
reader.readRequest();
|
reader.readRequest();
|
||||||
|
|||||||
@@ -46,8 +46,7 @@ public class SimplexOutgoingSessionTest extends BriarTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNothingToSend() throws Exception {
|
public void testNothingToSend() throws Exception {
|
||||||
final org.briarproject.sync.SimplexOutgoingSession
|
final SimplexOutgoingSession session = new SimplexOutgoingSession(db,
|
||||||
session = new org.briarproject.sync.SimplexOutgoingSession(db,
|
|
||||||
dbExecutor, eventBus, contactId, transportId, maxLatency,
|
dbExecutor, eventBus, contactId, transportId, maxLatency,
|
||||||
packetWriter);
|
packetWriter);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
@@ -87,8 +86,7 @@ public class SimplexOutgoingSessionTest extends BriarTestCase {
|
|||||||
public void testSomethingToSend() throws Exception {
|
public void testSomethingToSend() throws Exception {
|
||||||
final Ack ack = new Ack(Collections.singletonList(messageId));
|
final Ack ack = new Ack(Collections.singletonList(messageId));
|
||||||
final byte[] raw = new byte[1234];
|
final byte[] raw = new byte[1234];
|
||||||
final org.briarproject.sync.SimplexOutgoingSession
|
final SimplexOutgoingSession session = new SimplexOutgoingSession(db,
|
||||||
session = new org.briarproject.sync.SimplexOutgoingSession(db,
|
|
||||||
dbExecutor, eventBus, contactId, transportId, maxLatency,
|
dbExecutor, eventBus, contactId, transportId, maxLatency,
|
||||||
packetWriter);
|
packetWriter);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
|
|||||||
Reference in New Issue
Block a user