mil.dod.th.ose.core/test/mil/dod/th/ose/core/ConfigurationAdminMocker.java
@SuppressWarnings({"rawtypes", "unchecked"})
    // This is due to the mocking of Dictionary type
    public static Configuration addMockConfiguration(final FactoryObject object, final String pid)
    {
        Preconditions.checkNotNull(pid);
        
        if (m_Configs.containsKey(pid))
        {
            throw new IllegalArgumentException("PID already exists in map");
        }
        
        Configuration config = mock(Configuration.class);

        m_Configs.put(pid, config);

        when(config.getFactoryPid()).thenReturn(null);
        when(config.getPid()).thenReturn(pid);

        when(config.getProperties()).thenAnswer(new Answer<Dictionary>()
        {
            @Override
            public Dictionary answer(InvocationOnMock invocation) throws Throwable
            {
                return m_Properties.get(pid);
            }
        });

        try
        {
            doAnswer(new Answer<Object>()
            {
                @Override
                public Object answer(final InvocationOnMock invocation) throws Throwable
                {
                    final Dictionary<String, ?> newProps = (Dictionary<String, ?>)invocation.getArguments()[0];
                    
                    Map<String, Object> newPropMap = new HashMap<>();
                    Enumeration<String> enumerable = newProps.keys();
                    while (enumerable.hasMoreElements())
                    {
                        Object key = enumerable.nextElement();
                        newPropMap.put((String)key, newProps.get(key));
                    }
                    
                    m_Properties.put(pid, newProps);
                    ((AbstractFactoryObject) object).blockingPropsUpdate(newPropMap);
                    return null;
                }
            }).when(config).update(Mockito.any(Dictionary.class));
    
            doAnswer(new Answer<Object>()
            {
                @Override
                public Object answer(final InvocationOnMock invocation) throws Throwable
                {
                    m_Configs.remove(pid);
                    m_Properties.remove(pid);
                    return null;
                }
            }).when(config).delete();
        }
        catch (IOException e)
        {
            throw new IllegalStateException(e);
        }
        
        return config;
    }
/**
     * Mock the configuration for an object.
     */
Mock the configuration for an object.
Mock the configuration for an object .
@SuppressWarnings({"rawtypes", "unchecked"})
    public static Configuration addMockConfiguration(final FactoryObject object, final String pid)
    {
        Preconditions.checkNotNull(pid);
        if (m_Configs.containsKey(pid))
        {
            throw new IllegalArgumentException("PID already exists in map");
        }
        Configuration config = mock(Configuration.class);
        m_Configs.put(pid, config);
        when(config.getFactoryPid()).thenReturn(null);
        when(config.getPid()).thenReturn(pid);
        when(config.getProperties()).thenAnswer(new Answer<Dictionary>()
        {
            @Override
            public Dictionary answer(InvocationOnMock invocation) throws Throwable
            {
                return m_Properties.get(pid);
            }
        });
        try
        {
            doAnswer(new Answer<Object>()
            {
                @Override
                public Object answer(final InvocationOnMock invocation) throws Throwable
                {
                    final Dictionary<String, ?> newProps = (Dictionary<String, ?>)invocation.getArguments()[0];
                    Map<String, Object> newPropMap = new HashMap<>();
                    Enumeration<String> enumerable = newProps.keys();
                    while (enumerable.hasMoreElements())
                    {
                        Object key = enumerable.nextElement();
                        newPropMap.put((String)key, newProps.get(key));
                    }
                    m_Properties.put(pid, newProps);
                    ((AbstractFactoryObject) object).blockingPropsUpdate(newPropMap);
                    return null;
                }
            }).when(config).update(Mockito.any(Dictionary.class));
            doAnswer(new Answer<Object>()
            {
                @Override
                public Object answer(final InvocationOnMock invocation) throws Throwable
                {
                    m_Configs.remove(pid);
                    m_Properties.remove(pid);
                    return null;
                }
            }).when(config).delete();
        }
        catch (IOException e)
        {
            throw new IllegalStateException(e);
        }
        return config;
    }
@ SuppressWarnings ( { "rawtypes" , "unchecked" } ) public static Configuration addMockConfiguration ( final FactoryObject object , final String pid ) { Preconditions . checkNotNull ( pid ) ; if ( m_Configs . containsKey ( pid ) ) { throw new IllegalArgumentException ( "PID already exists in map" ) ; } Configuration config = mock ( Configuration . class ) ; m_Configs . put ( pid , config ) ; when ( config . getFactoryPid ( ) ) . thenReturn ( null ) ; when ( config . getPid ( ) ) . thenReturn ( pid ) ; when ( config . getProperties ( ) ) . thenAnswer ( new Answer < Dictionary > ( ) { @ Override public Dictionary answer ( InvocationOnMock invocation ) throws Throwable { return m_Properties . get ( pid ) ; } } ) ; try { doAnswer ( new Answer < Object > ( ) { @ Override public Object answer ( final InvocationOnMock invocation ) throws Throwable { final Dictionary < String , ? > newProps = ( Dictionary < String , ? > ) invocation . getArguments ( ) [ 0 ] ; Map < String , Object > newPropMap = new HashMap < > ( ) ; Enumeration < String > enumerable = newProps . keys ( ) ; while ( enumerable . hasMoreElements ( ) ) { Object key = enumerable . nextElement ( ) ; newPropMap . put ( ( String ) key , newProps . get ( key ) ) ; } m_Properties . put ( pid , newProps ) ; ( ( AbstractFactoryObject ) object ) . blockingPropsUpdate ( newPropMap ) ; return null ; } } ) . when ( config ) . update ( Mockito . any ( Dictionary . class ) ) ; doAnswer ( new Answer < Object > ( ) { @ Override public Object answer ( final InvocationOnMock invocation ) throws Throwable { m_Configs . remove ( pid ) ; m_Properties . remove ( pid ) ; return null ; } } ) . when ( config ) . delete ( ) ; } catch ( IOException e ) { throw new IllegalStateException ( e ) ; } return config ; }
Mock the configuration for an object.
Mock the configuration for an object .
// This is due to the mocking of Dictionary type