mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 13:49:53 +01:00
Disable shuffling of contacts when unit testing the modem plugin.
This commit is contained in:
@@ -42,18 +42,21 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
|||||||
private final SerialPortList serialPortList;
|
private final SerialPortList serialPortList;
|
||||||
private final DuplexPluginCallback callback;
|
private final DuplexPluginCallback callback;
|
||||||
private final long pollingInterval;
|
private final long pollingInterval;
|
||||||
|
private final boolean shuffle; // Used to disable shuffling for testing
|
||||||
|
|
||||||
private volatile boolean running = false;
|
private volatile boolean running = false;
|
||||||
private volatile Modem modem = null;
|
private volatile Modem modem = null;
|
||||||
|
|
||||||
ModemPlugin(@PluginExecutor Executor pluginExecutor,
|
ModemPlugin(@PluginExecutor Executor pluginExecutor,
|
||||||
ModemFactory modemFactory, SerialPortList serialPortList,
|
ModemFactory modemFactory, SerialPortList serialPortList,
|
||||||
DuplexPluginCallback callback, long pollingInterval) {
|
DuplexPluginCallback callback, long pollingInterval,
|
||||||
|
boolean shuffle) {
|
||||||
this.pluginExecutor = pluginExecutor;
|
this.pluginExecutor = pluginExecutor;
|
||||||
this.modemFactory = modemFactory;
|
this.modemFactory = modemFactory;
|
||||||
this.serialPortList = serialPortList;
|
this.serialPortList = serialPortList;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.pollingInterval = pollingInterval;
|
this.pollingInterval = pollingInterval;
|
||||||
|
this.shuffle = shuffle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransportId getId() {
|
public TransportId getId() {
|
||||||
@@ -138,7 +141,7 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
|||||||
Map<ContactId, TransportProperties> remote =
|
Map<ContactId, TransportProperties> remote =
|
||||||
callback.getRemoteProperties();
|
callback.getRemoteProperties();
|
||||||
List<ContactId> contacts = new ArrayList<ContactId>(remote.keySet());
|
List<ContactId> contacts = new ArrayList<ContactId>(remote.keySet());
|
||||||
Collections.shuffle(contacts);
|
if(shuffle) Collections.shuffle(contacts);
|
||||||
Iterator<ContactId> it = contacts.iterator();
|
Iterator<ContactId> it = contacts.iterator();
|
||||||
while(it.hasNext() && running) {
|
while(it.hasNext() && running) {
|
||||||
ContactId c = it.next();
|
ContactId c = it.next();
|
||||||
|
|||||||
@@ -34,6 +34,6 @@ public class ModemPluginFactory implements DuplexPluginFactory {
|
|||||||
String enabled = callback.getConfig().get("enabled");
|
String enabled = callback.getConfig().get("enabled");
|
||||||
if(StringUtils.isNullOrEmpty(enabled)) return null;
|
if(StringUtils.isNullOrEmpty(enabled)) return null;
|
||||||
return new ModemPlugin(pluginExecutor, modemFactory, serialPortList,
|
return new ModemPlugin(pluginExecutor, modemFactory, serialPortList,
|
||||||
callback, POLLING_INTERVAL);
|
callback, POLLING_INTERVAL, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
final SerialPortList serialPortList =
|
final SerialPortList serialPortList =
|
||||||
context.mock(SerialPortList.class);
|
context.mock(SerialPortList.class);
|
||||||
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
||||||
serialPortList, null, 0L);
|
serialPortList, null, 0L, true);
|
||||||
final Modem modem = context.mock(Modem.class);
|
final Modem modem = context.mock(Modem.class);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(serialPortList).getPortNames();
|
oneOf(serialPortList).getPortNames();
|
||||||
@@ -71,7 +71,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
final DuplexPluginCallback callback =
|
final DuplexPluginCallback callback =
|
||||||
context.mock(DuplexPluginCallback.class);
|
context.mock(DuplexPluginCallback.class);
|
||||||
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
||||||
serialPortList, callback, 0L);
|
serialPortList, callback, 0L, true);
|
||||||
final Modem modem = context.mock(Modem.class);
|
final Modem modem = context.mock(Modem.class);
|
||||||
final TransportProperties local = new TransportProperties();
|
final TransportProperties local = new TransportProperties();
|
||||||
local.put("iso3166", ISO_1336);
|
local.put("iso3166", ISO_1336);
|
||||||
@@ -112,7 +112,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
final DuplexPluginCallback callback =
|
final DuplexPluginCallback callback =
|
||||||
context.mock(DuplexPluginCallback.class);
|
context.mock(DuplexPluginCallback.class);
|
||||||
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
||||||
serialPortList, callback, 0L);
|
serialPortList, callback, 0L, true);
|
||||||
final Modem modem = context.mock(Modem.class);
|
final Modem modem = context.mock(Modem.class);
|
||||||
final TransportProperties local = new TransportProperties();
|
final TransportProperties local = new TransportProperties();
|
||||||
local.put("iso3166", ISO_1336);
|
local.put("iso3166", ISO_1336);
|
||||||
@@ -153,7 +153,7 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
final DuplexPluginCallback callback =
|
final DuplexPluginCallback callback =
|
||||||
context.mock(DuplexPluginCallback.class);
|
context.mock(DuplexPluginCallback.class);
|
||||||
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
final ModemPlugin plugin = new ModemPlugin(null, modemFactory,
|
||||||
serialPortList, callback, 0L);
|
serialPortList, callback, 0L, true);
|
||||||
final Modem modem = context.mock(Modem.class);
|
final Modem modem = context.mock(Modem.class);
|
||||||
final TransportProperties local = new TransportProperties();
|
final TransportProperties local = new TransportProperties();
|
||||||
local.put("iso3166", ISO_1336);
|
local.put("iso3166", ISO_1336);
|
||||||
@@ -202,8 +202,9 @@ public class ModemPluginTest extends BriarTestCase {
|
|||||||
context.mock(SerialPortList.class);
|
context.mock(SerialPortList.class);
|
||||||
final DuplexPluginCallback callback =
|
final DuplexPluginCallback callback =
|
||||||
context.mock(DuplexPluginCallback.class);
|
context.mock(DuplexPluginCallback.class);
|
||||||
|
// Disable shuffling for this test, it confuses jMock
|
||||||
final ModemPlugin plugin = new ModemPlugin(pluginExecutor, modemFactory,
|
final ModemPlugin plugin = new ModemPlugin(pluginExecutor, modemFactory,
|
||||||
serialPortList, callback, 0L);
|
serialPortList, callback, 0L, false);
|
||||||
final Modem modem = context.mock(Modem.class);
|
final Modem modem = context.mock(Modem.class);
|
||||||
final TransportProperties local = new TransportProperties();
|
final TransportProperties local = new TransportProperties();
|
||||||
local.put("iso3166", ISO_1336);
|
local.put("iso3166", ISO_1336);
|
||||||
|
|||||||
Reference in New Issue
Block a user