edu.udayton.udri.asset.novatel/test/edu/udayton/udri/asset/novatel/impl/connection/TestNovatelConnectionMgrImpl.java
@Test
    public void testStartProcessingAndReadMessage() throws IllegalArgumentException, CCommException, 
        PhysicalLinkException, AssetException, InterruptedException, IOException
    {
        when(m_CustomCommService.tryCreatePhysicalLink(PhysicalLinkTypeEnum.SERIAL_PORT, m_PhysPort)).
            thenReturn(m_UUID);
        when(m_CustomCommService.requestPhysicalLink(m_UUID)).thenReturn(m_SerialPort);
        final String novatelTimeString = "#TIMEA,COM1,0,48.5,FINESTEERING,1702,47.848,00000000,ddae,7053;VALID," 
                + "-3.432839221e-09,6.603391298e-08,-16.00000000000,2013,11,6,15,40,51000,VALID*10581099";
        final String novatelPVAString = "#INSPVAA,COM1,0,31.0,FINESTEERING,1264,144088.000,00040000,5615,1541'1264," 
                + "144088.002284950,51.116827527,-114.037738908,401.191547167,354.846489850,108.429407241," 
                + "-10.837482850,1.116219952,-3.476059035,7.372686190,INS_ALIGNMENT_COMPLETE*af719fd9";

        // the input stream
        InputStream inStream = new InputStream()
        {
            private char[] chars = (novatelPVAString + "\r\n" + novatelTimeString + "\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;
            }
        };
        when(m_SerialPort.getInputStream()).thenReturn(inStream);
        
        m_SUT.startProcessing(m_PhysPort, m_BaudRate);
        
        String message = m_SUT.readMessage();
        assertThat(message, is(novatelPVAString));
        message = m_SUT.readMessage();
        assertThat(message, is(novatelTimeString));
        message = m_SUT.readMessage();
        assertThat(message, is(nullValue()));
    }
/**
     * Test the start processing method.
     * Verify that read thread is initialized and that data is posted to the event admin.
     */
Test the start processing method.
Verify that read thread is initialized and that data is posted to the event admin.
Test the start processing method . Verify that read thread is initialized and that data is posted to the event admin .
@Test
    public void testStartProcessingAndReadMessage() throws IllegalArgumentException, CCommException, 
        PhysicalLinkException, AssetException, InterruptedException, IOException
    {
        when(m_CustomCommService.tryCreatePhysicalLink(PhysicalLinkTypeEnum.SERIAL_PORT, m_PhysPort)).
            thenReturn(m_UUID);
        when(m_CustomCommService.requestPhysicalLink(m_UUID)).thenReturn(m_SerialPort);
        final String novatelTimeString = "#TIMEA,COM1,0,48.5,FINESTEERING,1702,47.848,00000000,ddae,7053;VALID," 
                + "-3.432839221e-09,6.603391298e-08,-16.00000000000,2013,11,6,15,40,51000,VALID*10581099";
        final String novatelPVAString = "#INSPVAA,COM1,0,31.0,FINESTEERING,1264,144088.000,00040000,5615,1541'1264," 
                + "144088.002284950,51.116827527,-114.037738908,401.191547167,354.846489850,108.429407241," 
                + "-10.837482850,1.116219952,-3.476059035,7.372686190,INS_ALIGNMENT_COMPLETE*af719fd9";
        InputStream inStream = new InputStream()
        {
            private char[] chars = (novatelPVAString + "\r\n" + novatelTimeString + "\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;
            }
        };
        when(m_SerialPort.getInputStream()).thenReturn(inStream);
        m_SUT.startProcessing(m_PhysPort, m_BaudRate);
        String message = m_SUT.readMessage();
        assertThat(message, is(novatelPVAString));
        message = m_SUT.readMessage();
        assertThat(message, is(novatelTimeString));
        message = m_SUT.readMessage();
        assertThat(message, is(nullValue()));
    }
@ Test public void testStartProcessingAndReadMessage ( ) throws IllegalArgumentException , CCommException , PhysicalLinkException , AssetException , InterruptedException , IOException { when ( m_CustomCommService . tryCreatePhysicalLink ( PhysicalLinkTypeEnum . SERIAL_PORT , m_PhysPort ) ) . thenReturn ( m_UUID ) ; when ( m_CustomCommService . requestPhysicalLink ( m_UUID ) ) . thenReturn ( m_SerialPort ) ; final String novatelTimeString = "#TIMEA,COM1,0,48.5,FINESTEERING,1702,47.848,00000000,ddae,7053;VALID," + "-3.432839221e-09,6.603391298e-08,-16.00000000000,2013,11,6,15,40,51000,VALID*10581099" ; final String novatelPVAString = "#INSPVAA,COM1,0,31.0,FINESTEERING,1264,144088.000,00040000,5615,1541'1264," + "144088.002284950,51.116827527,-114.037738908,401.191547167,354.846489850,108.429407241," + "-10.837482850,1.116219952,-3.476059035,7.372686190,INS_ALIGNMENT_COMPLETE*af719fd9" ; InputStream inStream = new InputStream ( ) { private char [ ] chars = ( novatelPVAString + "\r\n" + novatelTimeString + "\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 ; } } ; when ( m_SerialPort . getInputStream ( ) ) . thenReturn ( inStream ) ; m_SUT . startProcessing ( m_PhysPort , m_BaudRate ) ; String message = m_SUT . readMessage ( ) ; assertThat ( message , is ( novatelPVAString ) ) ; message = m_SUT . readMessage ( ) ; assertThat ( message , is ( novatelTimeString ) ) ; message = m_SUT . readMessage ( ) ; assertThat ( message , is ( nullValue ( ) ) ) ; }
Test the start processing method.
Test the start processing method .
// the input stream