@Test public void testModemCreation() throws Exception { Mockery context = new Mockery(); ModemFactory modemFactory = context.mock(ModemFactory.class); SerialPortList serialPortList = context.mock(SerialPortList.class); ModemPlugin plugin = new ModemPlugin(modemFactory, serialPortList, null, 0); Modem modem = context.mock(Modem.class); context.checking(new Expectations() {{ oneOf(serialPortList).getPortNames(); will(returnValue(new String[] { "foo", "bar", "baz" })); oneOf(modemFactory).createModem(plugin, "foo"); will(returnValue(modem)); oneOf(modem).start(); will(returnValue(false)); oneOf(modemFactory).createModem(plugin, "bar"); will(returnValue(modem)); oneOf(modem).start(); will(throwException(new IOException())); oneOf(modemFactory).createModem(plugin, "baz"); will(returnValue(modem)); oneOf(modem).start(); will(returnValue(true)); }}); plugin.start(); context.assertIsSatisfied(); }
@Override public void start() throws PluginException { if (used.getAndSet(true)) throw new IllegalStateException(); for (String portName : serialPortList.getPortNames()) { if (LOG.isLoggable(INFO)) LOG.info("Trying to initialise modem on " + portName); modem = modemFactory.createModem(this, portName); try { if (!modem.start()) continue; if (LOG.isLoggable(INFO)) LOG.info("Initialised modem on " + portName); running = true; return; } catch (IOException e) { logException(LOG, WARNING, e); } } throw new PluginException(); }
ModemPlugin implements DuplexPlugin, Modem.Callback { @Override public void start() throws PluginException { if (used.getAndSet(true)) throw new IllegalStateException(); for (String portName : serialPortList.getPortNames()) { if (LOG.isLoggable(INFO)) LOG.info("Trying to initialise modem on " + portName); modem = modemFactory.createModem(this, portName); try { if (!modem.start()) continue; if (LOG.isLoggable(INFO)) LOG.info("Initialised modem on " + portName); running = true; return; } catch (IOException e) { logException(LOG, WARNING, e); } } throw new PluginException(); } }
ModemPlugin implements DuplexPlugin, Modem.Callback { @Override public void start() throws PluginException { if (used.getAndSet(true)) throw new IllegalStateException(); for (String portName : serialPortList.getPortNames()) { if (LOG.isLoggable(INFO)) LOG.info("Trying to initialise modem on " + portName); modem = modemFactory.createModem(this, portName); try { if (!modem.start()) continue; if (LOG.isLoggable(INFO)) LOG.info("Initialised modem on " + portName); running = true; return; } catch (IOException e) { logException(LOG, WARNING, e); } } throw new PluginException(); } ModemPlugin(ModemFactory modemFactory, SerialPortList serialPortList,
			DuplexPluginCallback callback, int maxLatency); }
ModemPlugin implements DuplexPlugin, Modem.Callback { @Override public void start() throws PluginException { if (used.getAndSet(true)) throw new IllegalStateException(); for (String portName : serialPortList.getPortNames()) { if (LOG.isLoggable(INFO)) LOG.info("Trying to initialise modem on " + portName); modem = modemFactory.createModem(this, portName); try { if (!modem.start()) continue; if (LOG.isLoggable(INFO)) LOG.info("Initialised modem on " + portName); running = true; return; } catch (IOException e) { logException(LOG, WARNING, e); } } throw new PluginException(); } ModemPlugin(ModemFactory modemFactory, SerialPortList serialPortList,
			DuplexPluginCallback callback, int maxLatency); @Override TransportId getId(); @Override int getMaxLatency(); @Override int getMaxIdleTime(); @Override void start(); @Override void stop(); @Override boolean isRunning(); @Override boolean shouldPoll(); @Override int getPollingInterval(); @Override void poll(Map<ContactId, TransportProperties> contacts); @Override DuplexTransportConnection createConnection(TransportProperties p); @Override boolean supportsKeyAgreement(); @Override KeyAgreementListener createKeyAgreementListener(byte[] commitment); @Override DuplexTransportConnection createKeyAgreementConnection(
			byte[] commitment, BdfList descriptor); @Override void incomingCallConnected(); }
ModemPlugin implements DuplexPlugin, Modem.Callback { @Override public void start() throws PluginException { if (used.getAndSet(true)) throw new IllegalStateException(); for (String portName : serialPortList.getPortNames()) { if (LOG.isLoggable(INFO)) LOG.info("Trying to initialise modem on " + portName); modem = modemFactory.createModem(this, portName); try { if (!modem.start()) continue; if (LOG.isLoggable(INFO)) LOG.info("Initialised modem on " + portName); running = true; return; } catch (IOException e) { logException(LOG, WARNING, e); } } throw new PluginException(); } ModemPlugin(ModemFactory modemFactory, SerialPortList serialPortList,
			DuplexPluginCallback callback, int maxLatency); @Override TransportId getId(); @Override int getMaxLatency(); @Override int getMaxIdleTime(); @Override void start(); @Override void stop(); @Override boolean isRunning(); @Override boolean shouldPoll(); @Override int getPollingInterval(); @Override void poll(Map<ContactId, TransportProperties> contacts); @Override DuplexTransportConnection createConnection(TransportProperties p); @Override boolean supportsKeyAgreement(); @Override KeyAgreementListener createKeyAgreementListener(byte[] commitment); @Override DuplexTransportConnection createKeyAgreementConnection(
			byte[] commitment, BdfList descriptor); @Override void incomingCallConnected();  }