mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/ccomm/CustomCommsServiceImpl_TestCommon.java
@SuppressWarnings({"rawtypes", "unchecked"})
    protected void stubServices() throws Exception
    {
        m_SUT = new CustomCommsServiceImpl();
        MockitoAnnotations.initMocks(this);
        m_SUT.setLoggingService(LoggingServiceMocker.createMock());

        m_Context = mock(BundleContext.class);
        m_PhysicalLinkFactoryObjectDataManager = mock(PhysicalLinkFactoryObjectDataManager.class);
        m_LinkLayerFactoryObjectDataManager = mock(LinkLayerFactoryObjectDataManager.class);
        m_TransportLayerFactoryObjectDataManager = mock(TransportLayerFactoryObjectDataManager.class);
        
        FactoryObjectDataManagerMocker.createMockFactoryObjectDataManager(m_PhysicalLinkFactoryObjectDataManager);
        FactoryObjectDataManagerMocker.createMockFactoryObjectDataManager(m_LinkLayerFactoryObjectDataManager);
        FactoryObjectDataManagerMocker.createMockFactoryObjectDataManager(m_TransportLayerFactoryObjectDataManager);
        
        m_PhysicalLinkProxy = mock(PhysicalLinkServiceProxy.class);
        m_LinkLayerProxy = mock(LinkLayerServiceProxy.class);
        m_TransportLayerProxy = mock(TransportLayerServiceProxy.class);

        when(m_PowerManager.createWakeLock(m_SUT.getClass(), "coreCustomCommsService")).thenReturn(m_WakeLock);

        m_SUT.setPhysicalLinkFactoryServiceProxy(m_PhysicalLinkProxy);
        m_SUT.setLinkLayerFactoryServiceProxy(m_LinkLayerProxy);
        m_SUT.setTransportLayerFactoryServiceProxy(m_TransportLayerProxy);
        m_SUT.setFactoryServiceContextFactory(serviceContextFactory);
        m_SUT.setPowerManager(m_PowerManager);
        
        List<ComponentInfo<FactoryServiceContext>> serviceContextComps = 
                ComponentFactoryMocker.mockComponents(FactoryServiceContext.class, serviceContextFactory, 3);
        m_PhysicalLinkServiceContext = serviceContextComps.get(0).getObject();
        m_LinkLayerServiceContext = serviceContextComps.get(1).getObject();
        m_TransportLayerServiceContext = serviceContextComps.get(2).getObject();
        
        m_PhysicalLinkComp = serviceContextComps.get(0).getInstance();
        m_LinkLayerComp = serviceContextComps.get(1).getInstance();
        m_TransportLayerComp = serviceContextComps.get(2).getInstance();
        
        //they are reg'ed in order: phys, link, trans
        m_PhysRegistry = mock(FactoryRegistry.class);
        m_LinkRegistry = mock(FactoryRegistry.class);
        m_TransRegistry = mock(FactoryRegistry.class);
        m_PhysFactory = mock(FactoryInternal.class);
        m_LinkFactory = mock(FactoryInternal.class);
        m_TransFactory = mock(FactoryInternal.class);
        m_PhysInternal = mock(PhysicalLinkInternal.class);
        m_LinkInternal = mock(LinkLayerInternal.class);
        m_TransInternal = mock(TransportLayerInternal.class);
        
        when(m_PhysicalLinkServiceContext.getRegistry()).thenReturn(m_PhysRegistry);
        when(m_LinkLayerServiceContext.getRegistry()).thenReturn(m_LinkRegistry);
        when(m_TransportLayerServiceContext.getRegistry()).thenReturn(m_TransRegistry);
        
        when(m_PhysicalLinkServiceContext.getFactories()).thenReturn(
                ImmutableMap.builder().put(PL_PRODUCT_TYPE, m_PhysFactory).build());
        when(m_LinkLayerServiceContext.getFactories()).thenReturn(
                ImmutableMap.builder().put(LL_PRODUCT_TYPE, m_LinkFactory).build());
        when(m_TransportLayerServiceContext.getFactories()).thenReturn(
                ImmutableMap.builder().put(TL_PRODUCT_TYPE, m_TransFactory).build());
        
        //uuids
        m_PhysUuidUno = UUID.randomUUID();
        m_LinkUuidUno = UUID.randomUUID();
        
        //factory mocking phys
        m_PhyCaps = new PhysicalLinkCapabilities().withLinkType(PhysicalLinkTypeEnum.SERIAL_PORT);
        when(m_PhysFactory.getProductName()).thenReturn("SerialPortProxy1");
        when(m_PhysFactory.getProductType()).thenReturn(PL_PRODUCT_TYPE);
        when(m_PhysFactory.getPhysicalLinkCapabilities()).thenReturn(m_PhyCaps);
        
        //factory mocking link
        when(m_LinkFactory.getProductName()).thenReturn("LinkyLink");
        when(m_LinkFactory.getProductType()).thenReturn(LL_PRODUCT_TYPE);
        when(m_LinkFactory.getLinkLayerCapabilities()).thenReturn(m_LinkLayerCapabilities );
        
        //factory mocking trans
        when(m_TransFactory.getProductName()).thenReturn("TrannyLayer");
        when(m_TransFactory.getProductType()).thenReturn(TL_PRODUCT_TYPE);
        
        //internal setup phys
        when(m_PhysInternal.getUuid()).thenReturn(m_PhysUuidUno);
        when(m_PhysRegistry.createNewObject(eq(m_PhysFactory), Mockito.anyString(), Mockito.any(Map.class))).
            thenReturn(m_PhysInternal);
        
        //internal setup linklayer
        when(m_LinkInternal.getUuid()).thenReturn(m_LinkUuidUno);
        when(m_LinkRegistry.createNewObject(eq(m_LinkFactory), Mockito.anyString(), Mockito.any(Map.class))).
            thenReturn(m_LinkInternal);
        when(m_LinkInternal.getFactory()).thenReturn(m_LinkFactory);
        
        //internal setup trans layer
        when(m_TransInternal.getUuid()).thenReturn(m_TransUuidUno);
        when(m_TransRegistry.createNewObject(eq(m_TransFactory), Mockito.anyString(), Mockito.any(Map.class))).
            thenReturn(m_TransInternal);
        when(m_TransInternal.getFactory()).thenReturn(m_TransFactory);
        
        m_SUT.activate(m_Context);
    }
