@Test public void testCreateConnection() throws Exception { Mockery context = new Mockery(); ModemFactory modemFactory = context.mock(ModemFactory.class); SerialPortList serialPortList = context.mock(SerialPortList.class); DuplexPluginCallback callback = context.mock(DuplexPluginCallback.class); ModemPlugin plugin = new ModemPlugin(modemFactory, serialPortList, callback, 0); Modem modem = context.mock(Modem.class); TransportProperties local = new TransportProperties(); local.put("iso3166", ISO_1336); TransportProperties remote = new TransportProperties(); remote.put("iso3166", ISO_1336); remote.put("number", NUMBER); context.checking(new Expectations() {{ oneOf(serialPortList).getPortNames(); will(returnValue(new String[] { "foo" })); oneOf(modemFactory).createModem(plugin, "foo"); will(returnValue(modem)); oneOf(modem).start(); will(returnValue(true)); oneOf(callback).getLocalProperties(); will(returnValue(local)); oneOf(modem).dial(NUMBER); will(returnValue(true)); }}); plugin.start(); assertNotNull(plugin.createConnection(remote)); context.assertIsSatisfied(); }
@Override public DuplexTransportConnection createConnection(TransportProperties p) { if (!running) return null; String fromIso = callback.getLocalProperties().get("iso3166"); if (StringUtils.isNullOrEmpty(fromIso)) return null; String toIso = p.get("iso3166"); if (StringUtils.isNullOrEmpty(toIso)) return null; String number = p.get("number"); if (StringUtils.isNullOrEmpty(number)) return null; number = CountryCodes.translate(number, fromIso, toIso); if (number == null) return null; try { if (!modem.dial(number)) return null; } catch (IOException e) { logException(LOG, WARNING, e); resetModem(); return null; } return new ModemTransportConnection(); }
ModemPlugin implements DuplexPlugin, Modem.Callback { @Override public DuplexTransportConnection createConnection(TransportProperties p) { if (!running) return null; String fromIso = callback.getLocalProperties().get("iso3166"); if (StringUtils.isNullOrEmpty(fromIso)) return null; String toIso = p.get("iso3166"); if (StringUtils.isNullOrEmpty(toIso)) return null; String number = p.get("number"); if (StringUtils.isNullOrEmpty(number)) return null; number = CountryCodes.translate(number, fromIso, toIso); if (number == null) return null; try { if (!modem.dial(number)) return null; } catch (IOException e) { logException(LOG, WARNING, e); resetModem(); return null; } return new ModemTransportConnection(); } }
ModemPlugin implements DuplexPlugin, Modem.Callback { @Override public DuplexTransportConnection createConnection(TransportProperties p) { if (!running) return null; String fromIso = callback.getLocalProperties().get("iso3166"); if (StringUtils.isNullOrEmpty(fromIso)) return null; String toIso = p.get("iso3166"); if (StringUtils.isNullOrEmpty(toIso)) return null; String number = p.get("number"); if (StringUtils.isNullOrEmpty(number)) return null; number = CountryCodes.translate(number, fromIso, toIso); if (number == null) return null; try { if (!modem.dial(number)) return null; } catch (IOException e) { logException(LOG, WARNING, e); resetModem(); return null; } return new ModemTransportConnection(); } ModemPlugin(ModemFactory modemFactory, SerialPortList serialPortList,
			DuplexPluginCallback callback, int maxLatency); }
ModemPlugin implements DuplexPlugin, Modem.Callback { @Override public DuplexTransportConnection createConnection(TransportProperties p) { if (!running) return null; String fromIso = callback.getLocalProperties().get("iso3166"); if (StringUtils.isNullOrEmpty(fromIso)) return null; String toIso = p.get("iso3166"); if (StringUtils.isNullOrEmpty(toIso)) return null; String number = p.get("number"); if (StringUtils.isNullOrEmpty(number)) return null; number = CountryCodes.translate(number, fromIso, toIso); if (number == null) return null; try { if (!modem.dial(number)) return null; } catch (IOException e) { logException(LOG, WARNING, e); resetModem(); return null; } return new ModemTransportConnection(); } 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 DuplexTransportConnection createConnection(TransportProperties p) { if (!running) return null; String fromIso = callback.getLocalProperties().get("iso3166"); if (StringUtils.isNullOrEmpty(fromIso)) return null; String toIso = p.get("iso3166"); if (StringUtils.isNullOrEmpty(toIso)) return null; String number = p.get("number"); if (StringUtils.isNullOrEmpty(number)) return null; number = CountryCodes.translate(number, fromIso, toIso); if (number == null) return null; try { if (!modem.dial(number)) return null; } catch (IOException e) { logException(LOG, WARNING, e); resetModem(); return null; } return new ModemTransportConnection(); } 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();  }