urbanairship-core/src/test/java/com/urbanairship/actions/ActionServiceTest.java
@Test
    @Config(shadows = { CustomShadowService.class })
    public void testHandleRunActionIntent() {

        ShadowApplication shadowApplication = Shadows.shadowOf(RuntimeEnvironment.application);
        CustomShadowService shadowService = (CustomShadowService) Shadows.shadowOf(service);
        shadowApplication.clearStartedServices();

        ActionRunRequest runRequest = Mockito.mock(StubbedActionRunRequest.class, Mockito.CALLS_REAL_METHODS);
        when(actionRunRequestFactory.createActionRequest("actionName")).thenReturn(runRequest);

        // Call the request finish callback
        doAnswer(new Answer<Void>() {
            @Override
            public Void answer(InvocationOnMock invocation) throws Throwable {
                Object[] args = invocation.getArguments();
                ActionCompletionCallback callback = (ActionCompletionCallback) args[0];
                callback.onFinish(null, ActionResult.newEmptyResult());
                return null;
            }
        }).when(runRequest).run(Mockito.any(ActionCompletionCallback.class));

        // Metadata
        Bundle metadata = new Bundle();
        metadata.putString("oh", "hi");

        // Create the intent
        ActionService.runActions(context, "{ \"actionName\": \"actionValue\" }", Action.SITUATION_WEB_VIEW_INVOCATION, metadata);
        Intent runActionsIntent = shadowApplication.getNextStartedService();

        // Start the service
        service.onStartCommand(runActionsIntent, 0, 1);

        verify(runRequest).setValue(ActionValue.wrap("actionValue"));
        verify(runRequest).setSituation(Action.SITUATION_WEB_VIEW_INVOCATION);
        verify(runRequest).run(Mockito.any(ActionCompletionCallback.class));
        verify(runRequest).setMetadata(argThat(new ArgumentMatcher<Bundle>() {
            @Override
            public boolean matches(Bundle bundle) {
                return bundle.getString("oh").equals("hi");
            }
        }));

        // Verify that the service called stop self with the last start id
        assertEquals(1, shadowService.getLastStopSelfId());
    }
/**
     * Test running actions in the action service actually runs the actions
     * and calls stop self once its done.
     */
Test running actions in the action service actually runs the actions
and calls stop self once its done.
Test running actions in the action service actually runs the actions and calls stop self once its done .
@Test
    @Config(shadows = { CustomShadowService.class })
    public void testHandleRunActionIntent() {
        ShadowApplication shadowApplication = Shadows.shadowOf(RuntimeEnvironment.application);
        CustomShadowService shadowService = (CustomShadowService) Shadows.shadowOf(service);
        shadowApplication.clearStartedServices();
        ActionRunRequest runRequest = Mockito.mock(StubbedActionRunRequest.class, Mockito.CALLS_REAL_METHODS);
        when(actionRunRequestFactory.createActionRequest("actionName")).thenReturn(runRequest);
        doAnswer(new Answer<Void>() {
            @Override
            public Void answer(InvocationOnMock invocation) throws Throwable {
                Object[] args = invocation.getArguments();
                ActionCompletionCallback callback = (ActionCompletionCallback) args[0];
                callback.onFinish(null, ActionResult.newEmptyResult());
                return null;
            }
        }).when(runRequest).run(Mockito.any(ActionCompletionCallback.class));
        Bundle metadata = new Bundle();
        metadata.putString("oh", "hi");
        ActionService.runActions(context, "{ \"actionName\": \"actionValue\" }", Action.SITUATION_WEB_VIEW_INVOCATION, metadata);
        Intent runActionsIntent = shadowApplication.getNextStartedService();
        service.onStartCommand(runActionsIntent, 0, 1);
        verify(runRequest).setValue(ActionValue.wrap("actionValue"));
        verify(runRequest).setSituation(Action.SITUATION_WEB_VIEW_INVOCATION);
        verify(runRequest).run(Mockito.any(ActionCompletionCallback.class));
        verify(runRequest).setMetadata(argThat(new ArgumentMatcher<Bundle>() {
            @Override
            public boolean matches(Bundle bundle) {
                return bundle.getString("oh").equals("hi");
            }
        }));
        assertEquals(1, shadowService.getLastStopSelfId());
    }
@ Test @ Config ( shadows = { CustomShadowService . class } ) public void testHandleRunActionIntent ( ) { ShadowApplication shadowApplication = Shadows . shadowOf ( RuntimeEnvironment . application ) ; CustomShadowService shadowService = ( CustomShadowService ) Shadows . shadowOf ( service ) ; shadowApplication . clearStartedServices ( ) ; ActionRunRequest runRequest = Mockito . mock ( StubbedActionRunRequest . class , Mockito . CALLS_REAL_METHODS ) ; when ( actionRunRequestFactory . createActionRequest ( "actionName" ) ) . thenReturn ( runRequest ) ; doAnswer ( new Answer < Void > ( ) { @ Override public Void answer ( InvocationOnMock invocation ) throws Throwable { Object [ ] args = invocation . getArguments ( ) ; ActionCompletionCallback callback = ( ActionCompletionCallback ) args [ 0 ] ; callback . onFinish ( null , ActionResult . newEmptyResult ( ) ) ; return null ; } } ) . when ( runRequest ) . run ( Mockito . any ( ActionCompletionCallback . class ) ) ; Bundle metadata = new Bundle ( ) ; metadata . putString ( "oh" , "hi" ) ; ActionService . runActions ( context , "{ \"actionName\": \"actionValue\" }" , Action . SITUATION_WEB_VIEW_INVOCATION , metadata ) ; Intent runActionsIntent = shadowApplication . getNextStartedService ( ) ; service . onStartCommand ( runActionsIntent , 0 , 1 ) ; verify ( runRequest ) . setValue ( ActionValue . wrap ( "actionValue" ) ) ; verify ( runRequest ) . setSituation ( Action . SITUATION_WEB_VIEW_INVOCATION ) ; verify ( runRequest ) . run ( Mockito . any ( ActionCompletionCallback . class ) ) ; verify ( runRequest ) . setMetadata ( argThat ( new ArgumentMatcher < Bundle > ( ) { @ Override public boolean matches ( Bundle bundle ) { return bundle . getString ( "oh" ) . equals ( "hi" ) ; } } ) ) ; assertEquals ( 1 , shadowService . getLastStopSelfId ( ) ) ; }
Test running actions in the action service actually runs the actions
 and calls stop self once its done.
Test running actions in the action service actually runs the actions and calls stop self once its done .
// Call the request finish callback // Metadata // Create the intent // Start the service // Verify that the service called stop self with the last start id