@Test public void testRunBadArgs() throws ActionValueException { ActionResult performResult = ActionResult.newResult(ActionValue.wrap("result")); TestAction action = new TestAction(false, performResult); ActionResult badArgsResult = action.run(ActionTestUtils.createArgs(Action.SITUATION_MANUAL_INVOCATION, "value")); assertTrue("Does not accept arguments should return a 'null' result value", badArgsResult.getValue().isNull()); assertEquals("Result should have an rejected arguemnts status", ActionResult.STATUS_REJECTED_ARGUMENTS, badArgsResult.getStatus()); assertFalse("Does not accept arguments should not call any of the actions perform methods.", action.onStartCalled); assertFalse("Does not accept arguments should not call any of the actions perform methods.", action.performCalled); assertFalse("Does not accept arguments should not call any of the actions perform methods.", action.onFinishCalled); }
@NonNull final ActionResult run(@NonNull ActionArguments arguments) { try { if (!acceptsArguments(arguments)) { Logger.debug("Action %s is unable to accept arguments: %s", this, arguments); return ActionResult.newEmptyResultWithStatus(ActionResult.STATUS_REJECTED_ARGUMENTS); } Logger.info("Running action: %s arguments: %s", this, arguments); onStart(arguments); ActionResult result = perform(arguments); if (result == null) { result = ActionResult.newEmptyResult(); } onFinish(arguments, result); return result; } catch (Exception e) { Logger.error(e, "Failed to run action %s", this); return ActionResult.newErrorResult(e); } }
Action { @NonNull final ActionResult run(@NonNull ActionArguments arguments) { try { if (!acceptsArguments(arguments)) { Logger.debug("Action %s is unable to accept arguments: %s", this, arguments); return ActionResult.newEmptyResultWithStatus(ActionResult.STATUS_REJECTED_ARGUMENTS); } Logger.info("Running action: %s arguments: %s", this, arguments); onStart(arguments); ActionResult result = perform(arguments); if (result == null) { result = ActionResult.newEmptyResult(); } onFinish(arguments, result); return result; } catch (Exception e) { Logger.error(e, "Failed to run action %s", this); return ActionResult.newErrorResult(e); } } }
Action { @NonNull final ActionResult run(@NonNull ActionArguments arguments) { try { if (!acceptsArguments(arguments)) { Logger.debug("Action %s is unable to accept arguments: %s", this, arguments); return ActionResult.newEmptyResultWithStatus(ActionResult.STATUS_REJECTED_ARGUMENTS); } Logger.info("Running action: %s arguments: %s", this, arguments); onStart(arguments); ActionResult result = perform(arguments); if (result == null) { result = ActionResult.newEmptyResult(); } onFinish(arguments, result); return result; } catch (Exception e) { Logger.error(e, "Failed to run action %s", this); return ActionResult.newErrorResult(e); } }  }
Action { @NonNull final ActionResult run(@NonNull ActionArguments arguments) { try { if (!acceptsArguments(arguments)) { Logger.debug("Action %s is unable to accept arguments: %s", this, arguments); return ActionResult.newEmptyResultWithStatus(ActionResult.STATUS_REJECTED_ARGUMENTS); } Logger.info("Running action: %s arguments: %s", this, arguments); onStart(arguments); ActionResult result = perform(arguments); if (result == null) { result = ActionResult.newEmptyResult(); } onFinish(arguments, result); return result; } catch (Exception e) { Logger.error(e, "Failed to run action %s", this); return ActionResult.newErrorResult(e); } }  boolean acceptsArguments(@NonNull ActionArguments arguments); void onStart(@NonNull ActionArguments arguments); @NonNull abstract ActionResult perform(@NonNull ActionArguments arguments); void onFinish(@NonNull ActionArguments arguments, @NonNull ActionResult result); boolean shouldRunOnMainThread(); }
Action { @NonNull final ActionResult run(@NonNull ActionArguments arguments) { try { if (!acceptsArguments(arguments)) { Logger.debug("Action %s is unable to accept arguments: %s", this, arguments); return ActionResult.newEmptyResultWithStatus(ActionResult.STATUS_REJECTED_ARGUMENTS); } Logger.info("Running action: %s arguments: %s", this, arguments); onStart(arguments); ActionResult result = perform(arguments); if (result == null) { result = ActionResult.newEmptyResult(); } onFinish(arguments, result); return result; } catch (Exception e) { Logger.error(e, "Failed to run action %s", this); return ActionResult.newErrorResult(e); } }  boolean acceptsArguments(@NonNull ActionArguments arguments); void onStart(@NonNull ActionArguments arguments); @NonNull abstract ActionResult perform(@NonNull ActionArguments arguments); void onFinish(@NonNull ActionArguments arguments, @NonNull ActionResult result); boolean shouldRunOnMainThread(); final static int SITUATION_MANUAL_INVOCATION; final static int SITUATION_PUSH_RECEIVED; final static int SITUATION_PUSH_OPENED; final static int SITUATION_WEB_VIEW_INVOCATION; final static int SITUATION_FOREGROUND_NOTIFICATION_ACTION_BUTTON; final static int SITUATION_BACKGROUND_NOTIFICATION_ACTION_BUTTON; final static int SITUATION_AUTOMATION; }