mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/mp/TestMissionProgramSchedulerImpl.java
@Test
    public void testExecutegOneInALittleWhileOneLater() throws InterruptedException
    {
        //activate the component
        m_SUT.activate();
        
        //schedules
        MissionProgramSchedule schedule = TestProgramImpl.createMissionSchedule(System.currentTimeMillis() + 100L, 
                null, true, null, true, true);
        MissionProgramSchedule schedule2 = TestProgramImpl.createMissionSchedule(System.currentTimeMillis() + 200L, 
                null, true, null, true, true);
        
        //more behavior for the program instance
        when(m_Program1.getMissionSchedule()).thenReturn(schedule);
        when(m_Program2.getMissionSchedule()).thenReturn(schedule2);
        
        //mock power management
        WakeLock wakeLock1 = mock(WakeLock.class);
        WakeLock wakeLock2 = mock(WakeLock.class);
        when(m_PowerManager.createWakeLock(m_SUT.getClass(), PROG1_NAME)).thenReturn(wakeLock1);
        when(m_PowerManager.createWakeLock(m_SUT.getClass(), PROG2_NAME)).thenReturn(wakeLock2);

        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        
        //execute
        m_SUT.executeProgram(m_Program1);
        m_SUT.executeProgram(m_Program2);
        
        Thread.sleep(150);
        
        verify(wakeLock1).scheduleWakeTime(new Date(schedule.getStartInterval()));
        verify(wakeLock2).scheduleWakeTime(new Date(schedule2.getStartInterval()));

        //once for the first program executing
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        
        assertThat(eventCaptor.getValue().getTopic(), 
            is(Program.TOPIC_PROGRAM_EXECUTED));
        assertProgramEventProps(eventCaptor.getValue(), m_Program1);
        
        //wait just a little while longer
        Thread.sleep(300);
        
        //once for each program executing
        verify(m_EventAdmin, times(2)).postEvent(eventCaptor.capture());
        
        assertThat(eventCaptor.getValue().getTopic(), 
            is(Program.TOPIC_PROGRAM_EXECUTED));
        assertProgramEventProps(eventCaptor.getValue(), m_Program2);
        
        //sleep a little longer
        Thread.sleep(200);
        
        //verify no more events
        verify(m_EventAdmin, times(2)).postEvent(Mockito.any(Event.class));

        verify(wakeLock1).delete();
        verify(wakeLock2).delete();
    }
/**
     * Test executing multiple programs.
     * Verify that the programs execute.
     */
Test executing multiple programs.
Verify that the programs execute.
Test executing multiple programs . Verify that the programs execute .
@Test
    public void testExecutegOneInALittleWhileOneLater() throws InterruptedException
    {
        m_SUT.activate();
        MissionProgramSchedule schedule = TestProgramImpl.createMissionSchedule(System.currentTimeMillis() + 100L, 
                null, true, null, true, true);
        MissionProgramSchedule schedule2 = TestProgramImpl.createMissionSchedule(System.currentTimeMillis() + 200L, 
                null, true, null, true, true);
        when(m_Program1.getMissionSchedule()).thenReturn(schedule);
        when(m_Program2.getMissionSchedule()).thenReturn(schedule2);
        WakeLock wakeLock1 = mock(WakeLock.class);
        WakeLock wakeLock2 = mock(WakeLock.class);
        when(m_PowerManager.createWakeLock(m_SUT.getClass(), PROG1_NAME)).thenReturn(wakeLock1);
        when(m_PowerManager.createWakeLock(m_SUT.getClass(), PROG2_NAME)).thenReturn(wakeLock2);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        m_SUT.executeProgram(m_Program1);
        m_SUT.executeProgram(m_Program2);
        Thread.sleep(150);
        verify(wakeLock1).scheduleWakeTime(new Date(schedule.getStartInterval()));
        verify(wakeLock2).scheduleWakeTime(new Date(schedule2.getStartInterval()));
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        assertThat(eventCaptor.getValue().getTopic(), 
            is(Program.TOPIC_PROGRAM_EXECUTED));
        assertProgramEventProps(eventCaptor.getValue(), m_Program1);
        Thread.sleep(300);
        verify(m_EventAdmin, times(2)).postEvent(eventCaptor.capture());
        assertThat(eventCaptor.getValue().getTopic(), 
            is(Program.TOPIC_PROGRAM_EXECUTED));
        assertProgramEventProps(eventCaptor.getValue(), m_Program2);
        Thread.sleep(200);
        verify(m_EventAdmin, times(2)).postEvent(Mockito.any(Event.class));
        verify(wakeLock1).delete();
        verify(wakeLock2).delete();
    }
@ Test public void testExecutegOneInALittleWhileOneLater ( ) throws InterruptedException { m_SUT . activate ( ) ; MissionProgramSchedule schedule = TestProgramImpl . createMissionSchedule ( System . currentTimeMillis ( ) + 100L , null , true , null , true , true ) ; MissionProgramSchedule schedule2 = TestProgramImpl . createMissionSchedule ( System . currentTimeMillis ( ) + 200L , null , true , null , true , true ) ; when ( m_Program1 . getMissionSchedule ( ) ) . thenReturn ( schedule ) ; when ( m_Program2 . getMissionSchedule ( ) ) . thenReturn ( schedule2 ) ; WakeLock wakeLock1 = mock ( WakeLock . class ) ; WakeLock wakeLock2 = mock ( WakeLock . class ) ; when ( m_PowerManager . createWakeLock ( m_SUT . getClass ( ) , PROG1_NAME ) ) . thenReturn ( wakeLock1 ) ; when ( m_PowerManager . createWakeLock ( m_SUT . getClass ( ) , PROG2_NAME ) ) . thenReturn ( wakeLock2 ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; m_SUT . executeProgram ( m_Program1 ) ; m_SUT . executeProgram ( m_Program2 ) ; Thread . sleep ( 150 ) ; verify ( wakeLock1 ) . scheduleWakeTime ( new Date ( schedule . getStartInterval ( ) ) ) ; verify ( wakeLock2 ) . scheduleWakeTime ( new Date ( schedule2 . getStartInterval ( ) ) ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; assertThat ( eventCaptor . getValue ( ) . getTopic ( ) , is ( Program . TOPIC_PROGRAM_EXECUTED ) ) ; assertProgramEventProps ( eventCaptor . getValue ( ) , m_Program1 ) ; Thread . sleep ( 300 ) ; verify ( m_EventAdmin , times ( 2 ) ) . postEvent ( eventCaptor . capture ( ) ) ; assertThat ( eventCaptor . getValue ( ) . getTopic ( ) , is ( Program . TOPIC_PROGRAM_EXECUTED ) ) ; assertProgramEventProps ( eventCaptor . getValue ( ) , m_Program2 ) ; Thread . sleep ( 200 ) ; verify ( m_EventAdmin , times ( 2 ) ) . postEvent ( Mockito . any ( Event . class ) ) ; verify ( wakeLock1 ) . delete ( ) ; verify ( wakeLock2 ) . delete ( ) ; }
Test executing multiple programs.
Test executing multiple programs .
//activate the component //schedules //more behavior for the program instance //mock power management //execute //once for the first program executing //wait just a little while longer //once for each program executing //sleep a little longer //verify no more events