diff --git a/components/net/sf/briar/plugins/bluetooth/BluetoothPlugin.java b/components/net/sf/briar/plugins/bluetooth/BluetoothPlugin.java index a2a6e3083a5be38df35db59af516572d4dbe2f1f..c79d2e59060f6e85d034ada70021299c5bd33cf9 100644 --- a/components/net/sf/briar/plugins/bluetooth/BluetoothPlugin.java +++ b/components/net/sf/briar/plugins/bluetooth/BluetoothPlugin.java @@ -31,6 +31,7 @@ class BluetoothPlugin extends AbstractPlugin implements StreamTransportPlugin { private final long pollingInterval; private StreamTransportCallback callback = null; + private LocalDevice localDevice = null; private StreamConnectionNotifier streamConnectionNotifier = null; BluetoothPlugin(Executor executor, String uuid, long pollingInterval) { @@ -46,10 +47,11 @@ class BluetoothPlugin extends AbstractPlugin implements StreamTransportPlugin { public synchronized void start(Map<String, String> localProperties, Map<ContactId, Map<String, String>> remoteProperties, Map<String, String> config, StreamTransportCallback callback) - throws InvalidPropertiesException, InvalidConfigException, - IOException { + throws InvalidPropertiesException, InvalidConfigException, IOException { super.start(localProperties, remoteProperties, config); this.callback = callback; + // Initialise the Bluetooth stack + localDevice = LocalDevice.getLocalDevice(); executor.execute(createBinder()); } @@ -73,14 +75,6 @@ class BluetoothPlugin extends AbstractPlugin implements StreamTransportPlugin { synchronized(this) { if(!started) return; } - // Initialise the Bluetooth stack - LocalDevice localDevice = null; - try { - localDevice = LocalDevice.getLocalDevice(); - } catch(BluetoothStateException e) { - // FIXME: Logging - return; - } // Try to make the device discoverable (requires root on Linux) try { localDevice.setDiscoverable(DiscoveryAgent.GIAC); diff --git a/test/net/sf/briar/plugins/ImmediateExecutor.java b/test/net/sf/briar/plugins/ImmediateExecutor.java new file mode 100644 index 0000000000000000000000000000000000000000..fe21666e06641800e38fdc5673b8847818d716b9 --- /dev/null +++ b/test/net/sf/briar/plugins/ImmediateExecutor.java @@ -0,0 +1,10 @@ +package net.sf.briar.plugins; + +import java.util.concurrent.Executor; + +public class ImmediateExecutor implements Executor { + + public void execute(Runnable r) { + r.run(); + } +} diff --git a/test/net/sf/briar/plugins/StubStreamCallback.java b/test/net/sf/briar/plugins/StubStreamCallback.java new file mode 100644 index 0000000000000000000000000000000000000000..d39b32cd45d0da9946cfd8136f0fbd7b48154038 --- /dev/null +++ b/test/net/sf/briar/plugins/StubStreamCallback.java @@ -0,0 +1,39 @@ +package net.sf.briar.plugins; + +import java.util.Map; + +import net.sf.briar.api.ContactId; +import net.sf.briar.api.transport.stream.StreamTransportCallback; +import net.sf.briar.api.transport.stream.StreamTransportConnection; + +public class StubStreamCallback implements StreamTransportCallback { + + public Map<String, String> localProperties = null; + public volatile int incomingConnections = 0; + + public void setLocalProperties(Map<String, String> properties) { + localProperties = properties; + } + + public void setConfig(Map<String, String> config) { + } + + public void showMessage(String... message) { + } + + public boolean showConfirmationMessage(String... message) { + return false; + } + + public int showChoice(String[] choices, String... message) { + return -1; + } + + public void incomingConnectionCreated(StreamTransportConnection c) { + incomingConnections++; + } + + public void outgoingConnectionCreated(ContactId contactId, + StreamTransportConnection c) { + } +} diff --git a/test/net/sf/briar/plugins/file/RemovableDrivePluginTest.java b/test/net/sf/briar/plugins/file/RemovableDrivePluginTest.java index 2bede141746f9f0c646779a5e3ba6833a5da404d..02f42665cde5e57a6cb01f9d1a6f29369d9c5be5 100644 --- a/test/net/sf/briar/plugins/file/RemovableDrivePluginTest.java +++ b/test/net/sf/briar/plugins/file/RemovableDrivePluginTest.java @@ -17,6 +17,7 @@ import net.sf.briar.api.ContactId; import net.sf.briar.api.transport.TransportConstants; import net.sf.briar.api.transport.batch.BatchTransportCallback; import net.sf.briar.api.transport.batch.BatchTransportWriter; +import net.sf.briar.plugins.ImmediateExecutor; import net.sf.briar.plugins.file.RemovableDriveMonitor.Callback; import org.jmock.Expectations; @@ -407,11 +408,4 @@ public class RemovableDrivePluginTest extends TestCase { public void tearDown() { TestUtils.deleteTestDirectory(testDir); } - - private static class ImmediateExecutor implements Executor { - - public void execute(Runnable r) { - r.run(); - } - } } diff --git a/test/net/sf/briar/plugins/socket/SimpleSocketPluginTest.java b/test/net/sf/briar/plugins/socket/SimpleSocketPluginTest.java index 6093a7e3604602a35a552b7dec57cf8c90bfe292..e94b20609134838259396a9e908b2bd5a153a5c5 100644 --- a/test/net/sf/briar/plugins/socket/SimpleSocketPluginTest.java +++ b/test/net/sf/briar/plugins/socket/SimpleSocketPluginTest.java @@ -8,14 +8,14 @@ import java.util.HashMap; import java.util.Map; import java.util.TreeMap; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import junit.framework.TestCase; import net.sf.briar.api.ContactId; -import net.sf.briar.api.transport.stream.StreamTransportCallback; import net.sf.briar.api.transport.stream.StreamTransportConnection; +import net.sf.briar.plugins.ImmediateExecutor; +import net.sf.briar.plugins.StubStreamCallback; import org.junit.Before; import org.junit.Test; @@ -38,7 +38,7 @@ public class SimpleSocketPluginTest extends TestCase { @Test public void testIncomingConnection() throws Exception { - StubCallback callback = new StubCallback(); + StubStreamCallback callback = new StubStreamCallback(); localProperties.put("host", "127.0.0.1"); localProperties.put("port", "0"); SimpleSocketPlugin plugin = @@ -74,7 +74,7 @@ public class SimpleSocketPluginTest extends TestCase { @Test public void testOutgoingConnection() throws Exception { - StubCallback callback = new StubCallback(); + StubStreamCallback callback = new StubStreamCallback(); SimpleSocketPlugin plugin = new SimpleSocketPlugin(new ImmediateExecutor(), 10); plugin.start(localProperties, remoteProperties, config, callback); @@ -114,7 +114,7 @@ public class SimpleSocketPluginTest extends TestCase { @Test public void testUpdatingPropertiesReopensSocket() throws Exception { - StubCallback callback = new StubCallback(); + StubStreamCallback callback = new StubStreamCallback(); localProperties.put("host", "127.0.0.1"); localProperties.put("port", "0"); SimpleSocketPlugin plugin = @@ -169,43 +169,4 @@ public class SimpleSocketPluginTest extends TestCase { fail(); } catch(IOException expected) {} } - - private static class ImmediateExecutor implements Executor { - - public void execute(Runnable r) { - r.run(); - } - } - - private static class StubCallback implements StreamTransportCallback { - - private Map<String, String> localProperties = null; - private volatile int incomingConnections = 0; - - public void setLocalProperties(Map<String, String> properties) { - localProperties = properties; - } - - public void setConfig(Map<String, String> config) { - } - - public void showMessage(String... message) { - } - - public boolean showConfirmationMessage(String... message) { - return false; - } - - public int showChoice(String[] choices, String... message) { - return -1; - } - - public void incomingConnectionCreated(StreamTransportConnection c) { - incomingConnections++; - } - - public void outgoingConnectionCreated(ContactId contactId, - StreamTransportConnection c) { - } - } }