/**
     * Mock all needed objects and stub them out.
     */
Mock all needed objects and stub them out.
Mock all needed objects and stub them out .
@SuppressWarnings({"rawtypes", "unchecked"})
    protected void stubServices() throws Exception
    {
        m_SUT = new CustomCommsServiceImpl();
        MockitoAnnotations.initMocks(this);
        m_SUT.setLoggingService(LoggingServiceMocker.createMock());
        m_Context = mock(BundleContext.class);
        m_PhysicalLinkFactoryObjectDataManager = mock(PhysicalLinkFactoryObjectDataManager.class);
        m_LinkLayerFactoryObjectDataManager = mock(LinkLayerFactoryObjectDataManager.class);
        m_TransportLayerFactoryObjectDataManager = mock(TransportLayerFactoryObjectDataManager.class);
        FactoryObjectDataManagerMocker.createMockFactoryObjectDataManager(m_PhysicalLinkFactoryObjectDataManager);
        FactoryObjectDataManagerMocker.createMockFactoryObjectDataManager(m_LinkLayerFactoryObjectDataManager);
        FactoryObjectDataManagerMocker.createMockFactoryObjectDataManager(m_TransportLayerFactoryObjectDataManager);
        m_PhysicalLinkProxy = mock(PhysicalLinkServiceProxy.class);
        m_LinkLayerProxy = mock(LinkLayerServiceProxy.class);
        m_TransportLayerProxy = mock(TransportLayerServiceProxy.class);
        when(m_PowerManager.createWakeLock(m_SUT.getClass(), "coreCustomCommsService")).thenReturn(m_WakeLock);
        m_SUT.setPhysicalLinkFactoryServiceProxy(m_PhysicalLinkProxy);
        m_SUT.setLinkLayerFactoryServiceProxy(m_LinkLayerProxy);
        m_SUT.setTransportLayerFactoryServiceProxy(m_TransportLayerProxy);
        m_SUT.setFactoryServiceContextFactory(serviceContextFactory);
        m_SUT.setPowerManager(m_PowerManager);
        List<ComponentInfo<FactoryServiceContext>> serviceContextComps = 
                ComponentFactoryMocker.mockComponents(FactoryServiceContext.class, serviceContextFactory, 3);
        m_PhysicalLinkServiceContext = serviceContextComps.get(0).getObject();
        m_LinkLayerServiceContext = serviceContextComps.get(1).getObject();
        m_TransportLayerServiceContext = serviceContextComps.get(2).getObject();
        m_PhysicalLinkComp = serviceContextComps.get(0).getInstance();
        m_LinkLayerComp = serviceContextComps.get(1).getInstance();
        m_TransportLayerComp = serviceContextComps.get(2).getInstance();
        m_PhysRegistry = mock(FactoryRegistry.class);
        m_LinkRegistry = mock(FactoryRegistry.class);
        m_TransRegistry = mock(FactoryRegistry.class);
        m_PhysFactory = mock(FactoryInternal.class);
        m_LinkFactory = mock(FactoryInternal.class);
        m_TransFactory = mock(FactoryInternal.class);
        m_PhysInternal = mock(PhysicalLinkInternal.class);
        m_LinkInternal = mock(LinkLayerInternal.class);
        m_TransInternal = mock(TransportLayerInternal.class);
        when(m_PhysicalLinkServiceContext.getRegistry()).thenReturn(m_PhysRegistry);
        when(m_LinkLayerServiceContext.getRegistry()).thenReturn(m_LinkRegistry);
        when(m_TransportLayerServiceContext.getRegistry()).thenReturn(m_TransRegistry);
        when(m_PhysicalLinkServiceContext.getFactories()).thenReturn(
                ImmutableMap.builder().put(PL_PRODUCT_TYPE, m_PhysFactory).build());
        when(m_LinkLayerServiceContext.getFactories()).thenReturn(
                ImmutableMap.builder().put(LL_PRODUCT_TYPE, m_LinkFactory).build());
        when(m_TransportLayerServiceContext.getFactories()).thenReturn(
                ImmutableMap.builder().put(TL_PRODUCT_TYPE, m_TransFactory).build());
        m_PhysUuidUno = UUID.randomUUID();
        m_LinkUuidUno = UUID.randomUUID();
        m_PhyCaps = new PhysicalLinkCapabilities().withLinkType(PhysicalLinkTypeEnum.SERIAL_PORT);
        when(m_PhysFactory.getProductName()).thenReturn("SerialPortProxy1");
        when(m_PhysFactory.getProductType()).thenReturn(PL_PRODUCT_TYPE);
        when(m_PhysFactory.getPhysicalLinkCapabilities()).thenReturn(m_PhyCaps);
        when(m_LinkFactory.getProductName()).thenReturn("LinkyLink");
        when(m_LinkFactory.getProductType()).thenReturn(LL_PRODUCT_TYPE);
        when(m_LinkFactory.getLinkLayerCapabilities()).thenReturn(m_LinkLayerCapabilities );
        when(m_TransFactory.getProductName()).thenReturn("TrannyLayer");
        when(m_TransFactory.getProductType()).thenReturn(TL_PRODUCT_TYPE);
        when(m_PhysInternal.getUuid()).thenReturn(m_PhysUuidUno);
        when(m_PhysRegistry.createNewObject(eq(m_PhysFactory), Mockito.anyString(), Mockito.any(Map.class))).
            thenReturn(m_PhysInternal);
        when(m_LinkInternal.getUuid()).thenReturn(m_LinkUuidUno);
        when(m_LinkRegistry.createNewObject(eq(m_LinkFactory), Mockito.anyString(), Mockito.any(Map.class))).
            thenReturn(m_LinkInternal);
        when(m_LinkInternal.getFactory()).thenReturn(m_LinkFactory);
        when(m_TransInternal.getUuid()).thenReturn(m_TransUuidUno);
        when(m_TransRegistry.createNewObject(eq(m_TransFactory), Mockito.anyString(), Mockito.any(Map.class))).
            thenReturn(m_TransInternal);
        when(m_TransInternal.getFactory()).thenReturn(m_TransFactory);
        m_SUT.activate(m_Context);
    }
