edu.udayton.udri.asset.novatel/test/edu/udayton/udri/asset/novatel/impl/timechanger/TestTimeChangeImpl.java
@Test
    public void testConnectTimeServiceIOException() throws IOException, InterruptedException
    {
        doThrow(new IOException("error")).when(m_ClientSocketFactory).createClientSocket(
                Mockito.anyString(), Mockito.anyInt());
        
        m_SUT.connectTimeService(m_StatusHandler, PORT);
        
        verify(m_ClientSocketFactory, timeout(100).atLeast(1))
            .createClientSocket(Mockito.anyString(), Mockito.anyInt());
        
        m_SUT.disconnectTimeService();
        
        ArgumentCaptor<ComponentStatus> statusCaptor = ArgumentCaptor.forClass(ComponentStatus.class);
        verify(m_StatusHandler, atLeast(2)).handleStatusUpdate(statusCaptor.capture());

        List<ComponentStatus> status = statusCaptor.getAllValues();
        boolean foundBad = false;
        boolean foundOff = false;
        for (ComponentStatus aStatus : status)
        {
            assertThat(aStatus.getComponent().getType(), is(ComponentTypeEnum.SOFTWARE_UNIT));
            assertThat(aStatus.getComponent().getDescription(), is("Time Service"));

            if (aStatus.getStatus().getSummary() == SummaryStatusEnum.BAD)
            {
                assertThat(aStatus.getStatus().getDescription(), is("error"));
                foundBad = true;
            }
            else if (aStatus.getStatus().getSummary() == SummaryStatusEnum.OFF)
            {
                assertThat(aStatus.getStatus().getDescription(), is("Time service is now off."));
                foundOff = true;
            }
        }
        assertThat(foundBad, is(true));
        assertThat(foundOff, is(true));
    }
/**
     * Verify that when exception occurs on connection that fails
     */
Verify that when exception occurs on connection that fails
Verify that when exception occurs on connection that fails
@Test
    public void testConnectTimeServiceIOException() throws IOException, InterruptedException
    {
        doThrow(new IOException("error")).when(m_ClientSocketFactory).createClientSocket(
                Mockito.anyString(), Mockito.anyInt());
        m_SUT.connectTimeService(m_StatusHandler, PORT);
        verify(m_ClientSocketFactory, timeout(100).atLeast(1))
            .createClientSocket(Mockito.anyString(), Mockito.anyInt());
        m_SUT.disconnectTimeService();
        ArgumentCaptor<ComponentStatus> statusCaptor = ArgumentCaptor.forClass(ComponentStatus.class);
        verify(m_StatusHandler, atLeast(2)).handleStatusUpdate(statusCaptor.capture());
        List<ComponentStatus> status = statusCaptor.getAllValues();
        boolean foundBad = false;
        boolean foundOff = false;
        for (ComponentStatus aStatus : status)
        {
            assertThat(aStatus.getComponent().getType(), is(ComponentTypeEnum.SOFTWARE_UNIT));
            assertThat(aStatus.getComponent().getDescription(), is("Time Service"));
            if (aStatus.getStatus().getSummary() == SummaryStatusEnum.BAD)
            {
                assertThat(aStatus.getStatus().getDescription(), is("error"));
                foundBad = true;
            }
            else if (aStatus.getStatus().getSummary() == SummaryStatusEnum.OFF)
            {
                assertThat(aStatus.getStatus().getDescription(), is("Time service is now off."));
                foundOff = true;
            }
        }
        assertThat(foundBad, is(true));
        assertThat(foundOff, is(true));
    }
@ Test public void testConnectTimeServiceIOException ( ) throws IOException , InterruptedException { doThrow ( new IOException ( "error" ) ) . when ( m_ClientSocketFactory ) . createClientSocket ( Mockito . anyString ( ) , Mockito . anyInt ( ) ) ; m_SUT . connectTimeService ( m_StatusHandler , PORT ) ; verify ( m_ClientSocketFactory , timeout ( 100 ) . atLeast ( 1 ) ) . createClientSocket ( Mockito . anyString ( ) , Mockito . anyInt ( ) ) ; m_SUT . disconnectTimeService ( ) ; ArgumentCaptor < ComponentStatus > statusCaptor = ArgumentCaptor . forClass ( ComponentStatus . class ) ; verify ( m_StatusHandler , atLeast ( 2 ) ) . handleStatusUpdate ( statusCaptor . capture ( ) ) ; List < ComponentStatus > status = statusCaptor . getAllValues ( ) ; boolean foundBad = false ; boolean foundOff = false ; for ( ComponentStatus aStatus : status ) { assertThat ( aStatus . getComponent ( ) . getType ( ) , is ( ComponentTypeEnum . SOFTWARE_UNIT ) ) ; assertThat ( aStatus . getComponent ( ) . getDescription ( ) , is ( "Time Service" ) ) ; if ( aStatus . getStatus ( ) . getSummary ( ) == SummaryStatusEnum . BAD ) { assertThat ( aStatus . getStatus ( ) . getDescription ( ) , is ( "error" ) ) ; foundBad = true ; } else if ( aStatus . getStatus ( ) . getSummary ( ) == SummaryStatusEnum . OFF ) { assertThat ( aStatus . getStatus ( ) . getDescription ( ) , is ( "Time service is now off." ) ) ; foundOff = true ; } } assertThat ( foundBad , is ( true ) ) ; assertThat ( foundOff , is ( true ) ) ; }
Verify that when exception occurs on connection that fails
Verify that when exception occurs on connection that fails