mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/mp/TestTemplateProgramManagerImpl.java
@Test
    public void testRemoveTemplate() throws IllegalArgumentException, PersistenceFailedException
    {
        //mock the stored templates
        mockTemplateProgramManagerTemplates();
        m_SUT.activate(context);
        
        //test a template that does not exist
        try
        {
            m_SUT.removeTemplate("Ninja");
            fail("expecting an exception");
        }
        catch(IllegalArgumentException exception)
        {
             //expected exception because this template does not exist
        }
        
        MissionProgramTemplate template = new MissionProgramTemplate().withName("George").withSource("dragon");
        m_SUT.loadMissionTemplate(template);
        //need to capture the UUID so it is known for removal
        ArgumentCaptor<UUID> uuid = ArgumentCaptor.forClass(UUID.class);
        ArgumentCaptor<byte[]> templateCap = ArgumentCaptor.forClass(byte[].class);
        verify(m_PersistentDataStore).persist(eq(TemplateProgramManagerImpl.class), uuid.capture(), 
            eq("George"), templateCap.capture());
        
        // mock data store
        PersistentData foundData = mock(PersistentData.class);
        when(m_PersistentDataStore.find((UUID)Mockito.any())).thenReturn(foundData);
        when(foundData.getEntity()).thenReturn(templateCap.getValue());
        
        template = m_SUT.getTemplate("George");
        assertThat(template, is(notNullValue()));
        m_SUT.removeTemplate("George");
        
        MissionProgramTemplate templateToRemove = (MissionProgramTemplate)XmlUtils.fromXML(templateCap.getValue(), 
                MissionProgramTemplate.class);
        assertThat(templateToRemove.getName(), is(template.getName()));
        
        //verify removed from data store
        verify(m_PersistentDataStore).remove(uuid.getValue());
        
        assertThat(m_SUT.getMissionTemplateNames(), not(hasItem("George")));
    }
/**
     * Testing the removal of a mission template.
     */
Testing the removal of a mission template.
Testing the removal of a mission template .
@Test
    public void testRemoveTemplate() throws IllegalArgumentException, PersistenceFailedException
    {
        mockTemplateProgramManagerTemplates();
        m_SUT.activate(context);
        try
        {
            m_SUT.removeTemplate("Ninja");
            fail("expecting an exception");
        }
        catch(IllegalArgumentException exception)
        {
        }
        MissionProgramTemplate template = new MissionProgramTemplate().withName("George").withSource("dragon");
        m_SUT.loadMissionTemplate(template);
        ArgumentCaptor<UUID> uuid = ArgumentCaptor.forClass(UUID.class);
        ArgumentCaptor<byte[]> templateCap = ArgumentCaptor.forClass(byte[].class);
        verify(m_PersistentDataStore).persist(eq(TemplateProgramManagerImpl.class), uuid.capture(), 
            eq("George"), templateCap.capture());
        PersistentData foundData = mock(PersistentData.class);
        when(m_PersistentDataStore.find((UUID)Mockito.any())).thenReturn(foundData);
        when(foundData.getEntity()).thenReturn(templateCap.getValue());
        template = m_SUT.getTemplate("George");
        assertThat(template, is(notNullValue()));
        m_SUT.removeTemplate("George");
        MissionProgramTemplate templateToRemove = (MissionProgramTemplate)XmlUtils.fromXML(templateCap.getValue(), 
                MissionProgramTemplate.class);
        assertThat(templateToRemove.getName(), is(template.getName()));
        verify(m_PersistentDataStore).remove(uuid.getValue());
        assertThat(m_SUT.getMissionTemplateNames(), not(hasItem("George")));
    }
@ Test public void testRemoveTemplate ( ) throws IllegalArgumentException , PersistenceFailedException { mockTemplateProgramManagerTemplates ( ) ; m_SUT . activate ( context ) ; try { m_SUT . removeTemplate ( "Ninja" ) ; fail ( "expecting an exception" ) ; } catch ( IllegalArgumentException exception ) { } MissionProgramTemplate template = new MissionProgramTemplate ( ) . withName ( "George" ) . withSource ( "dragon" ) ; m_SUT . loadMissionTemplate ( template ) ; ArgumentCaptor < UUID > uuid = ArgumentCaptor . forClass ( UUID . class ) ; ArgumentCaptor < byte [ ] > templateCap = ArgumentCaptor . forClass ( byte [ ] . class ) ; verify ( m_PersistentDataStore ) . persist ( eq ( TemplateProgramManagerImpl . class ) , uuid . capture ( ) , eq ( "George" ) , templateCap . capture ( ) ) ; PersistentData foundData = mock ( PersistentData . class ) ; when ( m_PersistentDataStore . find ( ( UUID ) Mockito . any ( ) ) ) . thenReturn ( foundData ) ; when ( foundData . getEntity ( ) ) . thenReturn ( templateCap . getValue ( ) ) ; template = m_SUT . getTemplate ( "George" ) ; assertThat ( template , is ( notNullValue ( ) ) ) ; m_SUT . removeTemplate ( "George" ) ; MissionProgramTemplate templateToRemove = ( MissionProgramTemplate ) XmlUtils . fromXML ( templateCap . getValue ( ) , MissionProgramTemplate . class ) ; assertThat ( templateToRemove . getName ( ) , is ( template . getName ( ) ) ) ; verify ( m_PersistentDataStore ) . remove ( uuid . getValue ( ) ) ; assertThat ( m_SUT . getMissionTemplateNames ( ) , not ( hasItem ( "George" ) ) ) ; }
Testing the removal of a mission template.
Testing the removal of a mission template .
//mock the stored templates //test a template that does not exist //expected exception because this template does not exist //need to capture the UUID so it is known for removal // mock data store //verify removed from data store