edu.udayton.udri.asset.novatel/test/edu/udayton/udri/asset/novatel/impl/timechanger/TestTimeChangeImpl.java
@Test
    public void testChangeTimeIOException() throws IOException, InterruptedException, AssetException
    {
        when(m_ClientSocket.getOutputStream()).thenReturn(null);
        m_SUT.connectTimeService(m_StatusHandler, PORT);
        
        long time = System.currentTimeMillis() - 1000;
        m_SUT.changeTime(time);
        
        ArgumentCaptor<ComponentStatus> statusCaptor = ArgumentCaptor.forClass(ComponentStatus.class);
        
        verify(m_StatusHandler, timeout(1000)
                .atLeast(2)).handleStatusUpdate(statusCaptor.capture());
        
        m_SUT.disconnectTimeService();
        
        verify(m_Stream, never()).write(Mockito.any(byte[].class));
        
        List<ComponentStatus> list = statusCaptor.getAllValues();
        
        boolean found = false;
        for(ComponentStatus status : list)
        {
            if (status.getStatus().getSummary() == SummaryStatusEnum.BAD)
            {
                assertThat(status.getComponent().getType(), is(ComponentTypeEnum.SOFTWARE_UNIT));
                assertThat(status.getComponent().getDescription(), is("Time Service"));
                assertThat(status.getStatus().getSummary(), is(SummaryStatusEnum.BAD));
                
                found = true;
            }
        }
        assertThat(found, is(true));
    }
/**
     * Verify that when an IOException is thrown in change time it is properly handled.
     */
Verify that when an IOException is thrown in change time it is properly handled.
Verify that when an IOException is thrown in change time it is properly handled .
@Test
    public void testChangeTimeIOException() throws IOException, InterruptedException, AssetException
    {
        when(m_ClientSocket.getOutputStream()).thenReturn(null);
        m_SUT.connectTimeService(m_StatusHandler, PORT);
        long time = System.currentTimeMillis() - 1000;
        m_SUT.changeTime(time);
        ArgumentCaptor<ComponentStatus> statusCaptor = ArgumentCaptor.forClass(ComponentStatus.class);
        verify(m_StatusHandler, timeout(1000)
                .atLeast(2)).handleStatusUpdate(statusCaptor.capture());
        m_SUT.disconnectTimeService();
        verify(m_Stream, never()).write(Mockito.any(byte[].class));
        List<ComponentStatus> list = statusCaptor.getAllValues();
        boolean found = false;
        for(ComponentStatus status : list)
        {
            if (status.getStatus().getSummary() == SummaryStatusEnum.BAD)
            {
                assertThat(status.getComponent().getType(), is(ComponentTypeEnum.SOFTWARE_UNIT));
                assertThat(status.getComponent().getDescription(), is("Time Service"));
                assertThat(status.getStatus().getSummary(), is(SummaryStatusEnum.BAD));
                found = true;
            }
        }
        assertThat(found, is(true));
    }
@ Test public void testChangeTimeIOException ( ) throws IOException , InterruptedException , AssetException { when ( m_ClientSocket . getOutputStream ( ) ) . thenReturn ( null ) ; m_SUT . connectTimeService ( m_StatusHandler , PORT ) ; long time = System . currentTimeMillis ( ) - 1000 ; m_SUT . changeTime ( time ) ; ArgumentCaptor < ComponentStatus > statusCaptor = ArgumentCaptor . forClass ( ComponentStatus . class ) ; verify ( m_StatusHandler , timeout ( 1000 ) . atLeast ( 2 ) ) . handleStatusUpdate ( statusCaptor . capture ( ) ) ; m_SUT . disconnectTimeService ( ) ; verify ( m_Stream , never ( ) ) . write ( Mockito . any ( byte [ ] . class ) ) ; List < ComponentStatus > list = statusCaptor . getAllValues ( ) ; boolean found = false ; for ( ComponentStatus status : list ) { if ( status . getStatus ( ) . getSummary ( ) == SummaryStatusEnum . BAD ) { assertThat ( status . getComponent ( ) . getType ( ) , is ( ComponentTypeEnum . SOFTWARE_UNIT ) ) ; assertThat ( status . getComponent ( ) . getDescription ( ) , is ( "Time Service" ) ) ; assertThat ( status . getStatus ( ) . getSummary ( ) , is ( SummaryStatusEnum . BAD ) ) ; found = true ; } } assertThat ( found , is ( true ) ) ; }
Verify that when an IOException is thrown in change time it is properly handled.
Verify that when an IOException is thrown in change time it is properly handled .