### Question:
Driver implements DriverService { @Override public void scanForDevices(String settingsString, DriverDeviceScanListener listener) throws ArgumentSyntaxException, ScanException, ScanInterruptedException { interruptScan = false; Settings settings = new Settings(settingsString, true); MBusConnection mBusConnection; if (!interfaces.containsKey(settings.scanConnectionAddress)) { try { if (settings.host.isEmpty()) { mBusConnection = MBusConnection.newSerialBuilder(settings.scanConnectionAddress) .setBaudrate(settings.baudRate) .setTimeout(settings.timeout) .build(); } else { mBusConnection = MBusConnection.newTcpBuilder(settings.host, settings.port) .setTimeout(settings.timeout) .setConnectionTimeout(settings.connectionTimeout) .build(); } } catch (IOException e) { throw new ScanException(e); } if (logger.isTraceEnabled()) { mBusConnection.setVerboseMessageListener(new VerboseMessageListenerImpl()); } } else { mBusConnection = interfaces.get(settings.scanConnectionAddress).getMBusConnection(); } try { if (settings.scanSecondary) { SecondaryAddressListenerImplementation secondaryAddressListenerImplementation = new SecondaryAddressListenerImplementation( listener, settings.scanConnectionAddress); mBusConnection.scan("ffffffff", secondaryAddressListenerImplementation); } else { scanPrimaryAddress(listener, settings, mBusConnection); } } catch (IOException e) { logger.error("Failed to scan for devices.", e); } finally { mBusConnection.close(); } }  @Override DriverInfo getInfo(); @Override void scanForDevices(String settingsString, DriverDeviceScanListener listener); @Override void interruptDeviceScan(); @Override Connection connect(String deviceAddress, String settingsString);  }### Answer:
@Test public void testScanForDevices() throws Exception { scan("/dev/ttyS100:2400"); }
@Test(expected = ScanException.class) public void scanConOpenIOException() throws Exception { MBusSerialBuilder builder = mock(MBusSerialBuilder.class); whenNew(MBusSerialBuilder.class).withAnyArguments().thenReturn(builder); when(builder.setBaudrate(anyInt())).thenReturn(builder); when(builder.setTimeout(anyInt())).thenReturn(builder); when(builder.build()).thenThrow(new IOException()); new Driver().scanForDevices("/dev/ttyS100:2400", mock(DriverDeviceScanListener.class)); }