mil.dod.th.ose.shared/test/mil/dod/th/ose/shared/TestSharedMessageUtils.java
@Test
    public void testCreateFactoryObjectMessage()
    {
        //mock factory object
        FactoryObject object = mock(FactoryObject.class);
        FactoryDescriptor descriptor = mock(FactoryDescriptor.class);
        when(descriptor.getProductType()).thenReturn("product-type");
        when(object.getUuid()).thenReturn(UUID.randomUUID());
        when(object.getPid()).thenReturn("pid");
        when(object.getFactory()).thenReturn(descriptor);
        
        //create message
        FactoryObjectInfo info = SharedMessageUtils.createFactoryObjectInfoMessage(object);

        //verify values
        assertThat(info.getPid(), is("pid"));
        assertThat(info.getUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(object.getUuid())));
        assertThat(info.getProductType(), is("product-type"));
        
        //verify that a message is still created even if a pid does not exist
        when(object.getPid()).thenReturn(null);
        
        FactoryObjectInfo pidNull = SharedMessageUtils.createFactoryObjectInfoMessage(object);
        
        assertThat(pidNull.getPid(), is(""));
        assertThat(pidNull.getUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(object.getUuid())));
        assertThat(pidNull.getProductType(), is("product-type"));
    }
/**
     * Test the creation of a factory object info message from a given factory object.
     */
Test the creation of a factory object info message from a given factory object.
Test the creation of a factory object info message from a given factory object .
@Test
    public void testCreateFactoryObjectMessage()
    {
        FactoryObject object = mock(FactoryObject.class);
        FactoryDescriptor descriptor = mock(FactoryDescriptor.class);
        when(descriptor.getProductType()).thenReturn("product-type");
        when(object.getUuid()).thenReturn(UUID.randomUUID());
        when(object.getPid()).thenReturn("pid");
        when(object.getFactory()).thenReturn(descriptor);
        FactoryObjectInfo info = SharedMessageUtils.createFactoryObjectInfoMessage(object);
        assertThat(info.getPid(), is("pid"));
        assertThat(info.getUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(object.getUuid())));
        assertThat(info.getProductType(), is("product-type"));
        when(object.getPid()).thenReturn(null);
        FactoryObjectInfo pidNull = SharedMessageUtils.createFactoryObjectInfoMessage(object);
        assertThat(pidNull.getPid(), is(""));
        assertThat(pidNull.getUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(object.getUuid())));
        assertThat(pidNull.getProductType(), is("product-type"));
    }
@ Test public void testCreateFactoryObjectMessage ( ) { FactoryObject object = mock ( FactoryObject . class ) ; FactoryDescriptor descriptor = mock ( FactoryDescriptor . class ) ; when ( descriptor . getProductType ( ) ) . thenReturn ( "product-type" ) ; when ( object . getUuid ( ) ) . thenReturn ( UUID . randomUUID ( ) ) ; when ( object . getPid ( ) ) . thenReturn ( "pid" ) ; when ( object . getFactory ( ) ) . thenReturn ( descriptor ) ; FactoryObjectInfo info = SharedMessageUtils . createFactoryObjectInfoMessage ( object ) ; assertThat ( info . getPid ( ) , is ( "pid" ) ) ; assertThat ( info . getUuid ( ) , is ( SharedMessageUtils . convertUUIDToProtoUUID ( object . getUuid ( ) ) ) ) ; assertThat ( info . getProductType ( ) , is ( "product-type" ) ) ; when ( object . getPid ( ) ) . thenReturn ( null ) ; FactoryObjectInfo pidNull = SharedMessageUtils . createFactoryObjectInfoMessage ( object ) ; assertThat ( pidNull . getPid ( ) , is ( "" ) ) ; assertThat ( pidNull . getUuid ( ) , is ( SharedMessageUtils . convertUUIDToProtoUUID ( object . getUuid ( ) ) ) ) ; assertThat ( pidNull . getProductType ( ) , is ( "product-type" ) ) ; }
Test the creation of a factory object info message from a given factory object.
Test the creation of a factory object info message from a given factory object .
//mock factory object //create message //verify values //verify that a message is still created even if a pid does not exist