edu.udayton.udri.asset.novatel/test/edu/udayton/udri/asset/novatel/impl/connection/TestNovatelConnectionMgrImpl.java
@Test
    public void testReconnectWithOpenCloseOpen() throws IllegalArgumentException, CCommException, AssetException, 
        PhysicalLinkException, IOException
    {
        InputStream inStream = new InputStream()
        {
            private char[] chars = ("Asd" + "\r\n" + "As" + "\r\n").toCharArray();
            private int m_Index = 0;
            private boolean read = false;

            @Override
            public int read() throws IOException
            {
                if (m_Index < chars.length)
                {
                    int toReturn = chars[m_Index];
                    m_Index++;
                    return toReturn;
                }
                read = true;
                return -1;
            }
            
            @Override
            public int available() throws IOException
            {
                if (!read)
                {
                    return chars.length;
                }
                return 0;
            }
        };
        
        //Not activated therefore should return false.
        assertThat(m_SUT.isProcessing(), is(false));
        
        when(m_CustomCommService.tryCreatePhysicalLink(PhysicalLinkTypeEnum.SERIAL_PORT, m_PhysPort)).
            thenReturn(m_UUID);
        when(m_CustomCommService.requestPhysicalLink(m_UUID)).thenReturn(m_SerialPort);
        when(m_SerialPort.getInputStream()).thenReturn(mock(InputStream.class), inStream);
        when(m_SerialPort.getName()).thenReturn(m_PhysPort);
        m_SUT.startProcessing(m_PhysPort, m_BaudRate);
        
        when(m_SerialPort.isOpen()).thenReturn(true, true, false);

        //reconnect should close the serial port
        m_SUT.reconnect();
        verify(m_SerialPort).close();
        verify(m_SerialPort).release();
        
        String message = m_SUT.readMessage();
        assertThat(message, is("Asd"));
    }
/**
     * Test the reconnect method with open port, verify it is closed and released.
     * Verify it can be re-acquired.
     */
Test the reconnect method with open port, verify it is closed and released.
Verify it can be re-acquired.
Test the reconnect method with open port verify it is closed and released . Verify it can be re - acquired .
@Test
    public void testReconnectWithOpenCloseOpen() throws IllegalArgumentException, CCommException, AssetException, 
        PhysicalLinkException, IOException
    {
        InputStream inStream = new InputStream()
        {
            private char[] chars = ("Asd" + "\r\n" + "As" + "\r\n").toCharArray();
            private int m_Index = 0;
            private boolean read = false;
            @Override
            public int read() throws IOException
            {
                if (m_Index < chars.length)
                {
                    int toReturn = chars[m_Index];
                    m_Index++;
                    return toReturn;
                }
                read = true;
                return -1;
            }
            @Override
            public int available() throws IOException
            {
                if (!read)
                {
                    return chars.length;
                }
                return 0;
            }
        };
        assertThat(m_SUT.isProcessing(), is(false));
        when(m_CustomCommService.tryCreatePhysicalLink(PhysicalLinkTypeEnum.SERIAL_PORT, m_PhysPort)).
            thenReturn(m_UUID);
        when(m_CustomCommService.requestPhysicalLink(m_UUID)).thenReturn(m_SerialPort);
        when(m_SerialPort.getInputStream()).thenReturn(mock(InputStream.class), inStream);
        when(m_SerialPort.getName()).thenReturn(m_PhysPort);
        m_SUT.startProcessing(m_PhysPort, m_BaudRate);
        when(m_SerialPort.isOpen()).thenReturn(true, true, false);
        m_SUT.reconnect();
        verify(m_SerialPort).close();
        verify(m_SerialPort).release();
        String message = m_SUT.readMessage();
        assertThat(message, is("Asd"));
    }
@ Test public void testReconnectWithOpenCloseOpen ( ) throws IllegalArgumentException , CCommException , AssetException , PhysicalLinkException , IOException { InputStream inStream = new InputStream ( ) { private char [ ] chars = ( "Asd" + "\r\n" + "As" + "\r\n" ) . toCharArray ( ) ; private int m_Index = 0 ; private boolean read = false ; @ Override public int read ( ) throws IOException { if ( m_Index < chars . length ) { int toReturn = chars [ m_Index ] ; m_Index ++ ; return toReturn ; } read = true ; return - 1 ; } @ Override public int available ( ) throws IOException { if ( ! read ) { return chars . length ; } return 0 ; } } ; assertThat ( m_SUT . isProcessing ( ) , is ( false ) ) ; when ( m_CustomCommService . tryCreatePhysicalLink ( PhysicalLinkTypeEnum . SERIAL_PORT , m_PhysPort ) ) . thenReturn ( m_UUID ) ; when ( m_CustomCommService . requestPhysicalLink ( m_UUID ) ) . thenReturn ( m_SerialPort ) ; when ( m_SerialPort . getInputStream ( ) ) . thenReturn ( mock ( InputStream . class ) , inStream ) ; when ( m_SerialPort . getName ( ) ) . thenReturn ( m_PhysPort ) ; m_SUT . startProcessing ( m_PhysPort , m_BaudRate ) ; when ( m_SerialPort . isOpen ( ) ) . thenReturn ( true , true , false ) ; m_SUT . reconnect ( ) ; verify ( m_SerialPort ) . close ( ) ; verify ( m_SerialPort ) . release ( ) ; String message = m_SUT . readMessage ( ) ; assertThat ( message , is ( "Asd" ) ) ; }
Test the reconnect method with open port, verify it is closed and released.
Test the reconnect method with open port verify it is closed and released .
//Not activated therefore should return false. //reconnect should close the serial port