mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/mp/TestMissionProgramManagerImpl.java
@SuppressWarnings({"unchecked"})
    private <T> void assertOptionalService(String variable, Class<T> serviceClass, Consumer<T> bind, 
            Consumer<T> unbind) throws Exception
    {
        setScriptEngineAndActivate();

        T service = mock(serviceClass);
        bind.consume(service);

        verify(m_ScriptEngine).put(variable, service);

        //mock template manager
        Set<String> templateNames = new HashSet<String>();
        templateNames.add("blah");
        when(m_TemplateManager.getMissionTemplateNames()).thenReturn(templateNames);

        //mission
        MissionProgramTemplate programModel = new MissionProgramTemplate().withSource("test").withName("blah");
        when(m_TemplateManager.getTemplate("blah")).thenReturn(programModel);
        MissionProgramSchedule schedule = new MissionProgramSchedule().withImmediately(true).
                withIndefiniteInterval(false).withActive(true);
        MissionProgramParameters params = new MissionProgramParameters().withTemplateName("blah").
                withSchedule(schedule).withProgramName("name");

        //load the params
        Program program = m_SUT.loadParameters(params);

        //check that the binding was processed
        ArgumentCaptor<ScriptContext> context = ArgumentCaptor.forClass(ScriptContext.class);
        verify(m_ScriptEngine, times(1)).eval(eq("test"), context.capture());
        assertThat((T)context.getValue().getBindings(ScriptContext.ENGINE_SCOPE).get(variable), is(service));

        m_SUT.removeProgram(program, null);

        unbind.consume(service);

        //mission
        MissionProgramSchedule schedule2 = new MissionProgramSchedule().withImmediately(true).
                withIndefiniteInterval(false).withActive(true);
        MissionProgramParameters params2 = new MissionProgramParameters().withTemplateName("blah").
                withSchedule(schedule2).withProgramName("name2");

        program = m_SUT.loadParameters(params2);

        //behavior from scheduler
        Future<?> future = mock(Future.class);
        when(future.get()).thenReturn(null);

        //execute program
        program.execute();
        verify(m_ScriptEngine).put(variable, null);
        verify(m_ScriptEngine, times(2)).eval(eq("test"), context.capture());
        assertThat(context.getValue().getBindings(ScriptContext.ENGINE_SCOPE).get(variable), is(nullValue()));
        
        m_SUT.removeProgram(program, null);
    }
/**
     * Method asserts the given service class is correctly bound as a variable.
     * 
     * @param variable
     *      name of variable used for the service
     */
Method asserts the given service class is correctly bound as a variable.

@param variable
name of variable used for the service
Method asserts the given service class is correctly bound as a variable . @param variable name of variable used for the service
@SuppressWarnings({"unchecked"})
    private <T> void assertOptionalService(String variable, Class<T> serviceClass, Consumer<T> bind, 
            Consumer<T> unbind) throws Exception
    {
        setScriptEngineAndActivate();
        T service = mock(serviceClass);
        bind.consume(service);
        verify(m_ScriptEngine).put(variable, service);
        Set<String> templateNames = new HashSet<String>();
        templateNames.add("blah");
        when(m_TemplateManager.getMissionTemplateNames()).thenReturn(templateNames);
        MissionProgramTemplate programModel = new MissionProgramTemplate().withSource("test").withName("blah");
        when(m_TemplateManager.getTemplate("blah")).thenReturn(programModel);
        MissionProgramSchedule schedule = new MissionProgramSchedule().withImmediately(true).
                withIndefiniteInterval(false).withActive(true);
        MissionProgramParameters params = new MissionProgramParameters().withTemplateName("blah").
                withSchedule(schedule).withProgramName("name");
        Program program = m_SUT.loadParameters(params);
        ArgumentCaptor<ScriptContext> context = ArgumentCaptor.forClass(ScriptContext.class);
        verify(m_ScriptEngine, times(1)).eval(eq("test"), context.capture());
        assertThat((T)context.getValue().getBindings(ScriptContext.ENGINE_SCOPE).get(variable), is(service));
        m_SUT.removeProgram(program, null);
        unbind.consume(service);
        MissionProgramSchedule schedule2 = new MissionProgramSchedule().withImmediately(true).
                withIndefiniteInterval(false).withActive(true);
        MissionProgramParameters params2 = new MissionProgramParameters().withTemplateName("blah").
                withSchedule(schedule2).withProgramName("name2");
        program = m_SUT.loadParameters(params2);
        Future<?> future = mock(Future.class);
        when(future.get()).thenReturn(null);
        program.execute();
        verify(m_ScriptEngine).put(variable, null);
        verify(m_ScriptEngine, times(2)).eval(eq("test"), context.capture());
        assertThat(context.getValue().getBindings(ScriptContext.ENGINE_SCOPE).get(variable), is(nullValue()));
        m_SUT.removeProgram(program, null);
    }
