mil.dod.th.ose.core/test/mil/dod/th/ose/core/factory/impl/TestFactoryServiceContextImpl.java
@SuppressWarnings({"rawtypes", "unchecked"})
    @Test
    public void testAddPluginFactory_AlreadyRegistered() throws Exception
    {
        ComponentFactory otherFactoryInternalFactory = mock(ComponentFactory.class);
        ComponentFactory otherProxyComponentFactory = mock(ComponentFactory.class);
        
        // replay initial registration
        testAddPluginFactory();
        
        assertThat(m_SUT.getFactories().size(), is(1));
        
        // mock new component with the same product type
        ComponentInfo<FactoryInternal> component = 
                ComponentFactoryMocker.mockSingleComponent(FactoryInternal.class, otherFactoryInternalFactory);
        FactoryInternal factory = component.getObject();
        
        ServiceReference proxyServiceRef = mock(ServiceReference.class);
        when(proxyServiceRef.getProperty(ComponentConstants.COMPONENT_NAME)).thenReturn(PRODUCT_TYPE);
        when(factory.getProductType()).thenReturn(PRODUCT_TYPE);

        doThrow(new FactoryException("blah")).when(m_FactoryServiceProxy)
            .beforeAddFactory(Mockito.any(FactoryServiceContext.class), Mockito.any(FactoryInternal.class));
        
        // replay
        m_ServiceListenerAdpator.addService(proxyServiceRef, otherProxyComponentFactory);
        
        // should still be holding at 1
        assertThat(m_SUT.getFactories().size(), is(1));
        
        // should not attempt to create another factory instance since product type is duplicated
        verify(otherFactoryInternalFactory, never()).newInstance(Mockito.any(Dictionary.class));
    }
/**
     * Verify if factory is already in map, it will not be registered again.
     */
Verify if factory is already in map, it will not be registered again.
Verify if factory is already in map it will not be registered again .
@SuppressWarnings({"rawtypes", "unchecked"})
    @Test
    public void testAddPluginFactory_AlreadyRegistered() throws Exception
    {
        ComponentFactory otherFactoryInternalFactory = mock(ComponentFactory.class);
        ComponentFactory otherProxyComponentFactory = mock(ComponentFactory.class);
        testAddPluginFactory();
        assertThat(m_SUT.getFactories().size(), is(1));
        ComponentInfo<FactoryInternal> component = 
                ComponentFactoryMocker.mockSingleComponent(FactoryInternal.class, otherFactoryInternalFactory);
        FactoryInternal factory = component.getObject();
        ServiceReference proxyServiceRef = mock(ServiceReference.class);
        when(proxyServiceRef.getProperty(ComponentConstants.COMPONENT_NAME)).thenReturn(PRODUCT_TYPE);
        when(factory.getProductType()).thenReturn(PRODUCT_TYPE);
        doThrow(new FactoryException("blah")).when(m_FactoryServiceProxy)
            .beforeAddFactory(Mockito.any(FactoryServiceContext.class), Mockito.any(FactoryInternal.class));
        m_ServiceListenerAdpator.addService(proxyServiceRef, otherProxyComponentFactory);
        assertThat(m_SUT.getFactories().size(), is(1));
        verify(otherFactoryInternalFactory, never()).newInstance(Mockito.any(Dictionary.class));
    }
@ SuppressWarnings ( { "rawtypes" , "unchecked" } ) @ Test public void testAddPluginFactory_AlreadyRegistered ( ) throws Exception { ComponentFactory otherFactoryInternalFactory = mock ( ComponentFactory . class ) ; ComponentFactory otherProxyComponentFactory = mock ( ComponentFactory . class ) ; testAddPluginFactory ( ) ; assertThat ( m_SUT . getFactories ( ) . size ( ) , is ( 1 ) ) ; ComponentInfo < FactoryInternal > component = ComponentFactoryMocker . mockSingleComponent ( FactoryInternal . class , otherFactoryInternalFactory ) ; FactoryInternal factory = component . getObject ( ) ; ServiceReference proxyServiceRef = mock ( ServiceReference . class ) ; when ( proxyServiceRef . getProperty ( ComponentConstants . COMPONENT_NAME ) ) . thenReturn ( PRODUCT_TYPE ) ; when ( factory . getProductType ( ) ) . thenReturn ( PRODUCT_TYPE ) ; doThrow ( new FactoryException ( "blah" ) ) . when ( m_FactoryServiceProxy ) . beforeAddFactory ( Mockito . any ( FactoryServiceContext . class ) , Mockito . any ( FactoryInternal . class ) ) ; m_ServiceListenerAdpator . addService ( proxyServiceRef , otherProxyComponentFactory ) ; assertThat ( m_SUT . getFactories ( ) . size ( ) , is ( 1 ) ) ; verify ( otherFactoryInternalFactory , never ( ) ) . newInstance ( Mockito . any ( Dictionary . class ) ) ; }
Verify if factory is already in map, it will not be registered again.
Verify if factory is already in map it will not be registered again .
// replay initial registration // mock new component with the same product type // replay // should still be holding at 1 // should not attempt to create another factory instance since product type is duplicated