mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
No need to use @Before to create stateful test objects.
This commit is contained in:
@@ -17,7 +17,6 @@ import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.transport.KeyManager;
|
||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
import org.briarproject.bramble.test.DbExpectations;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -63,13 +62,9 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
||||
private final long timestamp = System.currentTimeMillis();
|
||||
private final boolean alice = new Random().nextBoolean();
|
||||
|
||||
private ContactManagerImpl contactManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
contactManager = new ContactManagerImpl(db, keyManager,
|
||||
identityManager, pendingContactFactory);
|
||||
}
|
||||
private final ContactManagerImpl contactManager =
|
||||
new ContactManagerImpl(db, keyManager, identityManager,
|
||||
pendingContactFactory);
|
||||
|
||||
@Test
|
||||
public void testAddContact() throws Exception {
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.briarproject.bramble.data;
|
||||
|
||||
import org.briarproject.bramble.test.BrambleTestCase;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -17,14 +16,8 @@ import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
public class BdfWriterImplTest extends BrambleTestCase {
|
||||
|
||||
private ByteArrayOutputStream out = null;
|
||||
private BdfWriterImpl w = null;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
out = new ByteArrayOutputStream();
|
||||
w = new BdfWriterImpl(out);
|
||||
}
|
||||
private final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
private final BdfWriterImpl w = new BdfWriterImpl(out);
|
||||
|
||||
@Test
|
||||
public void testWriteNull() throws IOException {
|
||||
|
||||
@@ -14,7 +14,6 @@ import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
import org.briarproject.bramble.test.DbExpectations;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
@@ -41,13 +40,8 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
|
||||
private final KeyPair handshakeKeyPair =
|
||||
new KeyPair(handshakePublicKey, handshakePrivateKey);
|
||||
|
||||
private IdentityManagerImpl identityManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
identityManager =
|
||||
new IdentityManagerImpl(db, crypto, authorFactory, clock);
|
||||
}
|
||||
private final IdentityManagerImpl identityManager =
|
||||
new IdentityManagerImpl(db, crypto, authorFactory, clock);
|
||||
|
||||
@Test
|
||||
public void testOpenDatabaseIdentityRegistered() throws Exception {
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
import org.briarproject.bramble.test.DbExpectations;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -34,12 +33,8 @@ public class LifecycleManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
private final SecretKey dbKey = getSecretKey();
|
||||
|
||||
private LifecycleManagerImpl lifecycleManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
lifecycleManager = new LifecycleManagerImpl(db, eventBus, clock);
|
||||
}
|
||||
private final LifecycleManagerImpl lifecycleManager =
|
||||
new LifecycleManagerImpl(db, eventBus, clock);
|
||||
|
||||
@Test
|
||||
public void testOpenDatabaseHooksAreCalledAtStartup() throws Exception {
|
||||
|
||||
@@ -5,7 +5,6 @@ import org.briarproject.bramble.api.mailbox.MailboxFolderId;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.briarproject.bramble.api.mailbox.MailboxConstants.CLIENT_SUPPORTS;
|
||||
@@ -34,13 +33,9 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
|
||||
requireNonNull(properties.getOutboxId());
|
||||
private final ContactId contactId = getContactId();
|
||||
|
||||
private ContactMailboxClient client;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
client = new ContactMailboxClient(workerFactory, connectivityChecker,
|
||||
reachabilityMonitor);
|
||||
}
|
||||
private final ContactMailboxClient client =
|
||||
new ContactMailboxClient(workerFactory, connectivityChecker,
|
||||
reachabilityMonitor);
|
||||
|
||||
@Test
|
||||
public void testStartAndDestroyWithNoContactsAssigned() {
|
||||
|
||||
@@ -12,7 +12,6 @@ import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
import org.briarproject.bramble.test.CaptureArgumentAction;
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.lib.action.DoAllAction;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -38,13 +37,9 @@ public class TorReachabilityMonitorImplTest extends BrambleMockTestCase {
|
||||
private final TorReachabilityObserver observer =
|
||||
context.mock(TorReachabilityObserver.class);
|
||||
|
||||
private TorReachabilityMonitorImpl monitor;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
monitor = new TorReachabilityMonitorImpl(ioExecutor, taskScheduler,
|
||||
pluginManager, eventBus);
|
||||
}
|
||||
private final TorReachabilityMonitorImpl monitor =
|
||||
new TorReachabilityMonitorImpl(ioExecutor, taskScheduler,
|
||||
pluginManager, eventBus);
|
||||
|
||||
@Test
|
||||
public void testSchedulesTaskWhenStartedIfTorIsActive() {
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.briarproject.bramble.test.ImmediateExecutor;
|
||||
import org.briarproject.bramble.test.RunAction;
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.imposters.ByteBuddyClassImposteriser;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
@@ -59,22 +58,18 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
private final SecureRandom random;
|
||||
|
||||
private final Executor ioExecutor = new ImmediateExecutor();
|
||||
private final Executor wakefulIoExecutor = new ImmediateExecutor();
|
||||
private final TransportId transportId = getTransportId();
|
||||
private final ContactId contactId = getContactId();
|
||||
private final TransportProperties properties = new TransportProperties();
|
||||
private final int pollingInterval = 60 * 1000;
|
||||
private final long now = System.currentTimeMillis();
|
||||
|
||||
private PollerImpl poller;
|
||||
private final PollerImpl poller;
|
||||
|
||||
public PollerImplTest() {
|
||||
context.setImposteriser(ByteBuddyClassImposteriser.INSTANCE);
|
||||
random = context.mock(SecureRandom.class);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Executor wakefulIoExecutor = new ImmediateExecutor();
|
||||
poller = new PollerImpl(ioExecutor, wakefulIoExecutor, scheduler,
|
||||
connectionManager, connectionRegistry, pluginManager,
|
||||
transportPropertyManager, random, clock);
|
||||
|
||||
@@ -12,7 +12,6 @@ import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
import org.briarproject.bramble.test.BrambleTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -46,13 +45,11 @@ public class LanTcpPluginTest extends BrambleTestCase {
|
||||
|
||||
private final Backoff backoff = new TestBackoff();
|
||||
private final ExecutorService ioExecutor = newCachedThreadPool();
|
||||
private final Callback callback = new Callback();
|
||||
|
||||
private Callback callback = null;
|
||||
private LanTcpPlugin plugin = null;
|
||||
private final LanTcpPlugin plugin;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
callback = new Callback();
|
||||
public LanTcpPluginTest() {
|
||||
plugin = new LanTcpPlugin(ioExecutor, ioExecutor, backoff, callback,
|
||||
0, 0, 1000) {
|
||||
@Override
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.briarproject.bramble.test.DbExpectations;
|
||||
import org.briarproject.bramble.test.ImmediateExecutor;
|
||||
import org.briarproject.bramble.test.PredicateMatcher;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Random;
|
||||
@@ -93,14 +92,10 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
|
||||
getTransportProperties(3);
|
||||
private final boolean alice = new Random().nextBoolean();
|
||||
|
||||
private RendezvousPollerImpl rendezvousPoller;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
rendezvousPoller = new RendezvousPollerImpl(ioExecutor, scheduler, db,
|
||||
identityManager, transportCrypto, rendezvousCrypto,
|
||||
pluginManager, connectionManager, eventBus, clock);
|
||||
}
|
||||
private final RendezvousPollerImpl rendezvousPoller =
|
||||
new RendezvousPollerImpl(ioExecutor, scheduler, db,
|
||||
identityManager, transportCrypto, rendezvousCrypto,
|
||||
pluginManager, connectionManager, eventBus, clock);
|
||||
|
||||
@Test
|
||||
public void testAddsPendingContactsAndSchedulesPollingAtStartup()
|
||||
|
||||
@@ -14,7 +14,6 @@ import org.briarproject.bramble.api.sync.SyncRecordReader;
|
||||
import org.briarproject.bramble.api.sync.Versions;
|
||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -44,12 +43,8 @@ public class SyncRecordReaderImplTest extends BrambleMockTestCase {
|
||||
context.mock(MessageFactory.class);
|
||||
private final RecordReader recordReader = context.mock(RecordReader.class);
|
||||
|
||||
private SyncRecordReader reader;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
reader = new SyncRecordReaderImpl(messageFactory, recordReader);
|
||||
}
|
||||
private final SyncRecordReader reader =
|
||||
new SyncRecordReaderImpl(messageFactory, recordReader);
|
||||
|
||||
@Test
|
||||
public void testNoFormatExceptionIfAckIsMaximumSize() throws Exception {
|
||||
|
||||
@@ -20,7 +20,6 @@ import org.briarproject.bramble.api.sync.validation.MessageValidator;
|
||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
import org.briarproject.bramble.test.DbExpectations;
|
||||
import org.briarproject.bramble.test.ImmediateExecutor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -70,11 +69,10 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
private final MessageContext validResultWithDependencies =
|
||||
new MessageContext(metadata, singletonList(messageId1));
|
||||
|
||||
private ValidationManagerImpl vm;
|
||||
private final ValidationManagerImpl vm =
|
||||
new ValidationManagerImpl(db, dbExecutor, validationExecutor);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
vm = new ValidationManagerImpl(db, dbExecutor, validationExecutor);
|
||||
public ValidationManagerImplTest() {
|
||||
vm.registerMessageValidator(clientId, majorVersion, validator);
|
||||
vm.registerIncomingMessageHook(clientId, majorVersion, hook);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.hamcrest.Description;
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.api.Action;
|
||||
import org.jmock.api.Invocation;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -72,13 +71,9 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
|
||||
private final SecretKey rootKey = getSecretKey();
|
||||
private final Random random = new Random();
|
||||
|
||||
private TransportKeyManager transportKeyManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
transportKeyManager = new TransportKeyManagerImpl(db, transportCrypto,
|
||||
dbExecutor, scheduler, clock, transportId, maxLatency);
|
||||
}
|
||||
private final TransportKeyManager transportKeyManager =
|
||||
new TransportKeyManagerImpl(db, transportCrypto, dbExecutor,
|
||||
scheduler, clock, transportId, maxLatency);
|
||||
|
||||
@Test
|
||||
public void testKeysAreUpdatedAtStartup() throws Exception {
|
||||
|
||||
@@ -4,7 +4,6 @@ import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -25,12 +24,8 @@ public class ModemPluginTest extends BrambleMockTestCase {
|
||||
private final PluginCallback callback = context.mock(PluginCallback.class);
|
||||
private final Modem modem = context.mock(Modem.class);
|
||||
|
||||
private ModemPlugin plugin;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
plugin = new ModemPlugin(modemFactory, serialPortList, callback, 0);
|
||||
}
|
||||
private final ModemPlugin plugin =
|
||||
new ModemPlugin(modemFactory, serialPortList, callback, 0);
|
||||
|
||||
@Test
|
||||
public void testModemCreation() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user