mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Wrapped the system clock in an interface so it can be replaced in tests.
This commit is contained in:
@@ -46,6 +46,7 @@ import net.sf.briar.api.transport.ConnectionReader;
|
||||
import net.sf.briar.api.transport.ConnectionReaderFactory;
|
||||
import net.sf.briar.api.transport.ConnectionWriter;
|
||||
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||
import net.sf.briar.clock.ClockModule;
|
||||
import net.sf.briar.crypto.CryptoModule;
|
||||
import net.sf.briar.db.DatabaseModule;
|
||||
import net.sf.briar.lifecycle.LifecycleModule;
|
||||
@@ -83,7 +84,7 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
||||
|
||||
public ProtocolIntegrationTest() throws Exception {
|
||||
super();
|
||||
Injector i = Guice.createInjector(new CryptoModule(),
|
||||
Injector i = Guice.createInjector(new ClockModule(), new CryptoModule(),
|
||||
new DatabaseModule(), new LifecycleModule(),
|
||||
new ProtocolModule(), new SerialModule(),
|
||||
new TestDatabaseModule(), new SimplexProtocolModule(),
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.sf.briar.api.db.DatabaseComponent;
|
||||
import net.sf.briar.api.db.DbException;
|
||||
import net.sf.briar.api.lifecycle.ShutdownManager;
|
||||
import net.sf.briar.api.protocol.PacketFactory;
|
||||
import net.sf.briar.clock.SystemClock;
|
||||
import net.sf.briar.db.DatabaseCleaner.Callback;
|
||||
|
||||
import org.jmock.Expectations;
|
||||
@@ -145,6 +146,6 @@ public class DatabaseComponentImplTest extends DatabaseComponentTest {
|
||||
Database<T> database, DatabaseCleaner cleaner,
|
||||
ShutdownManager shutdown, PacketFactory packetFactory) {
|
||||
return new DatabaseComponentImpl<T>(database, cleaner, shutdown,
|
||||
packetFactory);
|
||||
packetFactory, new SystemClock());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import net.sf.briar.api.transport.ConnectionContextFactory;
|
||||
import net.sf.briar.api.transport.ConnectionWindow;
|
||||
import net.sf.briar.api.transport.ConnectionWindowFactory;
|
||||
import net.sf.briar.api.transport.TransportConstants;
|
||||
import net.sf.briar.clock.SystemClock;
|
||||
import net.sf.briar.crypto.CryptoModule;
|
||||
import net.sf.briar.lifecycle.LifecycleModule;
|
||||
import net.sf.briar.protocol.ProtocolModule;
|
||||
@@ -1847,7 +1848,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
private Database<Connection> open(boolean resume) throws Exception {
|
||||
Database<Connection> db = new H2Database(testDir, password, MAX_SIZE,
|
||||
connectionContextFactory, connectionWindowFactory,
|
||||
groupFactory);
|
||||
groupFactory, new SystemClock());
|
||||
db.open(resume);
|
||||
return db;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.sf.briar.api.protocol.TransportId;
|
||||
import net.sf.briar.api.protocol.TransportIndex;
|
||||
import net.sf.briar.api.transport.ConnectionDispatcher;
|
||||
import net.sf.briar.api.ui.UiCallback;
|
||||
import net.sf.briar.clock.SystemClock;
|
||||
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
@@ -27,7 +28,7 @@ public class PluginManagerImplTest extends BriarTestCase {
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final Poller poller = context.mock(Poller.class);
|
||||
final ConnectionDispatcher dispatcher =
|
||||
context.mock(ConnectionDispatcher.class);
|
||||
context.mock(ConnectionDispatcher.class);
|
||||
final UiCallback uiCallback = context.mock(UiCallback.class);
|
||||
final AtomicInteger index = new AtomicInteger(0);
|
||||
context.checking(new Expectations() {{
|
||||
@@ -47,8 +48,8 @@ public class PluginManagerImplTest extends BriarTestCase {
|
||||
oneOf(poller).stop();
|
||||
}});
|
||||
ExecutorService executor = Executors.newCachedThreadPool();
|
||||
PluginManagerImpl p = new PluginManagerImpl(executor, db, poller,
|
||||
dispatcher, uiCallback);
|
||||
PluginManagerImpl p = new PluginManagerImpl(executor, new SystemClock(),
|
||||
db, poller, dispatcher, uiCallback);
|
||||
// We expect either 3 or 4 plugins to be started, depending on whether
|
||||
// the test machine has a Bluetooth device
|
||||
int started = p.start();
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.concurrent.Executors;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportConfig;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.clock.SystemClock;
|
||||
import net.sf.briar.plugins.DuplexClientTest;
|
||||
|
||||
// This is not a JUnit test - it has to be run manually while the server test
|
||||
@@ -25,7 +26,7 @@ public class BluetoothClientTest extends DuplexClientTest {
|
||||
// Create the plugin
|
||||
callback = new ClientCallback(new TransportConfig(),
|
||||
new TransportProperties(), remote);
|
||||
plugin = new BluetoothPlugin(executor, callback, 0L);
|
||||
plugin = new BluetoothPlugin(executor, new SystemClock(), callback, 0L);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.concurrent.Executors;
|
||||
|
||||
import net.sf.briar.api.TransportConfig;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.clock.SystemClock;
|
||||
import net.sf.briar.plugins.DuplexServerTest;
|
||||
|
||||
// This is not a JUnit test - it has to be run manually while the client test
|
||||
@@ -20,7 +21,7 @@ public class BluetoothServerTest extends DuplexServerTest {
|
||||
// Create the plugin
|
||||
callback = new ServerCallback(new TransportConfig(), local,
|
||||
Collections.singletonMap(contactId, new TransportProperties()));
|
||||
plugin = new BluetoothPlugin(executor, callback, 0L);
|
||||
plugin = new BluetoothPlugin(executor, new SystemClock(), callback, 0L);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
@@ -1,25 +1,21 @@
|
||||
package net.sf.briar.plugins.email;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportConfig;
|
||||
import net.sf.briar.api.TransportProperties;
|
||||
import net.sf.briar.api.plugins.simplex.SimplexPluginCallback;
|
||||
import net.sf.briar.api.plugins.simplex.SimplexTransportReader;
|
||||
import net.sf.briar.api.plugins.simplex.SimplexTransportWriter;
|
||||
import net.sf.briar.clock.SystemClock;
|
||||
|
||||
import org.jmock.Mockery;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -106,7 +102,8 @@ Map<ContactId,TransportProperties> map = new HashMap<ContactId, TransportPropert
|
||||
public void testPluginFactoryCreation()
|
||||
{
|
||||
GmailPluginFactory plugin = new GmailPluginFactory();
|
||||
plugin.createPlugin(Executors.newSingleThreadExecutor(), callback);
|
||||
plugin.createPlugin(Executors.newSingleThreadExecutor(),
|
||||
new SystemClock(), callback);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -30,6 +30,7 @@ import net.sf.briar.api.transport.ConnectionReaderFactory;
|
||||
import net.sf.briar.api.transport.ConnectionRecogniser;
|
||||
import net.sf.briar.api.transport.ConnectionRegistry;
|
||||
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||
import net.sf.briar.clock.ClockModule;
|
||||
import net.sf.briar.crypto.CryptoModule;
|
||||
import net.sf.briar.db.DatabaseModule;
|
||||
import net.sf.briar.lifecycle.LifecycleModule;
|
||||
@@ -77,8 +78,9 @@ public class SimplexConnectionReadWriteTest extends BriarTestCase {
|
||||
}
|
||||
|
||||
private Injector createInjector(File dir) {
|
||||
return Guice.createInjector(new CryptoModule(), new DatabaseModule(),
|
||||
new LifecycleModule(), new ProtocolModule(), new SerialModule(),
|
||||
return Guice.createInjector(new ClockModule(), new CryptoModule(),
|
||||
new DatabaseModule(), new LifecycleModule(),
|
||||
new ProtocolModule(), new SerialModule(),
|
||||
new TestDatabaseModule(dir), new SimplexProtocolModule(),
|
||||
new TransportModule(), new DuplexProtocolModule());
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestDatabaseModule;
|
||||
import net.sf.briar.api.transport.ConnectionWriter;
|
||||
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||
import net.sf.briar.clock.ClockModule;
|
||||
import net.sf.briar.crypto.CryptoModule;
|
||||
import net.sf.briar.db.DatabaseModule;
|
||||
import net.sf.briar.lifecycle.LifecycleModule;
|
||||
@@ -30,7 +31,7 @@ public class ConnectionWriterTest extends BriarTestCase {
|
||||
|
||||
public ConnectionWriterTest() throws Exception {
|
||||
super();
|
||||
Injector i = Guice.createInjector(new CryptoModule(),
|
||||
Injector i = Guice.createInjector(new ClockModule(), new CryptoModule(),
|
||||
new DatabaseModule(), new LifecycleModule(),
|
||||
new ProtocolModule(), new SerialModule(),
|
||||
new TestDatabaseModule(), new SimplexProtocolModule(),
|
||||
|
||||
Reference in New Issue
Block a user