mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/ccomm/link/TestLinkLayerServiceProxy.java
@SuppressWarnings({"unchecked", "rawtypes"})
    @Test
    public void testOnRemoveFactory()
    {
        //mock behavior
        BundleContext bContext = mock(BundleContext.class);
        FactoryRegistry reg = mock(FactoryRegistry.class);
        FactoryServiceContext context = mock(FactoryServiceContext.class);
        when(context.getRegistry()).thenReturn(reg);
        
        FactoryInternal factory = mock(FactoryInternal.class);
        when(factory.getProductType()).thenReturn(PRODUCT_TYPE);

        Set<LinkLayer> links = new HashSet<>();
        LinkLayer link1 = mock(LinkLayerInternal.class);
        when(link1.isActivated()).thenReturn(true);
        LinkLayer link2 = mock(LinkLayerInternal.class);
        when(link2.isActivated()).thenReturn(false);
        links.add(link1);
        links.add(link2);
        when(reg.getObjectsByProductType(PRODUCT_TYPE)).thenReturn(links);
        
        m_SUT.activate(bContext);
        
        ArgumentCaptor<EventHandler> handlerCap = ArgumentCaptor.forClass(EventHandler.class);
        verify(bContext).registerService(eq(EventHandler.class), handlerCap.capture(), 
                Mockito.any(Dictionary.class));
        final EventHandler handler = handlerCap.getValue();
       
        //will make the unit test run faster
        Thread handlerThread = new Thread(new Runnable()
        {            
            @Override
            public void run()
            {
                handler.handleEvent(new Event(LinkLayer.TOPIC_DEACTIVATED, new HashMap<String, Object>()));
                handler.handleEvent(new Event(LinkLayer.TOPIC_DEACTIVATED, new HashMap<String, Object>()));
            }
        });

        handlerThread.start();
        m_SUT.onRemoveFactory(context, factory);
        
        //verify deactivated if isActivated returned true
        verify(link1).deactivateLayer();
        verify(link2, never()).deactivateLayer();
    }
/**
     * Verify event reg service is unregistered.
     * Verify link layers that are active are deactivated.
     */
Verify event reg service is unregistered.
Verify link layers that are active are deactivated.
Verify event reg service is unregistered . Verify link layers that are active are deactivated .
@SuppressWarnings({"unchecked", "rawtypes"})
    @Test
    public void testOnRemoveFactory()
    {
        BundleContext bContext = mock(BundleContext.class);
        FactoryRegistry reg = mock(FactoryRegistry.class);
        FactoryServiceContext context = mock(FactoryServiceContext.class);
        when(context.getRegistry()).thenReturn(reg);
        FactoryInternal factory = mock(FactoryInternal.class);
        when(factory.getProductType()).thenReturn(PRODUCT_TYPE);
        Set<LinkLayer> links = new HashSet<>();
        LinkLayer link1 = mock(LinkLayerInternal.class);
        when(link1.isActivated()).thenReturn(true);
        LinkLayer link2 = mock(LinkLayerInternal.class);
        when(link2.isActivated()).thenReturn(false);
        links.add(link1);
        links.add(link2);
        when(reg.getObjectsByProductType(PRODUCT_TYPE)).thenReturn(links);
        m_SUT.activate(bContext);
        ArgumentCaptor<EventHandler> handlerCap = ArgumentCaptor.forClass(EventHandler.class);
        verify(bContext).registerService(eq(EventHandler.class), handlerCap.capture(), 
                Mockito.any(Dictionary.class));
        final EventHandler handler = handlerCap.getValue();
        Thread handlerThread = new Thread(new Runnable()
        {            
            @Override
            public void run()
            {
                handler.handleEvent(new Event(LinkLayer.TOPIC_DEACTIVATED, new HashMap<String, Object>()));
                handler.handleEvent(new Event(LinkLayer.TOPIC_DEACTIVATED, new HashMap<String, Object>()));
            }
        });
        handlerThread.start();
        m_SUT.onRemoveFactory(context, factory);
        verify(link1).deactivateLayer();
        verify(link2, never()).deactivateLayer();
    }
@ SuppressWarnings ( { "unchecked" , "rawtypes" } ) @ Test public void testOnRemoveFactory ( ) { BundleContext bContext = mock ( BundleContext . class ) ; FactoryRegistry reg = mock ( FactoryRegistry . class ) ; FactoryServiceContext context = mock ( FactoryServiceContext . class ) ; when ( context . getRegistry ( ) ) . thenReturn ( reg ) ; FactoryInternal factory = mock ( FactoryInternal . class ) ; when ( factory . getProductType ( ) ) . thenReturn ( PRODUCT_TYPE ) ; Set < LinkLayer > links = new HashSet < > ( ) ; LinkLayer link1 = mock ( LinkLayerInternal . class ) ; when ( link1 . isActivated ( ) ) . thenReturn ( true ) ; LinkLayer link2 = mock ( LinkLayerInternal . class ) ; when ( link2 . isActivated ( ) ) . thenReturn ( false ) ; links . add ( link1 ) ; links . add ( link2 ) ; when ( reg . getObjectsByProductType ( PRODUCT_TYPE ) ) . thenReturn ( links ) ; m_SUT . activate ( bContext ) ; ArgumentCaptor < EventHandler > handlerCap = ArgumentCaptor . forClass ( EventHandler . class ) ; verify ( bContext ) . registerService ( eq ( EventHandler . class ) , handlerCap . capture ( ) , Mockito . any ( Dictionary . class ) ) ; final EventHandler handler = handlerCap . getValue ( ) ; Thread handlerThread = new Thread ( new Runnable ( ) { @ Override public void run ( ) { handler . handleEvent ( new Event ( LinkLayer . TOPIC_DEACTIVATED , new HashMap < String , Object > ( ) ) ) ; handler . handleEvent ( new Event ( LinkLayer . TOPIC_DEACTIVATED , new HashMap < String , Object > ( ) ) ) ; } } ) ; handlerThread . start ( ) ; m_SUT . onRemoveFactory ( context , factory ) ; verify ( link1 ) . deactivateLayer ( ) ; verify ( link2 , never ( ) ) . deactivateLayer ( ) ; }
Verify event reg service is unregistered.
Verify event reg service is unregistered .
//mock behavior //will make the unit test run faster //verify deactivated if isActivated returned true