From a847b30ed3b146decefbc57165b1f28f293361ea Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Tue, 5 Jan 2016 11:32:24 +0000 Subject: [PATCH] Code cleanup, complain about lack of unit tests. --- .../briarproject/data/MetadataParserImpl.java | 3 +- .../invitation/AliceConnector.java | 3 +- .../briarproject/invitation/BobConnector.java | 3 +- .../briarproject/invitation/Connector.java | 13 ++++--- .../invitation/ConnectorGroup.java | 3 +- briar-tests/build.xml | 2 ++ .../org/briarproject/LockFairnessTest.java | 2 +- .../data/MetadataEncoderImplTest.java | 14 ++++++++ .../data/MetadataParserImplTest.java | 14 ++++++++ .../org/briarproject/sync/ConsumersTest.java | 9 ++--- .../sync/PacketReaderImplTest.java | 36 ++++++------------- .../sync/SimplexOutgoingSessionTest.java | 6 ++-- 12 files changed, 62 insertions(+), 46 deletions(-) create mode 100644 briar-tests/src/org/briarproject/data/MetadataEncoderImplTest.java create mode 100644 briar-tests/src/org/briarproject/data/MetadataParserImplTest.java diff --git a/briar-core/src/org/briarproject/data/MetadataParserImpl.java b/briar-core/src/org/briarproject/data/MetadataParserImpl.java index ff9258f149..e4624dc603 100644 --- a/briar-core/src/org/briarproject/data/MetadataParserImpl.java +++ b/briar-core/src/org/briarproject/data/MetadataParserImpl.java @@ -10,6 +10,7 @@ import org.briarproject.util.StringUtils; import java.io.ByteArrayInputStream; 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.END; import static org.briarproject.data.Types.FALSE; @@ -39,7 +40,7 @@ class MetadataParserImpl implements MetadataParser { } private Object parseObject(byte[] b) throws FormatException { - if (b == null) return null; + if (b == REMOVE) return null; ByteArrayInputStream in = new ByteArrayInputStream(b); Object o = parseObject(in); if (in.available() > 0) throw new FormatException(); diff --git a/briar-core/src/org/briarproject/invitation/AliceConnector.java b/briar-core/src/org/briarproject/invitation/AliceConnector.java index c282dff575..794f542ec7 100644 --- a/briar-core/src/org/briarproject/invitation/AliceConnector.java +++ b/briar-core/src/org/briarproject/invitation/AliceConnector.java @@ -42,7 +42,8 @@ class AliceConnector extends Connector { Logger.getLogger(AliceConnector.class.getName()); AliceConnector(CryptoComponent crypto, - BdfReaderFactory bdfReaderFactory, BdfWriterFactory bdfWriterFactory, + BdfReaderFactory bdfReaderFactory, + BdfWriterFactory bdfWriterFactory, StreamReaderFactory streamReaderFactory, StreamWriterFactory streamWriterFactory, AuthorFactory authorFactory, GroupFactory groupFactory, diff --git a/briar-core/src/org/briarproject/invitation/BobConnector.java b/briar-core/src/org/briarproject/invitation/BobConnector.java index 55bb7da882..270ecfbf19 100644 --- a/briar-core/src/org/briarproject/invitation/BobConnector.java +++ b/briar-core/src/org/briarproject/invitation/BobConnector.java @@ -42,7 +42,8 @@ class BobConnector extends Connector { Logger.getLogger(BobConnector.class.getName()); BobConnector(CryptoComponent crypto, - BdfReaderFactory bdfReaderFactory, BdfWriterFactory bdfWriterFactory, + BdfReaderFactory bdfReaderFactory, + BdfWriterFactory bdfWriterFactory, StreamReaderFactory streamReaderFactory, StreamWriterFactory streamWriterFactory, AuthorFactory authorFactory, GroupFactory groupFactory, diff --git a/briar-core/src/org/briarproject/invitation/Connector.java b/briar-core/src/org/briarproject/invitation/Connector.java index ae1af77f36..bd2d8a3254 100644 --- a/briar-core/src/org/briarproject/invitation/Connector.java +++ b/briar-core/src/org/briarproject/invitation/Connector.java @@ -83,7 +83,8 @@ abstract class Connector extends Thread { private volatile ContactId contactId = null; Connector(CryptoComponent crypto, - BdfReaderFactory bdfReaderFactory, BdfWriterFactory bdfWriterFactory, + BdfReaderFactory bdfReaderFactory, + BdfWriterFactory bdfWriterFactory, StreamReaderFactory streamReaderFactory, StreamWriterFactory streamWriterFactory, AuthorFactory authorFactory, GroupFactory groupFactory, @@ -147,8 +148,8 @@ abstract class Connector extends Thread { if (LOG.isLoggable(INFO)) LOG.info(pluginName + " sent key"); } - protected byte[] receivePublicKey(BdfReader r) throws GeneralSecurityException, - IOException { + protected byte[] receivePublicKey(BdfReader r) + throws GeneralSecurityException, IOException { byte[] b = r.readRaw(MAX_PUBLIC_KEY_LENGTH); keyParser.parsePublicKey(b); if (LOG.isLoggable(INFO)) LOG.info(pluginName + " received key"); @@ -221,7 +222,8 @@ abstract class Connector extends Thread { 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.flush(); 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 { w.writeListStart(); - for (Entry<TransportId, TransportProperties> e : localProps.entrySet()) { + for (Entry<TransportId, TransportProperties> e : + localProps.entrySet()) { w.writeString(e.getKey().getString()); w.writeDictionary(e.getValue()); } diff --git a/briar-core/src/org/briarproject/invitation/ConnectorGroup.java b/briar-core/src/org/briarproject/invitation/ConnectorGroup.java index 863c24ed74..378fc54a5b 100644 --- a/briar-core/src/org/briarproject/invitation/ConnectorGroup.java +++ b/briar-core/src/org/briarproject/invitation/ConnectorGroup.java @@ -78,7 +78,8 @@ class ConnectorGroup extends Thread implements InvitationTask { private String remoteName = null; ConnectorGroup(CryptoComponent crypto, - BdfReaderFactory bdfReaderFactory, BdfWriterFactory bdfWriterFactory, + BdfReaderFactory bdfReaderFactory, + BdfWriterFactory bdfWriterFactory, StreamReaderFactory streamReaderFactory, StreamWriterFactory streamWriterFactory, AuthorFactory authorFactory, GroupFactory groupFactory, diff --git a/briar-tests/build.xml b/briar-tests/build.xml index bf96f04c59..29cc7dce91 100644 --- a/briar-tests/build.xml +++ b/briar-tests/build.xml @@ -107,6 +107,8 @@ <test name='org.briarproject.crypto.XSalsa20Poly1305AuthenticatedCipherTest'/> <test name='org.briarproject.data.BdfReaderImplTest'/> <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.DatabaseComponentImplTest'/> <test name='org.briarproject.db.ExponentialBackoffTest'/> diff --git a/briar-tests/src/org/briarproject/LockFairnessTest.java b/briar-tests/src/org/briarproject/LockFairnessTest.java index d8edd213e2..7daaf557e0 100644 --- a/briar-tests/src/org/briarproject/LockFairnessTest.java +++ b/briar-tests/src/org/briarproject/LockFairnessTest.java @@ -108,7 +108,7 @@ public class LockFairnessTest extends BriarTestCase { } }; first.start(); - // BdfWriter + // Writer Thread writer = new Thread() { @Override public void run() { diff --git a/briar-tests/src/org/briarproject/data/MetadataEncoderImplTest.java b/briar-tests/src/org/briarproject/data/MetadataEncoderImplTest.java new file mode 100644 index 0000000000..c0ab879def --- /dev/null +++ b/briar-tests/src/org/briarproject/data/MetadataEncoderImplTest.java @@ -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 + } +} diff --git a/briar-tests/src/org/briarproject/data/MetadataParserImplTest.java b/briar-tests/src/org/briarproject/data/MetadataParserImplTest.java new file mode 100644 index 0000000000..5e3518fb50 --- /dev/null +++ b/briar-tests/src/org/briarproject/data/MetadataParserImplTest.java @@ -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 + } +} diff --git a/briar-tests/src/org/briarproject/sync/ConsumersTest.java b/briar-tests/src/org/briarproject/sync/ConsumersTest.java index a9d4ed67ba..f8e3bfe4d7 100644 --- a/briar-tests/src/org/briarproject/sync/ConsumersTest.java +++ b/briar-tests/src/org/briarproject/sync/ConsumersTest.java @@ -23,8 +23,7 @@ public class ConsumersTest extends BriarTestCase { messageDigest.update(data); byte[] dig = messageDigest.digest(); // Check that feeding a DigestingConsumer generates the same digest - org.briarproject.sync.DigestingConsumer - dc = new org.briarproject.sync.DigestingConsumer(messageDigest); + DigestingConsumer dc = new DigestingConsumer(messageDigest); dc.write(data[0]); dc.write(data, 1, data.length - 2); dc.write(data[data.length - 1]); @@ -35,8 +34,7 @@ public class ConsumersTest extends BriarTestCase { @Test public void testCountingConsumer() throws Exception { byte[] data = new byte[1234]; - org.briarproject.sync.CountingConsumer - cc = new org.briarproject.sync.CountingConsumer(data.length); + CountingConsumer cc = new CountingConsumer(data.length); cc.write(data[0]); cc.write(data, 1, data.length - 2); cc.write(data[data.length - 1]); @@ -54,8 +52,7 @@ public class ConsumersTest extends BriarTestCase { byte[] data = new byte[1234]; new Random().nextBytes(data); // Check that a CopyingConsumer creates a faithful copy - org.briarproject.sync.CopyingConsumer - cc = new org.briarproject.sync.CopyingConsumer(); + CopyingConsumer cc = new CopyingConsumer(); cc.write(data[0]); cc.write(data, 1, data.length - 2); cc.write(data[data.length - 1]); diff --git a/briar-tests/src/org/briarproject/sync/PacketReaderImplTest.java b/briar-tests/src/org/briarproject/sync/PacketReaderImplTest.java index ac38110834..314bf4bd3b 100644 --- a/briar-tests/src/org/briarproject/sync/PacketReaderImplTest.java +++ b/briar-tests/src/org/briarproject/sync/PacketReaderImplTest.java @@ -43,9 +43,7 @@ public class PacketReaderImplTest extends BriarTestCase { public void testFormatExceptionIfAckIsTooLarge() throws Exception { byte[] b = createAck(true); ByteArrayInputStream in = new ByteArrayInputStream(b); - org.briarproject.sync.PacketReaderImpl - reader = new org.briarproject.sync.PacketReaderImpl( - bdfReaderFactory, null, + PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null, null, in); try { reader.readAck(); @@ -59,9 +57,7 @@ public class PacketReaderImplTest extends BriarTestCase { public void testNoFormatExceptionIfAckIsMaximumSize() throws Exception { byte[] b = createAck(false); ByteArrayInputStream in = new ByteArrayInputStream(b); - org.briarproject.sync.PacketReaderImpl - reader = new org.briarproject.sync.PacketReaderImpl( - bdfReaderFactory, null, + PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null, null, in); reader.readAck(); } @@ -70,9 +66,7 @@ public class PacketReaderImplTest extends BriarTestCase { public void testEmptyAck() throws Exception { byte[] b = createEmptyAck(); ByteArrayInputStream in = new ByteArrayInputStream(b); - org.briarproject.sync.PacketReaderImpl - reader = new org.briarproject.sync.PacketReaderImpl( - bdfReaderFactory, null, + PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null, null, in); try { reader.readAck(); @@ -86,9 +80,7 @@ public class PacketReaderImplTest extends BriarTestCase { public void testFormatExceptionIfOfferIsTooLarge() throws Exception { byte[] b = createOffer(true); ByteArrayInputStream in = new ByteArrayInputStream(b); - org.briarproject.sync.PacketReaderImpl - reader = new org.briarproject.sync.PacketReaderImpl( - bdfReaderFactory, null, + PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null, null, in); try { reader.readOffer(); @@ -102,8 +94,8 @@ public class PacketReaderImplTest extends BriarTestCase { public void testNoFormatExceptionIfOfferIsMaximumSize() throws Exception { byte[] b = createOffer(false); ByteArrayInputStream in = new ByteArrayInputStream(b); - org.briarproject.sync.PacketReaderImpl - reader = new org.briarproject.sync.PacketReaderImpl( + PacketReaderImpl + reader = new PacketReaderImpl( bdfReaderFactory, null, null, in); reader.readOffer(); @@ -113,9 +105,7 @@ public class PacketReaderImplTest extends BriarTestCase { public void testEmptyOffer() throws Exception { byte[] b = createEmptyOffer(); ByteArrayInputStream in = new ByteArrayInputStream(b); - org.briarproject.sync.PacketReaderImpl - reader = new org.briarproject.sync.PacketReaderImpl( - bdfReaderFactory, null, + PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null, null, in); try { reader.readOffer(); @@ -129,9 +119,7 @@ public class PacketReaderImplTest extends BriarTestCase { public void testFormatExceptionIfRequestIsTooLarge() throws Exception { byte[] b = createRequest(true); ByteArrayInputStream in = new ByteArrayInputStream(b); - org.briarproject.sync.PacketReaderImpl - reader = new org.briarproject.sync.PacketReaderImpl( - bdfReaderFactory, null, + PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null, null, in); try { reader.readRequest(); @@ -145,9 +133,7 @@ public class PacketReaderImplTest extends BriarTestCase { public void testNoFormatExceptionIfRequestIsMaximumSize() throws Exception { byte[] b = createRequest(false); ByteArrayInputStream in = new ByteArrayInputStream(b); - org.briarproject.sync.PacketReaderImpl - reader = new org.briarproject.sync.PacketReaderImpl( - bdfReaderFactory, null, + PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null, null, in); reader.readRequest(); } @@ -156,9 +142,7 @@ public class PacketReaderImplTest extends BriarTestCase { public void testEmptyRequest() throws Exception { byte[] b = createEmptyRequest(); ByteArrayInputStream in = new ByteArrayInputStream(b); - org.briarproject.sync.PacketReaderImpl - reader = new org.briarproject.sync.PacketReaderImpl( - bdfReaderFactory, null, + PacketReaderImpl reader = new PacketReaderImpl(bdfReaderFactory, null, null, in); try { reader.readRequest(); diff --git a/briar-tests/src/org/briarproject/sync/SimplexOutgoingSessionTest.java b/briar-tests/src/org/briarproject/sync/SimplexOutgoingSessionTest.java index 1848bad7fc..3cffb9feb6 100644 --- a/briar-tests/src/org/briarproject/sync/SimplexOutgoingSessionTest.java +++ b/briar-tests/src/org/briarproject/sync/SimplexOutgoingSessionTest.java @@ -46,8 +46,7 @@ public class SimplexOutgoingSessionTest extends BriarTestCase { @Test public void testNothingToSend() throws Exception { - final org.briarproject.sync.SimplexOutgoingSession - session = new org.briarproject.sync.SimplexOutgoingSession(db, + final SimplexOutgoingSession session = new SimplexOutgoingSession(db, dbExecutor, eventBus, contactId, transportId, maxLatency, packetWriter); context.checking(new Expectations() {{ @@ -87,8 +86,7 @@ public class SimplexOutgoingSessionTest extends BriarTestCase { public void testSomethingToSend() throws Exception { final Ack ack = new Ack(Collections.singletonList(messageId)); final byte[] raw = new byte[1234]; - final org.briarproject.sync.SimplexOutgoingSession - session = new org.briarproject.sync.SimplexOutgoingSession(db, + final SimplexOutgoingSession session = new SimplexOutgoingSession(db, dbExecutor, eventBus, contactId, transportId, maxLatency, packetWriter); context.checking(new Expectations() {{ -- GitLab