mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/ccomm/TestAddressManagerServiceImpl.java
@Test
    public void testGetOrCreateAddress() throws CCommException, IllegalArgumentException, InterruptedException,
        FactoryException, FactoryObjectInformationException, ClassNotFoundException
    {
        Address a = m_SUT.getOrCreateAddress("Base:a.b.c");
        m_RegistryObjects.add((AddressInternal) a);
        
        // mock address created previously to be equal to the next one being created
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("prop", "a.b.c");
        when(a.equalProperties(properties)).thenReturn(true);
        when(m_FactoryServiceContext.getRegistry()).thenReturn(m_Registry);
        when(m_FactoryServiceContext.getRegistry().getObjectsByProductType(anyString())).thenReturn(m_RegistryObjects);
        m_SUT.getOrCreateAddress(m_Factory.getProductType(), "old-addr", properties);
        
        // verify a new address is not created
        verify(m_WakeLock).activate();
        verify(m_Registry, times(1)).createNewObject(eq(m_Factory), anyString(), eq(properties));
        verify(m_WakeLock).cancel();
        
        // now mock to not be equal to the address
        when(a.equalProperties(properties)).thenReturn(false);
        m_SUT.getOrCreateAddress(m_Factory.getProductType(), "new-addr", properties);
        
        // verify a new address is created
        verify(m_WakeLock, times(2)).activate();
        verify(m_Registry, times(2)).createNewObject(eq(m_Factory), anyString(), eq(properties));
        verify(m_WakeLock, times(2)).cancel();
    }
/**
     * Verify that if an address is not already existent that it is created.  Conversely, if already created, not 
     * created again.
     */
Verify that if an address is not already existent that it is created.  Conversely, if already created, not
created again.
Verify that if an address is not already existent that it is created . Conversely if already created not created again .
@Test
    public void testGetOrCreateAddress() throws CCommException, IllegalArgumentException, InterruptedException,
        FactoryException, FactoryObjectInformationException, ClassNotFoundException
    {
        Address a = m_SUT.getOrCreateAddress("Base:a.b.c");
        m_RegistryObjects.add((AddressInternal) a);
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("prop", "a.b.c");
        when(a.equalProperties(properties)).thenReturn(true);
        when(m_FactoryServiceContext.getRegistry()).thenReturn(m_Registry);
        when(m_FactoryServiceContext.getRegistry().getObjectsByProductType(anyString())).thenReturn(m_RegistryObjects);
        m_SUT.getOrCreateAddress(m_Factory.getProductType(), "old-addr", properties);
        verify(m_WakeLock).activate();
        verify(m_Registry, times(1)).createNewObject(eq(m_Factory), anyString(), eq(properties));
        verify(m_WakeLock).cancel();
        when(a.equalProperties(properties)).thenReturn(false);
        m_SUT.getOrCreateAddress(m_Factory.getProductType(), "new-addr", properties);
        verify(m_WakeLock, times(2)).activate();
        verify(m_Registry, times(2)).createNewObject(eq(m_Factory), anyString(), eq(properties));
        verify(m_WakeLock, times(2)).cancel();
    }
@ Test public void testGetOrCreateAddress ( ) throws CCommException , IllegalArgumentException , InterruptedException , FactoryException , FactoryObjectInformationException , ClassNotFoundException { Address a = m_SUT . getOrCreateAddress ( "Base:a.b.c" ) ; m_RegistryObjects . add ( ( AddressInternal ) a ) ; Map < String , Object > properties = new HashMap < String , Object > ( ) ; properties . put ( "prop" , "a.b.c" ) ; when ( a . equalProperties ( properties ) ) . thenReturn ( true ) ; when ( m_FactoryServiceContext . getRegistry ( ) ) . thenReturn ( m_Registry ) ; when ( m_FactoryServiceContext . getRegistry ( ) . getObjectsByProductType ( anyString ( ) ) ) . thenReturn ( m_RegistryObjects ) ; m_SUT . getOrCreateAddress ( m_Factory . getProductType ( ) , "old-addr" , properties ) ; verify ( m_WakeLock ) . activate ( ) ; verify ( m_Registry , times ( 1 ) ) . createNewObject ( eq ( m_Factory ) , anyString ( ) , eq ( properties ) ) ; verify ( m_WakeLock ) . cancel ( ) ; when ( a . equalProperties ( properties ) ) . thenReturn ( false ) ; m_SUT . getOrCreateAddress ( m_Factory . getProductType ( ) , "new-addr" , properties ) ; verify ( m_WakeLock , times ( 2 ) ) . activate ( ) ; verify ( m_Registry , times ( 2 ) ) . createNewObject ( eq ( m_Factory ) , anyString ( ) , eq ( properties ) ) ; verify ( m_WakeLock , times ( 2 ) ) . cancel ( ) ; }
Verify that if an address is not already existent that it is created.
Verify that if an address is not already existent that it is created .
// mock address created previously to be equal to the next one being created // verify a new address is not created // now mock to not be equal to the address // verify a new address is created