@Test public void testRunPerformNullResult() { ActionArguments args = ActionTestUtils.createArgs(Action.SITUATION_MANUAL_INVOCATION, "value"); TestAction action = new TestAction(true, null); ActionResult result = action.run(args); assertNotNull("Result should never be null", result); assertTrue("Result should be 'null'", result.getValue().isNull()); assertEquals("Result should have the COMPLETED status", ActionResult.STATUS_COMPLETED, result.getStatus()); }
@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; }