mil.dod.th.ose.core/test/mil/dod/th/ose/core/factory/impl/TestFactoryServiceContextImpl.java
@SuppressWarnings({"rawtypes", "unchecked"})
    @Test
    public void testAddPluginFactory_ExceptionBeforeThread() throws Exception
    {
        ComponentInfo<FactoryInternal> component = 
                ComponentFactoryMocker.mockSingleComponent(FactoryInternal.class, m_FactoryInternalFactory);
        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, m_ProxyComponentFactory);
        
        verify(component.getInstance()).dispose();
        verify(m_CoreBundleContext).ungetService(proxyServiceRef);
        
        assertThat(m_SUT.getFactories().isEmpty(), is(true));
    }
/**
     * Verify if an exception is thrown before reaching thread, factory registration is cleaned up.
     */
Verify if an exception is thrown before reaching thread, factory registration is cleaned up.
Verify if an exception is thrown before reaching thread factory registration is cleaned up .
@SuppressWarnings({"rawtypes", "unchecked"})
    @Test
    public void testAddPluginFactory_ExceptionBeforeThread() throws Exception
    {
        ComponentInfo<FactoryInternal> component = 
                ComponentFactoryMocker.mockSingleComponent(FactoryInternal.class, m_FactoryInternalFactory);
        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, m_ProxyComponentFactory);
        verify(component.getInstance()).dispose();
        verify(m_CoreBundleContext).ungetService(proxyServiceRef);
        assertThat(m_SUT.getFactories().isEmpty(), is(true));
    }
@ SuppressWarnings ( { "rawtypes" , "unchecked" } ) @ Test public void testAddPluginFactory_ExceptionBeforeThread ( ) throws Exception { ComponentInfo < FactoryInternal > component = ComponentFactoryMocker . mockSingleComponent ( FactoryInternal . class , m_FactoryInternalFactory ) ; 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 , m_ProxyComponentFactory ) ; verify ( component . getInstance ( ) ) . dispose ( ) ; verify ( m_CoreBundleContext ) . ungetService ( proxyServiceRef ) ; assertThat ( m_SUT . getFactories ( ) . isEmpty ( ) , is ( true ) ) ; }
Verify if an exception is thrown before reaching thread, factory registration is cleaned up.
Verify if an exception is thrown before reaching thread factory registration is cleaned up .
// replay