Commit 1081a08e authored by Torsten Grote's avatar Torsten Grote

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

parent 32be148c
...@@ -5,18 +5,37 @@ targetCompatibility = 1.6 ...@@ -5,18 +5,37 @@ targetCompatibility = 1.6
apply plugin: 'witness' apply plugin: 'witness'
dependencies { dependencies {
compile "com.google.dagger:dagger:2.0.2" compile "com.google.dagger:dagger:2.8"
compile 'com.google.dagger:dagger-compiler:2.0.2' compile 'com.google.dagger:dagger-compiler:2.8'
compile 'com.google.code.findbugs:jsr305:3.0.1' 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 { dependencyVerification {
verify = [ verify = [
'com.google.dagger:dagger:84c0282ed8be73a29e0475d639da030b55dee72369e58dd35ae7d4fe6243dcf9', 'com.google.dagger:dagger:5070e1dff5c551a4908ba7b93125c0243de2a688aed3d2f475357d86d9d7c0ad',
'com.google.dagger:dagger-compiler:b74bc9de063dd4c6400b232231f2ef5056145b8fbecbf5382012007dd1c071b3', 'com.google.dagger:dagger-compiler:7b2686f94907868c5364e9965601ffe2f020ba4af1849ad9b57dad5fe3fa6242',
'com.google.code.findbugs:jsr305:c885ce34249682bc0236b4a7d56efcc12048e6135a5baf7a9cde8ad8cda13fcd',
'javax.inject:javax.inject:91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff', 'javax.inject:javax.inject:91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff',
'com.google.dagger:dagger-producers:99ec15e8a0507ba569e7655bc1165ee5e5ca5aa914b3c8f7e2c2458f724edd6b', 'com.google.dagger:dagger-producers:1e4043e85f67de381d19e22c7932aaf7ff1611091be7e1aaae93f2c37f331cf2',
'com.google.guava:guava:d664fbfc03d2e5ce9cab2a44fb01f1d0bf9dfebeccc1a473b1f9ea31f79f6f99', 'com.google.guava:guava:ff89d4a4a6b303c4084194975a5a35f55a8af6f7337678b4cc8ddbea9005c323',
'com.google.code.findbugs:jsr305:c885ce34249682bc0236b4a7d56efcc12048e6135a5baf7a9cde8ad8cda13fcd'
] ]
} }
// 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.jmock.Mockery;
import org.junit.After; import org.junit.After;
public abstract class BriarMockTestCase extends BriarTestCase { public abstract class BrambleMockTestCase extends
BrambleTestCase {
protected final Mockery context = new Mockery(); protected final Mockery context = new Mockery();
......
package org.briarproject; package org.briarproject.bramble;
import java.lang.Thread.UncaughtExceptionHandler; import java.lang.Thread.UncaughtExceptionHandler;
import static org.junit.Assert.fail; 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 // Ensure exceptions thrown on worker threads cause tests to fail
UncaughtExceptionHandler fail = new UncaughtExceptionHandler() { UncaughtExceptionHandler fail = new UncaughtExceptionHandler() {
@Override @Override
......
package org.briarproject; package org.briarproject.bramble;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; 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.crypto.SecretKey;
import org.briarproject.bramble.api.db.DatabaseConfig; 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.DatabaseConfig;
import org.briarproject.bramble.api.db.DatabaseExecutor; 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.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.system.SeedProvider; import org.briarproject.bramble.api.system.SeedProvider;
......
package org.briarproject; package org.briarproject.bramble;
import org.briarproject.bramble.api.system.SeedProvider; 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.UniqueId;
import org.briarproject.bramble.api.crypto.SecretKey; 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.bramble.util.IoUtils;
import org.briarproject.briar.api.client.MessageTracker;
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
import java.io.File; import java.io.File;
import java.util.Random; import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals;
public class TestUtils { public class TestUtils {
private static final AtomicInteger nextTestDir = private static final AtomicInteger nextTestDir =
...@@ -51,19 +45,4 @@ public class TestUtils { ...@@ -51,19 +45,4 @@ public class TestUtils {
return new SecretKey(getRandomBytes(SecretKey.LENGTH)); 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.client.ClientHelper;
import org.briarproject.bramble.api.data.MetadataEncoder; import org.briarproject.bramble.api.data.MetadataEncoder;
...@@ -10,7 +10,7 @@ import org.briarproject.bramble.api.sync.Message; ...@@ -10,7 +10,7 @@ import org.briarproject.bramble.api.sync.Message;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.api.system.Clock; import org.briarproject.bramble.api.system.Clock;
public abstract class ValidatorTestCase extends BriarMockTestCase { public abstract class ValidatorTestCase extends BrambleMockTestCase {
protected final ClientHelper clientHelper = protected final ClientHelper clientHelper =
context.mock(ClientHelper.class); 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.Bytes;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry;
import org.junit.Test; import org.junit.Test;
import java.util.Collections; import java.util.Collections;
...@@ -15,7 +13,7 @@ import static org.junit.Assert.assertArrayEquals; ...@@ -15,7 +13,7 @@ import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public class BdfDictionaryTest extends BriarTestCase { public class BdfDictionaryTest extends BrambleTestCase {
@Test @Test
public void testConstructors() { 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.Bytes;
import org.briarproject.bramble.api.FormatException; 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 org.junit.Test;
import java.util.Arrays; import java.util.Arrays;
...@@ -15,7 +12,7 @@ import static org.briarproject.bramble.api.data.BdfDictionary.NULL_VALUE; ...@@ -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.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
public class BdfListTest extends BriarTestCase { public class BdfListTest extends BrambleTestCase {
@Test @Test
public void testConstructors() { public void testConstructors() {
......
bin bin
build build
test.tmp
.settings .settings
...@@ -14,10 +14,7 @@ dependencies { ...@@ -14,10 +14,7 @@ dependencies {
compile 'com.madgag.spongycastle:core:1.54.0.0' compile 'com.madgag.spongycastle:core:1.54.0.0'
compile 'com.h2database:h2:1.4.190' compile 'com.h2database:h2:1.4.190'
testCompile project(':briar-tests') // TODO remove when moving unit tests (#778) testCompile project(path: ':bramble-api', configuration: 'testOutput')
testCompile 'junit:junit:4.12'
testCompile 'com.google.dagger:dagger-compiler:2.8'
testApt 'com.google.dagger:dagger-compiler:2.8'
} }
dependencyVerification { dependencyVerification {
...@@ -26,3 +23,15 @@ dependencyVerification { ...@@ -26,3 +23,15 @@ dependencyVerification {
'com.h2database:h2:23ba495a07bbbb3bd6c3084d10a96dad7a23741b8b6d64b213459a784195a98c' '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.hamcrest.Description;
import org.jmock.api.Action; import org.jmock.api.Action;
......
package org.briarproject.bramble.client; 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.FormatException;
import org.briarproject.bramble.api.client.BdfMessageContext; import org.briarproject.bramble.api.client.BdfMessageContext;
import org.briarproject.bramble.api.client.BdfMessageValidator; import org.briarproject.bramble.api.client.BdfMessageValidator;
......
package org.briarproject.bramble.client; package org.briarproject.bramble.client;
import org.briarproject.BriarTestCase; import org.briarproject.bramble.BrambleTestCase;
import org.briarproject.TestUtils; import org.briarproject.bramble.TestUtils;
import org.briarproject.bramble.api.FormatException; import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper; import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.crypto.CryptoComponent; import org.briarproject.bramble.api.crypto.CryptoComponent;
...@@ -32,13 +32,13 @@ import java.util.Collections; ...@@ -32,13 +32,13 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.briarproject.TestUtils.getRandomBytes; import static org.briarproject.bramble.TestUtils.getRandomBytes;
import static org.briarproject.TestUtils.getRandomId; import static org.briarproject.bramble.TestUtils.getRandomId;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
public class ClientHelperImplTest extends BriarTestCase { public class ClientHelperImplTest extends BrambleTestCase {
private final Mockery context = new Mockery(); private final Mockery context = new Mockery();
private final DatabaseComponent db = context.mock(DatabaseComponent.class); private final DatabaseComponent db = context.mock(DatabaseComponent.class);
...@@ -165,7 +165,8 @@ public class ClientHelperImplTest extends BriarTestCase { ...@@ -165,7 +165,8 @@ public class ClientHelperImplTest extends BriarTestCase {
@Test @Test
public void testGetMessageMetadataAsDictionaryMap() throws Exception { 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); map.put(messageId, dictionary);
final Transaction txn = new Transaction(null, true); final Transaction txn = new Transaction(null, true);
...@@ -187,7 +188,8 @@ public class ClientHelperImplTest extends BriarTestCase { ...@@ -187,7 +188,8 @@ public class ClientHelperImplTest extends BriarTestCase {
@Test @Test
public void testGetMessageMetadataAsDictionaryQuery() throws Exception { 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); map.put(messageId, dictionary);
final BdfDictionary query = final BdfDictionary query =
BdfDictionary.of(new BdfEntry("query", "me")); BdfDictionary.of(new BdfEntry("query", "me"));
......
package org.briarproject.bramble.contact; 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.Contact;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.ContactManager; import org.briarproject.bramble.api.contact.ContactManager;
...@@ -19,13 +19,13 @@ import java.util.ArrayList; ...@@ -19,13 +19,13 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import static org.briarproject.TestUtils.getRandomBytes; import static org.briarproject.bramble.TestUtils.getRandomBytes;
import static org.briarproject.TestUtils.getRandomId; import static org.briarproject.bramble.TestUtils.getRandomId;
import static org.briarproject.TestUtils.getSecretKey; import static org.briarproject.bramble.TestUtils.getSecretKey;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public class ContactManagerImplTest extends BriarMockTestCase { public class ContactManagerImplTest extends BrambleMockTestCase {
private final Mockery context = new Mockery(); private final Mockery context = new Mockery();
private final DatabaseComponent db = context.mock(DatabaseComponent.class); private final DatabaseComponent db = context.mock(DatabaseComponent.class);
...@@ -132,7 +132,8 @@ public class ContactManagerImplTest extends BriarMockTestCase { ...@@ -132,7 +132,8 @@ public class ContactManagerImplTest extends BriarMockTestCase {
@Test @Test
public void testActiveContacts() throws Exception { public void testActiveContacts() throws Exception {
Collection<Contact> activeContacts = Collections.singletonList(contact); 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)); contacts.add(new Contact(new ContactId(3), remote, local, true, false));
final Transaction txn = new Transaction(null, true); final Transaction txn = new Transaction(null, true);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
......
package org.briarproject.bramble.crypto; package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase; import org.briarproject.bramble.BrambleTestCase;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
public class AsciiArmourTest extends BriarTestCase { public class AsciiArmourTest extends BrambleTestCase {
@Test @Test
public void testWrapOnSingleLine() { public void testWrapOnSingleLine() {
......
package org.briarproject.bramble.crypto; package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase; import org.briarproject.bramble.BrambleTestCase;
import org.briarproject.bramble.util.StringUtils; import org.briarproject.bramble.util.StringUtils;
import org.junit.Test; import org.junit.Test;
...@@ -8,7 +8,7 @@ import java.util.Random; ...@@ -8,7 +8,7 @@ import java.util.Random;
import static org.junit.Assert.assertArrayEquals; 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 // Vectors from BLAKE2 web site: https://blake2.net/blake2s-test.txt
private static final String[][] keyedTestVectors = { private static final String[][] keyedTestVectors = {
......
package org.briarproject.bramble.crypto; package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase; import org.briarproject.bramble.BrambleTestCase;
import org.junit.Test; import org.junit.Test;
import org.spongycastle.asn1.teletrust.TeleTrusTNamedCurves; import org.spongycastle.asn1.teletrust.TeleTrusTNamedCurves;
import org.spongycastle.asn1.x9.X9ECParameters; import org.spongycastle.asn1.x9.X9ECParameters;
...@@ -20,7 +20,7 @@ import java.security.SecureRandom; ...@@ -20,7 +20,7 @@ import java.security.SecureRandom;
import static org.briarproject.bramble.crypto.EllipticCurveConstants.PARAMETERS; import static org.briarproject.bramble.crypto.EllipticCurveConstants.PARAMETERS;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
public class EllipticCurveMultiplicationTest extends BriarTestCase { public class EllipticCurveMultiplicationTest extends BrambleTestCase {
@Test @Test
public void testMultiplierProducesSameResultsAsDefault() throws Exception { public void testMultiplierProducesSameResultsAsDefault() throws Exception {
......
...@@ -69,7 +69,7 @@ public class EllipticCurvePerformanceTest { ...@@ -69,7 +69,7 @@ public class EllipticCurvePerformanceTest {
ECPublicKeyParameters public2 = ECPublicKeyParameters public2 =
(ECPublicKeyParameters) keyPair2.getPublic(); (ECPublicKeyParameters) keyPair2.getPublic();
// Time some ECDH key agreements // Time some ECDH key agreements
List<Long> samples = new ArrayList<>(); List<Long> samples = new ArrayList<Long>();
for (int i = 0; i < SAMPLES; i++) { for (int i = 0; i < SAMPLES; i++) {
ECDHCBasicAgreement agreement = new ECDHCBasicAgreement(); ECDHCBasicAgreement agreement = new ECDHCBasicAgreement();
long start = System.nanoTime(); long start = System.nanoTime();
...@@ -79,7 +79,7 @@ public class EllipticCurvePerformanceTest { ...@@ -79,7 +79,7 @@ public class EllipticCurvePerformanceTest {
} }
long agreementMedian = median(samples); long agreementMedian = median(samples);
// Time some signatures // Time some signatures
List<byte[]> signatures = new ArrayList<>(); List<byte[]> signatures = new ArrayList<byte[]>();
samples.clear(); samples.clear();
for (int i = 0; i < SAMPLES; i++) { for (int i = 0; i < SAMPLES; i++) {
Digest digest = new Blake2sDigest(); Digest digest = new Blake2sDigest();
......
package org.briarproject.bramble.crypto; package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase; import org.briarproject.bramble.BrambleTestCase;
import org.junit.Test; import org.junit.Test;
import org.spongycastle.crypto.BlockCipher; import org.spongycastle.crypto.BlockCipher;
import org.spongycastle.crypto.engines.AESLightEngine; import org.spongycastle.crypto.engines.AESLightEngine;
...@@ -9,7 +9,7 @@ import org.spongycastle.crypto.params.KeyParameter; ...@@ -9,7 +9,7 @@ import org.spongycastle.crypto.params.KeyParameter;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
public class FortunaGeneratorTest extends BriarTestCase { public class FortunaGeneratorTest extends BrambleTestCase {
@Test @Test
public void testCounterInitialisedToOne() { public void testCounterInitialisedToOne() {
......
package org.briarproject.bramble.crypto; package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase; import org.briarproject.bramble.BrambleTestCase;
import org.junit.Test; import org.junit.Test;
import org.spongycastle.crypto.BlockCipher; import org.spongycastle.crypto.BlockCipher;
import org.spongycastle.crypto.digests.SHA256Digest; import org.spongycastle.crypto.digests.SHA256Digest;
...@@ -13,7 +13,7 @@ import static org.briarproject.bramble.crypto.FortunaSecureRandom.SELF_TEST_VECT ...@@ -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.assertArrayEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public class FortunaSecureRandomTest extends BriarTestCase { public class FortunaSecureRandomTest extends BrambleTestCase {
@Test @Test
public void testClassPassesSelfTest() { public void testClassPassesSelfTest() {
......
package org.briarproject.bramble.crypto; package org.briarproject.bramble.crypto;
import org.briarproject.BriarTestCase; import org.briarproject.bramble.BrambleTestCase;
import org.briarproject.TestSeedProvider;