@ SuppressWarnings ( { "unchecked" } ) private < T > void assertOptionalService ( String variable , Class < T > serviceClass , Consumer < T > bind , Consumer < T > unbind ) throws Exception { setScriptEngineAndActivate ( ) ; T service = mock ( serviceClass ) ; bind . consume ( service ) ; verify ( m_ScriptEngine ) . put ( variable , service ) ; Set < String > templateNames = new HashSet < String > ( ) ; templateNames . add ( "blah" ) ; when ( m_TemplateManager . getMissionTemplateNames ( ) ) . thenReturn ( templateNames ) ; MissionProgramTemplate programModel = new MissionProgramTemplate ( ) . withSource ( "test" ) . withName ( "blah" ) ; when ( m_TemplateManager . getTemplate ( "blah" ) ) . thenReturn ( programModel ) ; MissionProgramSchedule schedule = new MissionProgramSchedule ( ) . withImmediately ( true ) . withIndefiniteInterval ( false ) . withActive ( true ) ; MissionProgramParameters params = new MissionProgramParameters ( ) . withTemplateName ( "blah" ) . withSchedule ( schedule ) . withProgramName ( "name" ) ; Program program = m_SUT . loadParameters ( params ) ; ArgumentCaptor < ScriptContext > context = ArgumentCaptor . forClass ( ScriptContext . class ) ; verify ( m_ScriptEngine , times ( 1 ) ) . eval ( eq ( "test" ) , context . capture ( ) ) ; assertThat ( ( T ) context . getValue ( ) . getBindings ( ScriptContext . ENGINE_SCOPE ) . get ( variable ) , is ( service ) ) ; m_SUT . removeProgram ( program , null ) ; unbind . consume ( service ) ; MissionProgramSchedule schedule2 = new MissionProgramSchedule ( ) . withImmediately ( true ) . withIndefiniteInterval ( false ) . withActive ( true ) ; MissionProgramParameters params2 = new MissionProgramParameters ( ) . withTemplateName ( "blah" ) . withSchedule ( schedule2 ) . withProgramName ( "name2" ) ; program = m_SUT . loadParameters ( params2 ) ; Future < ? > future = mock ( Future . class ) ; when ( future . get ( ) ) . thenReturn ( null ) ; program . execute ( ) ; verify ( m_ScriptEngine ) . put ( variable , null ) ; verify ( m_ScriptEngine , times ( 2 ) ) . eval ( eq ( "test" ) , context . capture ( ) ) ; assertThat ( context . getValue ( ) . getBindings ( ScriptContext . ENGINE_SCOPE ) . get ( variable ) , is ( nullValue ( ) ) ) ; m_SUT . removeProgram ( program , null ) ; }
Method asserts the given service class is correctly bound as a variable.
Method asserts the given service class is correctly bound as a variable .
//mock template manager //mission //load the params //check that the binding was processed //mission //behavior from scheduler //execute program