mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/controller/TestActiveControllerImpl.java
@Test
    public void testGetActiveController()
    {        
        //get a controller to make the active controller
        ControllerModel model = new ControllerModel(123456, m_ControllerImageInterface);
        
        /**
         * Verify active controller is null, if desired active controller model is not ready. 
         * No ACTIVE_CONTROLLER_CHANGED event should be posted.
         */
        m_SUT.setActiveController(model); 
        when(m_ControllerMgr.getController(eq(123456))).thenReturn(model);
        assertThat(m_SUT.getActiveController(), is(nullValue()));
        
        /**
         * Verify active controller is set if model is not null and is in ready state.
         * 1 ACTIVE_CONTROLLER_CHANGED event should be posted.
         */
        model.setIsReady(true);
        m_SUT.setActiveController(model); //active controller changed
        when(m_ControllerMgr.getController(eq(123456))).thenReturn(model); 
        assertThat((m_SUT.getActiveController()).getId(), is(123456));

        /**
         * mock controller manager returning null, this is the behavior expected when the model is not found to return.
         * 1 ACTIVE_CONTROLLER_CHANGED event should be posted
         */
        ControllerModel modelNull = null;
        when(m_ControllerMgr.getController(eq(123456))).thenReturn(modelNull);        
        assertThat(m_SUT.getActiveController(), is(nullValue())); //active controller changed
        verify(m_GrowlUtil).createLocalFacesMessage(eq(FacesMessage.SEVERITY_INFO), Mockito.anyString(), 
            Mockito.anyString());
        
        /**
         * verify update active controller grabs a new ready controller
         * if controller mgr returns model that's not ready.
         * 2 ACTIVE_CONTROLLER_CHANGED events should be posted.
         */
        ControllerModel model2 = new ControllerModel(7890, m_ControllerImageInterface);
        model2.setIsReady(true);
        model2.setName("model2");
        
        List<ControllerModel> modelList = new ArrayList<ControllerModel>();
        modelList.add(model2);
        modelList.add(model);       
        
        m_SUT.setActiveController(model2); //active controller changed
        model2.setIsReady(false);
        when(m_ControllerMgr.getController(eq(7890))).thenReturn(model2);
        when(m_ControllerMgr.getAllControllers()).thenReturn(modelList);
        assertThat(m_SUT.getActiveController().getId(), is(123456)); //grab first ready controller, controller changed
        
        /**
         * Verify calling get active controller on unchanged active controller does not
         * cause an ACTIVE_CONTROLLER_CHANGED event to be posted. 
         */
        when(m_ControllerMgr.getController(eq(123456))).thenReturn(model);  
        assertThat(m_SUT.getActiveController().getId(), is(123456));
        
        //verify event that the active controller changed 4 times
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, Mockito.times(4)).postEvent(eventCaptor.capture());
        assertThat(eventCaptor.getValue().getTopic(), is(ActiveController.TOPIC_ACTIVE_CONTROLLER_CHANGED));
    }
/**
     * Test getting the active controller.
     */
Test getting the active controller.
Test getting the active controller .
@Test
    public void testGetActiveController()
    {        
        ControllerModel model = new ControllerModel(123456, m_ControllerImageInterface);
        /**
         * Verify active controller is null, if desired active controller model is not ready. 
         * No ACTIVE_CONTROLLER_CHANGED event should be posted.
         */
        m_SUT.setActiveController(model); 
        when(m_ControllerMgr.getController(eq(123456))).thenReturn(model);
        assertThat(m_SUT.getActiveController(), is(nullValue()));
        /**
         * Verify active controller is set if model is not null and is in ready state.
         * 1 ACTIVE_CONTROLLER_CHANGED event should be posted.
         */
        model.setIsReady(true);
        m_SUT.setActiveController(model); 
        when(m_ControllerMgr.getController(eq(123456))).thenReturn(model); 
        assertThat((m_SUT.getActiveController()).getId(), is(123456));
        /**
         * mock controller manager returning null, this is the behavior expected when the model is not found to return.
         * 1 ACTIVE_CONTROLLER_CHANGED event should be posted
         */
        ControllerModel modelNull = null;
        when(m_ControllerMgr.getController(eq(123456))).thenReturn(modelNull);        
        assertThat(m_SUT.getActiveController(), is(nullValue())); 
        verify(m_GrowlUtil).createLocalFacesMessage(eq(FacesMessage.SEVERITY_INFO), Mockito.anyString(), 
            Mockito.anyString());
        /**
         * verify update active controller grabs a new ready controller
         * if controller mgr returns model that's not ready.
         * 2 ACTIVE_CONTROLLER_CHANGED events should be posted.
         */
        ControllerModel model2 = new ControllerModel(7890, m_ControllerImageInterface);
        model2.setIsReady(true);
        model2.setName("model2");
        List<ControllerModel> modelList = new ArrayList<ControllerModel>();
        modelList.add(model2);
        modelList.add(model);       
        m_SUT.setActiveController(model2); 
        model2.setIsReady(false);
        when(m_ControllerMgr.getController(eq(7890))).thenReturn(model2);
        when(m_ControllerMgr.getAllControllers()).thenReturn(modelList);
        assertThat(m_SUT.getActiveController().getId(), is(123456)); 
        /**
         * Verify calling get active controller on unchanged active controller does not
         * cause an ACTIVE_CONTROLLER_CHANGED event to be posted. 
         */
        when(m_ControllerMgr.getController(eq(123456))).thenReturn(model);  
        assertThat(m_SUT.getActiveController().getId(), is(123456));
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, Mockito.times(4)).postEvent(eventCaptor.capture());
        assertThat(eventCaptor.getValue().getTopic(), is(ActiveController.TOPIC_ACTIVE_CONTROLLER_CHANGED));
    }
