Search in sources :

Example 6 with SerialPortTimeoutException

use of org.openmuc.jrxtx.SerialPortTimeoutException in project OpenMUC by isc-konstanz.

the class DriverTest method testScanMBusSapReadThrowsIOException.

@Test(expected = ScanException.class)
public void testScanMBusSapReadThrowsIOException() throws Exception {
    MBusConnection con = mockNewBuilderCon();
    when(con.read(1)).thenReturn(new VariableDataStructure(null, 0, 0, null, null));
    when(con.read(250)).thenThrow(new SerialPortTimeoutException());
    when(con.read(anyInt())).thenThrow(new IOException());
    final Driver mdriver = new Driver();
    class InterruptScanThread implements Runnable {

        @Override
        public void run() {
            try {
                Thread.sleep(100);
                mdriver.interruptDeviceScan();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    new InterruptScanThread().run();
    mdriver.scanForDevices("/dev/ttyS100:2400", mock(DriverDeviceScanListener.class));
}
Also used : MBusConnection(org.openmuc.jmbus.MBusConnection) SerialPortTimeoutException(org.openmuc.jrxtx.SerialPortTimeoutException) DriverDeviceScanListener(org.openmuc.framework.driver.spi.DriverDeviceScanListener) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) VariableDataStructure(org.openmuc.jmbus.VariableDataStructure) ScanInterruptedException(org.openmuc.framework.config.ScanInterruptedException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

SerialPortTimeoutException (org.openmuc.jrxtx.SerialPortTimeoutException)6 MBusConnection (org.openmuc.jmbus.MBusConnection)5 VariableDataStructure (org.openmuc.jmbus.VariableDataStructure)5 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 IOException (java.io.IOException)2 ChannelRecordContainer (org.openmuc.framework.driver.spi.ChannelRecordContainer)2 DriverDeviceScanListener (org.openmuc.framework.driver.spi.DriverDeviceScanListener)2 InterruptedIOException (java.io.InterruptedIOException)1 ArrayList (java.util.ArrayList)1 ScanInterruptedException (org.openmuc.framework.config.ScanInterruptedException)1 Record (org.openmuc.framework.data.Record)1 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)1 DataRecord (org.openmuc.jmbus.DataRecord)1