Move all unit tests to their modules and remove briar-tests

parent 32be148c
......@@ -5,18 +5,37 @@ targetCompatibility = 1.6
apply plugin: 'witness'
dependencies {
compile "com.google.dagger:dagger:2.0.2"
compile 'com.google.dagger:dagger-compiler:2.0.2'
compile "com.google.dagger:dagger:2.8"
compile 'com.google.dagger:dagger-compiler:2.8'
compile 'com.google.code.findbugs:jsr305:3.0.1'
testCompile 'junit:junit:4.12'
testCompile "org.jmock:jmock:2.8.1"
testCompile "org.jmock:jmock-junit4:2.8.1"
testCompile "org.jmock:jmock-legacy:2.8.1"
testCompile "org.hamcrest:hamcrest-library:1.3"
testCompile "org.hamcrest:hamcrest-core:1.3"
}
dependencyVerification {
verify = [
'com.google.dagger:dagger:84c0282ed8be73a29e0475d639da030b55dee72369e58dd35ae7d4fe6243dcf9',
'com.google.dagger:dagger-compiler:b74bc9de063dd4c6400b232231f2ef5056145b8fbecbf5382012007dd1c071b3',
'com.google.dagger:dagger:5070e1dff5c551a4908ba7b93125c0243de2a688aed3d2f475357d86d9d7c0ad',
'com.google.dagger:dagger-compiler:7b2686f94907868c5364e9965601ffe2f020ba4af1849ad9b57dad5fe3fa6242',
'com.google.code.findbugs:jsr305:c885ce34249682bc0236b4a7d56efcc12048e6135a5baf7a9cde8ad8cda13fcd',
'javax.inject:javax.inject:91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff',
'com.google.dagger:dagger-producers:99ec15e8a0507ba569e7655bc1165ee5e5ca5aa914b3c8f7e2c2458f724edd6b',
'com.google.guava:guava:d664fbfc03d2e5ce9cab2a44fb01f1d0bf9dfebeccc1a473b1f9ea31f79f6f99',
'com.google.code.findbugs:jsr305:c885ce34249682bc0236b4a7d56efcc12048e6135a5baf7a9cde8ad8cda13fcd'
'com.google.dagger:dagger-producers:1e4043e85f67de381d19e22c7932aaf7ff1611091be7e1aaae93f2c37f331cf2',
'com.google.guava:guava:ff89d4a4a6b303c4084194975a5a35f55a8af6f7337678b4cc8ddbea9005c323',
]
}
// needed to make test output available to bramble-core and briar-core
configurations {
testOutput.extendsFrom(testCompile)
}
task jarTest (type: Jar, dependsOn: testClasses) {
from sourceSets.test.output
classifier = 'test'
}
artifacts {
testOutput jarTest
}
package org.briarproject;
package org.briarproject.bramble;
import org.jmock.Mockery;
import org.junit.After;
public abstract class BriarMockTestCase extends BriarTestCase {
public abstract class BrambleMockTestCase extends
BrambleTestCase {
protected final Mockery context = new Mockery();
......
package org.briarproject;
package org.briarproject.bramble;
import java.lang.Thread.UncaughtExceptionHandler;
import static org.junit.Assert.fail;
public abstract class BriarTestCase {
public abstract class BrambleTestCase {
public BriarTestCase() {
public BrambleTestCase() {
// Ensure exceptions thrown on worker threads cause tests to fail
UncaughtExceptionHandler fail = new UncaughtExceptionHandler() {
@Override
......
package org.briarproject;
package org.briarproject.bramble;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
......
package org.briarproject;
package org.briarproject.bramble;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.db.DatabaseConfig;
......
package org.briarproject;
package org.briarproject.bramble;
import org.briarproject.bramble.api.db.DatabaseConfig;
import org.briarproject.bramble.api.db.DatabaseExecutor;
......
package org.briarproject;
package org.briarproject.bramble;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.system.SeedProvider;
......
package org.briarproject;
package org.briarproject.bramble;
import org.briarproject.bramble.api.system.SeedProvider;
......
package org.briarproject;
package org.briarproject.bramble;
import org.briarproject.bramble.api.UniqueId;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.util.IoUtils;
import org.briarproject.briar.api.client.MessageTracker;
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
import java.io.File;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals;
public class TestUtils {
private static final AtomicInteger nextTestDir =
......@@ -51,19 +45,4 @@ public class TestUtils {
return new SecretKey(getRandomBytes(SecretKey.LENGTH));
}
public static void assertGroupCount(MessageTracker tracker, GroupId g,
long msgCount, long unreadCount, long latestMsgTime)
throws DbException {
GroupCount groupCount = tracker.getGroupCount(g);
assertEquals(msgCount, groupCount.getMsgCount());
assertEquals(unreadCount, groupCount.getUnreadCount());
assertEquals(latestMsgTime, groupCount.getLatestMsgTime());
}
public static void assertGroupCount(MessageTracker tracker, GroupId g,
long msgCount, long unreadCount) throws DbException {
GroupCount c1 = tracker.getGroupCount(g);
assertEquals(msgCount, c1.getMsgCount());
assertEquals(unreadCount, c1.getUnreadCount());
}
}
package org.briarproject;
package org.briarproject.bramble;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.data.MetadataEncoder;
......@@ -10,7 +10,7 @@ import org.briarproject.bramble.api.sync.Message;
import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.api.system.Clock;
public abstract class ValidatorTestCase extends BriarMockTestCase {
public abstract class ValidatorTestCase extends BrambleMockTestCase {
protected final ClientHelper clientHelper =
context.mock(ClientHelper.class);
......
package org.briarproject.bramble.data;
package org.briarproject.bramble.api.data;
import org.briarproject.BriarTestCase;
import org.briarproject.bramble.BrambleTestCase;
import org.briarproject.bramble.api.Bytes;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry;
import org.junit.Test;
import java.util.Collections;
......@@ -15,7 +13,7 @@ import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class BdfDictionaryTest extends BriarTestCase {
public class BdfDictionaryTest extends BrambleTestCase {
@Test
public void testConstructors() {
......
package org.briarproject.bramble.data;
package org.briarproject.bramble.api.data;
import org.briarproject.BriarTestCase;
import org.briarproject.bramble.BrambleTestCase;
import org.briarproject.bramble.api.Bytes;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry;
import org.briarproject.bramble.api.data.BdfList;
import org.junit.Test;
import java.util.Arrays;
......@@ -15,7 +12,7 @@ import static org.briarproject.bramble.api.data.BdfDictionary.NULL_VALUE;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
public class BdfListTest extends BriarTestCase {
public class BdfListTest extends BrambleTestCase {
@Test
public void testConstructors() {
......
......@@ -14,10 +14,7 @@ dependencies {
compile 'com.madgag.spongycastle:core:1.54.0.0'
compile 'com.h2database:h2:1.4.190'
testCompile project(':briar-tests') // TODO remove when moving unit tests (#778)
testCompile 'junit:junit:4.12'
testCompile 'com.google.dagger:dagger-compiler:2.8'
testApt 'com.google.dagger:dagger-compiler:2.8'
testCompile project(path: ':bramble-api', configuration: 'testOutput')
}
dependencyVerification {
......@@ -26,3 +23,15 @@ dependencyVerification {
'com.h2database:h2:23ba495a07bbbb3bd6c3084d10a96dad7a23741b8b6d64b213459a784195a98c'
]
}
// needed to make test output available to bramble-j2se
configurations {
testOutput.extendsFrom(testCompile)
}
task jarTest (type: Jar, dependsOn: testClasses) {
from sourceSets.test.output
classifier = 'test'
}
artifacts {
testOutput jarTest
}
package org.briarproject;
package org.briarproject.bramble;
import org.hamcrest.Description;
import org.jmock.api.Action;
......
package org.briarproject.bramble.client;
import org.briarproject.ValidatorTestCase;
import org.briarproject.bramble.ValidatorTestCase;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.BdfMessageContext;
import org.briarproject.bramble.api.client.BdfMessageValidator;
......
package org.briarproject.bramble.client;
import org.briarproject.BriarTestCase;
import org.briarproject.TestUtils;
import org.briarproject.bramble.BrambleTestCase;
import org.briarproject.bramble.TestUtils;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.crypto.CryptoComponent;
......@@ -32,13 +32,13 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import static org.briarproject.TestUtils.getRandomBytes;
import static org.briarproject.TestUtils.getRandomId;
import static org.briarproject.bramble.TestUtils.getRandomBytes;
import static org.briarproject.bramble.TestUtils.getRandomId;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class ClientHelperImplTest extends BriarTestCase {
public class ClientHelperImplTest extends BrambleTestCase {
private final Mockery context = new Mockery();
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
......@@ -165,7 +165,8 @@ public class ClientHelperImplTest extends BriarTestCase {
@Test
public void testGetMessageMetadataAsDictionaryMap() throws Exception {
final Map<MessageId, BdfDictionary> map = new HashMap<>();
final Map<MessageId, BdfDictionary> map =
new HashMap<MessageId, BdfDictionary>();
map.put(messageId, dictionary);
final Transaction txn = new Transaction(null, true);
......@@ -187,7 +188,8 @@ public class ClientHelperImplTest extends BriarTestCase {
@Test
public void testGetMessageMetadataAsDictionaryQuery() throws Exception {
final Map<MessageId, BdfDictionary> map = new HashMap<>();
final Map<MessageId, BdfDictionary> map =
new HashMap<MessageId, BdfDictionary>();
map.put(messageId, dictionary);
final BdfDictionary query =
BdfDictionary.of(new BdfEntry("query", "me"));
......
package org.briarproject.bramble.contact;
import org.briarproject.BriarMockTestCase;
import org.briarproject.bramble.BrambleMockTestCase;
import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.ContactManager;
......@@ -19,13 +19,13 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import static org.briarproject.TestUtils.getRandomBytes;
import static org.briarproject.TestUtils.getRandomId;
import static org.briarproject.TestUtils.getSecretKey;
import static org.briarproject.bramble.TestUtils.getRandomBytes;
import static org.briarproject.bramble.TestUtils.getRandomId;
import static org.briarproject.bramble.TestUtils.getSecretKey;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class ContactManagerImplTest extends BriarMockTestCase {
public class ContactManagerImplTest extends BrambleMockTestCase {
private final Mockery context = new Mockery();
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
......@@ -132,7 +132,8 @@ public class ContactManagerImplTest extends BriarMockTestCase {
@Test
public void testActiveContacts() throws Exception {
Collection<Contact> activeContacts = Collections.singletonList(contact);
final Collection<Contact> contacts = new ArrayList<>(activeContacts);
final Collection<Contact> contacts =
new ArrayList<Contact>(activeContacts);
contacts.add(new Contact(new ContactId(3), remote, local, true, false));
final Transaction txn = new Transaction(null, true);
context.checking(new Expectations() {{
......
package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase;
import org.briarproject.bramble.BrambleTestCase;
import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
public class AsciiArmourTest extends BriarTestCase {
public class AsciiArmourTest extends BrambleTestCase {
@Test
public void testWrapOnSingleLine() {
......
package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase;
import org.briarproject.bramble.BrambleTestCase;
import org.briarproject.bramble.util.StringUtils;
import org.junit.Test;
......@@ -8,7 +8,7 @@ import java.util.Random;
import static org.junit.Assert.assertArrayEquals;
public class Blake2sDigestTest extends BriarTestCase {
public class Blake2sDigestTest extends BrambleTestCase {
// Vectors from BLAKE2 web site: https://blake2.net/blake2s-test.txt
private static final String[][] keyedTestVectors = {
......
package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase;
import org.briarproject.bramble.BrambleTestCase;
import org.junit.Test;
import org.spongycastle.asn1.teletrust.TeleTrusTNamedCurves;
import org.spongycastle.asn1.x9.X9ECParameters;
......@@ -20,7 +20,7 @@ import java.security.SecureRandom;
import static org.briarproject.bramble.crypto.EllipticCurveConstants.PARAMETERS;
import static org.junit.Assert.assertEquals;
public class EllipticCurveMultiplicationTest extends BriarTestCase {
public class EllipticCurveMultiplicationTest extends BrambleTestCase {
@Test
public void testMultiplierProducesSameResultsAsDefault() throws Exception {
......
......@@ -69,7 +69,7 @@ public class EllipticCurvePerformanceTest {
ECPublicKeyParameters public2 =
(ECPublicKeyParameters) keyPair2.getPublic();
// Time some ECDH key agreements
List<Long> samples = new ArrayList<>();
List<Long> samples = new ArrayList<Long>();
for (int i = 0; i < SAMPLES; i++) {
ECDHCBasicAgreement agreement = new ECDHCBasicAgreement();
long start = System.nanoTime();
......@@ -79,7 +79,7 @@ public class EllipticCurvePerformanceTest {
}
long agreementMedian = median(samples);
// Time some signatures
List<byte[]> signatures = new ArrayList<>();
List<byte[]> signatures = new ArrayList<byte[]>();
samples.clear();
for (int i = 0; i < SAMPLES; i++) {
Digest digest = new Blake2sDigest();
......
package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase;
import org.briarproject.bramble.BrambleTestCase;
import org.junit.Test;
import org.spongycastle.crypto.BlockCipher;
import org.spongycastle.crypto.engines.AESLightEngine;
......@@ -9,7 +9,7 @@ import org.spongycastle.crypto.params.KeyParameter;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
public class FortunaGeneratorTest extends BriarTestCase {
public class FortunaGeneratorTest extends BrambleTestCase {
@Test
public void testCounterInitialisedToOne() {
......
package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase;
import org.briarproject.bramble.BrambleTestCase;
import org.junit.Test;
import org.spongycastle.crypto.BlockCipher;
import org.spongycastle.crypto.digests.SHA256Digest;
......@@ -13,7 +13,7 @@ import static org.briarproject.bramble.crypto.FortunaSecureRandom.SELF_TEST_VECT
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertTrue;
public class FortunaSecureRandomTest extends BriarTestCase {
public class FortunaSecureRandomTest extends BrambleTestCase {
@Test
public void testClassPassesSelfTest() {
......
package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase;
import org.briarproject.TestSeedProvider;
import org.briarproject.bramble.BrambleTestCase;
import org.briarproject.bramble.TestSeedProvider;
import org.briarproject.bramble.api.crypto.CryptoComponent;
import org.briarproject.bramble.api.crypto.KeyPair;
import org.briarproject.bramble.api.crypto.SecretKey;
......@@ -10,7 +10,7 @@ import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
public class KeyAgreementTest extends BriarTestCase {
public class KeyAgreementTest extends BrambleTestCase {
@Test
public void testDeriveMasterSecret() throws Exception {
......
package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase;
import org.briarproject.TestSeedProvider;
import org.briarproject.TestUtils;
import org.briarproject.bramble.BrambleTestCase;
import org.briarproject.bramble.TestSeedProvider;
import org.briarproject.bramble.TestUtils;
import org.briarproject.bramble.api.crypto.CryptoComponent;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.plugin.TransportId;
......@@ -16,7 +16,7 @@ import java.util.List;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertFalse;
public class KeyDerivationTest extends BriarTestCase {
public class KeyDerivationTest extends BrambleTestCase {
private final TransportId transportId = new TransportId("id");
private final CryptoComponent crypto;
......@@ -141,7 +141,7 @@ public class KeyDerivationTest extends BriarTestCase {
}
private void assertAllDifferent(TransportKeys... transportKeys) {
List<SecretKey> secretKeys = new ArrayList<>();
List<SecretKey> secretKeys = new ArrayList<SecretKey>();
for (TransportKeys k : transportKeys) {
secretKeys.add(k.getPreviousIncomingKeys().getTagKey());
secretKeys.add(k.getPreviousIncomingKeys().getHeaderKey());
......
package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase;
import org.briarproject.TestSeedProvider;
import org.briarproject.TestUtils;
import org.briarproject.bramble.BrambleTestCase;
import org.briarproject.bramble.TestSeedProvider;
import org.briarproject.bramble.TestUtils;
import org.briarproject.bramble.api.crypto.KeyPair;
import org.briarproject.bramble.api.crypto.KeyParser;
import org.briarproject.bramble.api.crypto.PrivateKey;
......@@ -16,7 +16,7 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATUR
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertTrue;
public class KeyEncodingAndParsingTest extends BriarTestCase {
public class KeyEncodingAndParsingTest extends BrambleTestCase {
private final CryptoComponentImpl crypto =
new CryptoComponentImpl(new TestSeedProvider());
......
package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase;
import org.briarproject.TestSeedProvider;
import org.briarproject.TestUtils;
import org.briarproject.bramble.BrambleTestCase;
import org.briarproject.bramble.TestSeedProvider;
import org.briarproject.bramble.TestUtils;
import org.briarproject.bramble.api.crypto.CryptoComponent;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.junit.Test;
......@@ -12,7 +12,7 @@ import java.util.Arrays;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertFalse;
public class MacTest extends BriarTestCase {
public class MacTest extends BrambleTestCase {
private final CryptoComponent crypto;
......
package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase;
import org.briarproject.bramble.BrambleTestCase;
import org.briarproject.bramble.api.crypto.KeyPair;
import org.briarproject.bramble.api.crypto.PrivateKey;
import org.briarproject.bramble.api.crypto.PublicKey;
......@@ -11,7 +11,7 @@ import java.security.SecureRandom;
import static org.junit.Assert.assertArrayEquals;
public class MessageEncrypterTest extends BriarTestCase {
public class MessageEncrypterTest extends BrambleTestCase {
private final SecureRandom random = new SecureRandom();
......
package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase;
import org.briarproject.TestSeedProvider;
import org.briarproject.TestUtils;
import org.briarproject.bramble.BrambleTestCase;
import org.briarproject.bramble.TestSeedProvider;
import org.briarproject.bramble.TestUtils;
import org.junit.Test;
import java.util.Random;
......@@ -12,7 +12,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class PasswordBasedKdfTest extends BriarTestCase {
public class PasswordBasedKdfTest extends BrambleTestCase {
private final CryptoComponentImpl crypto =
new CryptoComponentImpl(new TestSeedProvider());
......
package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase;
import org.briarproject.bramble.BrambleTestCase;
import org.briarproject.bramble.api.crypto.PasswordStrengthEstimator;
import org.junit.Test;
import static org.briarproject.bramble.api.crypto.PasswordStrengthEstimator.QUITE_STRONG;
import static org.junit.Assert.assertTrue;
public class PasswordStrengthEstimatorImplTest extends BriarTestCase {
public class PasswordStrengthEstimatorImplTest extends BrambleTestCase {
@Test
public void testWeakPasswords() {
......
package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase;
import org.briarproject.TestSeedProvider;
import org.briarproject.TestUtils;