@ Test public void testGetActiveController ( ) { ControllerModel model = new ControllerModel ( 123456 , m_ControllerImageInterface ) ; /**
         * Verify active controller is null, if desired active controller model is not ready. 
         * No ACTIVE_CONTROLLER_CHANGED event should be posted.
         */ m_SUT . setActiveController ( model ) ; when ( m_ControllerMgr . getController ( eq ( 123456 ) ) ) . thenReturn ( model ) ; assertThat ( m_SUT . getActiveController ( ) , is ( nullValue ( ) ) ) ; /**
         * Verify active controller is set if model is not null and is in ready state.
         * 1 ACTIVE_CONTROLLER_CHANGED event should be posted.
         */ model . setIsReady ( true ) ; m_SUT . setActiveController ( model ) ; when ( m_ControllerMgr . getController ( eq ( 123456 ) ) ) . thenReturn ( model ) ; assertThat ( ( m_SUT . getActiveController ( ) ) . getId ( ) , is ( 123456 ) ) ; /**
         * mock controller manager returning null, this is the behavior expected when the model is not found to return.
         * 1 ACTIVE_CONTROLLER_CHANGED event should be posted
         */ ControllerModel modelNull = null ; when ( m_ControllerMgr . getController ( eq ( 123456 ) ) ) . thenReturn ( modelNull ) ; assertThat ( m_SUT . getActiveController ( ) , is ( nullValue ( ) ) ) ; verify ( m_GrowlUtil ) . createLocalFacesMessage ( eq ( FacesMessage . SEVERITY_INFO ) , Mockito . anyString ( ) , Mockito . anyString ( ) ) ; /**
         * verify update active controller grabs a new ready controller
         * if controller mgr returns model that's not ready.
         * 2 ACTIVE_CONTROLLER_CHANGED events should be posted.
         */ ControllerModel model2 = new ControllerModel ( 7890 , m_ControllerImageInterface ) ; model2 . setIsReady ( true ) ; model2 . setName ( "model2" ) ; List < ControllerModel > modelList = new ArrayList < ControllerModel > ( ) ; modelList . add ( model2 ) ; modelList . add ( model ) ; m_SUT . setActiveController ( model2 ) ; model2 . setIsReady ( false ) ; when ( m_ControllerMgr . getController ( eq ( 7890 ) ) ) . thenReturn ( model2 ) ; when ( m_ControllerMgr . getAllControllers ( ) ) . thenReturn ( modelList ) ; assertThat ( m_SUT . getActiveController ( ) . getId ( ) , is ( 123456 ) ) ; /**
         * Verify calling get active controller on unchanged active controller does not
         * cause an ACTIVE_CONTROLLER_CHANGED event to be posted. 
         */ when ( m_ControllerMgr . getController ( eq ( 123456 ) ) ) . thenReturn ( model ) ; assertThat ( m_SUT . getActiveController ( ) . getId ( ) , is ( 123456 ) ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , Mockito . times ( 4 ) ) . postEvent ( eventCaptor . capture ( ) ) ; assertThat ( eventCaptor . getValue ( ) . getTopic ( ) , is ( ActiveController . TOPIC_ACTIVE_CONTROLLER_CHANGED ) ) ; }
Test getting the active controller.
Test getting the active controller .
//get a controller to make the active controller //active controller changed //active controller changed //active controller changed //grab first ready controller, controller changed //verify event that the active controller changed 4 times