@ SuppressWarnings ( { "rawtypes" , "unchecked" } ) protected void stubServices ( ) throws Exception { m_SUT = new CustomCommsServiceImpl ( ) ; MockitoAnnotations . initMocks ( this ) ; m_SUT . setLoggingService ( LoggingServiceMocker . createMock ( ) ) ; m_Context = mock ( BundleContext . class ) ; m_PhysicalLinkFactoryObjectDataManager = mock ( PhysicalLinkFactoryObjectDataManager . class ) ; m_LinkLayerFactoryObjectDataManager = mock ( LinkLayerFactoryObjectDataManager . class ) ; m_TransportLayerFactoryObjectDataManager = mock ( TransportLayerFactoryObjectDataManager . class ) ; FactoryObjectDataManagerMocker . createMockFactoryObjectDataManager ( m_PhysicalLinkFactoryObjectDataManager ) ; FactoryObjectDataManagerMocker . createMockFactoryObjectDataManager ( m_LinkLayerFactoryObjectDataManager ) ; FactoryObjectDataManagerMocker . createMockFactoryObjectDataManager ( m_TransportLayerFactoryObjectDataManager ) ; m_PhysicalLinkProxy = mock ( PhysicalLinkServiceProxy . class ) ; m_LinkLayerProxy = mock ( LinkLayerServiceProxy . class ) ; m_TransportLayerProxy = mock ( TransportLayerServiceProxy . class ) ; when ( m_PowerManager . createWakeLock ( m_SUT . getClass ( ) , "coreCustomCommsService" ) ) . thenReturn ( m_WakeLock ) ; m_SUT . setPhysicalLinkFactoryServiceProxy ( m_PhysicalLinkProxy ) ; m_SUT . setLinkLayerFactoryServiceProxy ( m_LinkLayerProxy ) ; m_SUT . setTransportLayerFactoryServiceProxy ( m_TransportLayerProxy ) ; m_SUT . setFactoryServiceContextFactory ( serviceContextFactory ) ; m_SUT . setPowerManager ( m_PowerManager ) ; List < ComponentInfo < FactoryServiceContext > > serviceContextComps = ComponentFactoryMocker . mockComponents ( FactoryServiceContext . class , serviceContextFactory , 3 ) ; m_PhysicalLinkServiceContext = serviceContextComps . get ( 0 ) . getObject ( ) ; m_LinkLayerServiceContext = serviceContextComps . get ( 1 ) . getObject ( ) ; m_TransportLayerServiceContext = serviceContextComps . get ( 2 ) . getObject ( ) ; m_PhysicalLinkComp = serviceContextComps . get ( 0 ) . getInstance ( ) ; m_LinkLayerComp = serviceContextComps . get ( 1 ) . getInstance ( ) ; m_TransportLayerComp = serviceContextComps . get ( 2 ) . getInstance ( ) ; m_PhysRegistry = mock ( FactoryRegistry . class ) ; m_LinkRegistry = mock ( FactoryRegistry . class ) ; m_TransRegistry = mock ( FactoryRegistry . class ) ; m_PhysFactory = mock ( FactoryInternal . class ) ; m_LinkFactory = mock ( FactoryInternal . class ) ; m_TransFactory = mock ( FactoryInternal . class ) ; m_PhysInternal = mock ( PhysicalLinkInternal . class ) ; m_LinkInternal = mock ( LinkLayerInternal . class ) ; m_TransInternal = mock ( TransportLayerInternal . class ) ; when ( m_PhysicalLinkServiceContext . getRegistry ( ) ) . thenReturn ( m_PhysRegistry ) ; when ( m_LinkLayerServiceContext . getRegistry ( ) ) . thenReturn ( m_LinkRegistry ) ; when ( m_TransportLayerServiceContext . getRegistry ( ) ) . thenReturn ( m_TransRegistry ) ; when ( m_PhysicalLinkServiceContext . getFactories ( ) ) . thenReturn ( ImmutableMap . builder ( ) . put ( PL_PRODUCT_TYPE , m_PhysFactory ) . build ( ) ) ; when ( m_LinkLayerServiceContext . getFactories ( ) ) . thenReturn ( ImmutableMap . builder ( ) . put ( LL_PRODUCT_TYPE , m_LinkFactory ) . build ( ) ) ; when ( m_TransportLayerServiceContext . getFactories ( ) ) . thenReturn ( ImmutableMap . builder ( ) . put ( TL_PRODUCT_TYPE , m_TransFactory ) . build ( ) ) ; m_PhysUuidUno = UUID . randomUUID ( ) ; m_LinkUuidUno = UUID . randomUUID ( ) ; m_PhyCaps = new PhysicalLinkCapabilities ( ) . withLinkType ( PhysicalLinkTypeEnum . SERIAL_PORT ) ; when ( m_PhysFactory . getProductName ( ) ) . thenReturn ( "SerialPortProxy1" ) ; when ( m_PhysFactory . getProductType ( ) ) . thenReturn ( PL_PRODUCT_TYPE ) ; when ( m_PhysFactory . getPhysicalLinkCapabilities ( ) ) . thenReturn ( m_PhyCaps ) ; when ( m_LinkFactory . getProductName ( ) ) . thenReturn ( "LinkyLink" ) ; when ( m_LinkFactory . getProductType ( ) ) . thenReturn ( LL_PRODUCT_TYPE ) ; when ( m_LinkFactory . getLinkLayerCapabilities ( ) ) . thenReturn ( m_LinkLayerCapabilities ) ; when ( m_TransFactory . getProductName ( ) ) . thenReturn ( "TrannyLayer" ) ; when ( m_TransFactory . getProductType ( ) ) . thenReturn ( TL_PRODUCT_TYPE ) ; when ( m_PhysInternal . getUuid ( ) ) . thenReturn ( m_PhysUuidUno ) ; when ( m_PhysRegistry . createNewObject ( eq ( m_PhysFactory ) , Mockito . anyString ( ) , Mockito . any ( Map . class ) ) ) . thenReturn ( m_PhysInternal ) ; when ( m_LinkInternal . getUuid ( ) ) . thenReturn ( m_LinkUuidUno ) ; when ( m_LinkRegistry . createNewObject ( eq ( m_LinkFactory ) , Mockito . anyString ( ) , Mockito . any ( Map . class ) ) ) . thenReturn ( m_LinkInternal ) ; when ( m_LinkInternal . getFactory ( ) ) . thenReturn ( m_LinkFactory ) ; when ( m_TransInternal . getUuid ( ) ) . thenReturn ( m_TransUuidUno ) ; when ( m_TransRegistry . createNewObject ( eq ( m_TransFactory ) , Mockito . anyString ( ) , Mockito . any ( Map . class ) ) ) . thenReturn ( m_TransInternal ) ; when ( m_TransInternal . getFactory ( ) ) . thenReturn ( m_TransFactory ) ; m_SUT . activate ( m_Context ) ; }
Mock all needed objects and stub them out.
Mock all needed objects and stub them out .
//they are reg'ed in order: phys, link, trans //uuids //factory mocking phys //factory mocking link //factory mocking trans //internal setup phys //internal setup linklayer //internal setup trans layer