mil.dod.th.ose.core/test/mil/dod/th/ose/core/FactoryObjectMocker.java
public static <T extends FactoryObject> T mockFactoryObject(Class<T> type, 
            String pid, final Config config)
    {
        MockSettings settings = withSettings().extraInterfaces(FactoryObjectInternal.class);
        if (config != null && config.getExtraInterfaces().length > 0)
        {
            settings.extraInterfaces(config.getExtraInterfaces());
        }
            
        T object = mock(type, settings);
        when(object.getUuid()).thenReturn(UUID.randomUUID());
        when(object.getPid()).thenReturn(pid);
        when(object.getName()).thenReturn(pid + "-name");
        
        FactoryDescriptor factory;
        String factoryClassName = type.getName() + "Factory";
        try
        {
            factory = (FactoryDescriptor)mock(Class.forName(factoryClassName));
        }
        catch (Exception e)
        {
            throw new IllegalStateException("Unable to mock class: " + factoryClassName);
        }

        String proxyClassName = type.getName() + "Proxy";
        doReturn(proxyClassName).when(factory).getProductType();
        
        when(object.getFactory()).thenReturn(factory);
        
        FactoryObjectInternal internalObj = (FactoryObjectInternal)object;
        doAnswer(new Answer<Object>()
        {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable
            {
                m_NameMap.put((FactoryObject)invocation.getMock(), (String)invocation.getArguments()[0]);
                return null;
            }
        }).when(internalObj).internalSetName(anyString());
        when(object.getName()).thenAnswer(new Answer<String>()
        {

            @Override
            public String answer(InvocationOnMock invocation) throws Throwable
            {
                return m_NameMap.get(invocation.getMock());
            }
        });
        
        return object;
    }
/**
     * Mock a factory object of the given type including the mocking of its factory.
     * 
     * @param type
     *      type of factory object to mock
     * @param pid
     *      configuration PID to use for the factory object
     * @param config
     *      extra configuration to give to the factory object or null if no configuration
     * @return
     *      the mocked factory object
     */
Mock a factory object of the given type including the mocking of its factory.

@param type
type of factory object to mock
@param pid
configuration PID to use for the factory object
@param config
extra configuration to give to the factory object or null if no configuration
@return
the mocked factory object
Mock a factory object of the given type including the mocking of its factory . @param type type of factory object to mock @param pid configuration PID to use for the factory object @param config extra configuration to give to the factory object or null if no configuration @return the mocked factory object
public static <T extends FactoryObject> T mockFactoryObject(Class<T> type, 
            String pid, final Config config)
    {
        MockSettings settings = withSettings().extraInterfaces(FactoryObjectInternal.class);
        if (config != null && config.getExtraInterfaces().length > 0)
        {
            settings.extraInterfaces(config.getExtraInterfaces());
        }
        T object = mock(type, settings);
        when(object.getUuid()).thenReturn(UUID.randomUUID());
        when(object.getPid()).thenReturn(pid);
        when(object.getName()).thenReturn(pid + "-name");
        FactoryDescriptor factory;
        String factoryClassName = type.getName() + "Factory";
        try
        {
            factory = (FactoryDescriptor)mock(Class.forName(factoryClassName));
        }
        catch (Exception e)
        {
            throw new IllegalStateException("Unable to mock class: " + factoryClassName);
        }
        String proxyClassName = type.getName() + "Proxy";
        doReturn(proxyClassName).when(factory).getProductType();
        when(object.getFactory()).thenReturn(factory);
        FactoryObjectInternal internalObj = (FactoryObjectInternal)object;
        doAnswer(new Answer<Object>()
        {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable
            {
                m_NameMap.put((FactoryObject)invocation.getMock(), (String)invocation.getArguments()[0]);
                return null;
            }
        }).when(internalObj).internalSetName(anyString());
        when(object.getName()).thenAnswer(new Answer<String>()
        {
            @Override
            public String answer(InvocationOnMock invocation) throws Throwable
            {
                return m_NameMap.get(invocation.getMock());
            }
        });
        return object;
    }
public static < T extends FactoryObject > T mockFactoryObject ( Class < T > type , String pid , final Config config ) { MockSettings settings = withSettings ( ) . extraInterfaces ( FactoryObjectInternal . class ) ; if ( config != null && config . getExtraInterfaces ( ) . length > 0 ) { settings . extraInterfaces ( config . getExtraInterfaces ( ) ) ; } T object = mock ( type , settings ) ; when ( object . getUuid ( ) ) . thenReturn ( UUID . randomUUID ( ) ) ; when ( object . getPid ( ) ) . thenReturn ( pid ) ; when ( object . getName ( ) ) . thenReturn ( pid + "-name" ) ; FactoryDescriptor factory ; String factoryClassName = type . getName ( ) + "Factory" ; try { factory = ( FactoryDescriptor ) mock ( Class . forName ( factoryClassName ) ) ; } catch ( Exception e ) { throw new IllegalStateException ( "Unable to mock class: " + factoryClassName ) ; } String proxyClassName = type . getName ( ) + "Proxy" ; doReturn ( proxyClassName ) . when ( factory ) . getProductType ( ) ; when ( object . getFactory ( ) ) . thenReturn ( factory ) ; FactoryObjectInternal internalObj = ( FactoryObjectInternal ) object ; doAnswer ( new Answer < Object > ( ) { @ Override public Object answer ( InvocationOnMock invocation ) throws Throwable { m_NameMap . put ( ( FactoryObject ) invocation . getMock ( ) , ( String ) invocation . getArguments ( ) [ 0 ] ) ; return null ; } } ) . when ( internalObj ) . internalSetName ( anyString ( ) ) ; when ( object . getName ( ) ) . thenAnswer ( new Answer < String > ( ) { @ Override public String answer ( InvocationOnMock invocation ) throws Throwable { return m_NameMap . get ( invocation . getMock ( ) ) ; } } ) ; return object ; }
Mock a factory object of the given type including the mocking of its factory.
Mock a factory object of the given type including the mocking of its factory .