@Test public void testRunActionsCommand() throws ActionValueException { ActionRunRequest actionRunRequest = Mockito.mock(StubbedActionRunRequest.class, Mockito.CALLS_REAL_METHODS); when(runRequestFactory.createActionRequest("action")).thenReturn(actionRunRequest); ActionRunRequest anotherActionRunRequest = Mockito.mock(StubbedActionRunRequest.class, Mockito.CALLS_REAL_METHODS); when(runRequestFactory.createActionRequest("anotherAction")).thenReturn(anotherActionRunRequest); String url = "uairship: assertTrue(nativeBridge.onHandleCommand(url, javaScriptExecutor, runRequestExtender, commandDelegate)); Map<String, Object> expectedMap = new HashMap<>(); expectedMap.put("key", "value"); verify(actionRunRequest).setValue(ActionValue.wrap(expectedMap)); verify(actionRunRequest).setSituation(Action.SITUATION_WEB_VIEW_INVOCATION); verify(actionRunRequest).run(any(ActionCompletionCallback.class)); List<String> expectedList = new ArrayList<>(); expectedList.add("one"); expectedList.add("two"); verify(anotherActionRunRequest).setValue(ActionValue.wrap(expectedList)); verify(anotherActionRunRequest).setSituation(Action.SITUATION_WEB_VIEW_INVOCATION); verify(anotherActionRunRequest).run(any(ActionCompletionCallback.class)); verify(runRequestExtender).extend(actionRunRequest); verify(runRequestExtender).extend(anotherActionRunRequest); verifyZeroInteractions(javaScriptExecutor, commandDelegate); }
@SuppressLint("LambdaLast") public boolean onHandleCommand(@Nullable String url, @NonNull JavaScriptExecutor javaScriptExecutor, @NonNull ActionRunRequestExtender actionRunRequestExtender, @NonNull CommandDelegate commandDelegate) { if (url == null) { return false; } Uri uri = Uri.parse(url); if (uri.getHost() == null || !UA_ACTION_SCHEME.equals(uri.getScheme())) { return false; } Logger.verbose("Intercepting: %s", url); switch (uri.getHost()) { case RUN_BASIC_ACTIONS_COMMAND: Logger.info("Running run basic actions command for URL: %s", url); runActions(actionRunRequestExtender, decodeActionArguments(uri, true)); break; case RUN_ACTIONS_COMMAND: Logger.info("Running run actions command for URL: %s", url); runActions(actionRunRequestExtender, decodeActionArguments(uri, false)); break; case RUN_ACTIONS_COMMAND_CALLBACK: Logger.info("Running run actions command with callback for URL: %s", url); List<String> paths = uri.getPathSegments(); if (paths.size() == 3) { Logger.info("Action: %s, Args: %s, Callback: %s", paths.get(0), paths.get(1), paths.get(2)); runAction(actionRunRequestExtender, javaScriptExecutor, paths.get(0), paths.get(1), paths.get(2)); } else { Logger.error("Unable to run action, invalid number of arguments."); } break; case CLOSE_COMMAND: Logger.info("Running close command for URL: %s", url); commandDelegate.onClose(); break; default: commandDelegate.onAirshipCommand(uri.getHost(), uri); break; } return true; }
NativeBridge { @SuppressLint("LambdaLast") public boolean onHandleCommand(@Nullable String url, @NonNull JavaScriptExecutor javaScriptExecutor, @NonNull ActionRunRequestExtender actionRunRequestExtender, @NonNull CommandDelegate commandDelegate) { if (url == null) { return false; } Uri uri = Uri.parse(url); if (uri.getHost() == null || !UA_ACTION_SCHEME.equals(uri.getScheme())) { return false; } Logger.verbose("Intercepting: %s", url); switch (uri.getHost()) { case RUN_BASIC_ACTIONS_COMMAND: Logger.info("Running run basic actions command for URL: %s", url); runActions(actionRunRequestExtender, decodeActionArguments(uri, true)); break; case RUN_ACTIONS_COMMAND: Logger.info("Running run actions command for URL: %s", url); runActions(actionRunRequestExtender, decodeActionArguments(uri, false)); break; case RUN_ACTIONS_COMMAND_CALLBACK: Logger.info("Running run actions command with callback for URL: %s", url); List<String> paths = uri.getPathSegments(); if (paths.size() == 3) { Logger.info("Action: %s, Args: %s, Callback: %s", paths.get(0), paths.get(1), paths.get(2)); runAction(actionRunRequestExtender, javaScriptExecutor, paths.get(0), paths.get(1), paths.get(2)); } else { Logger.error("Unable to run action, invalid number of arguments."); } break; case CLOSE_COMMAND: Logger.info("Running close command for URL: %s", url); commandDelegate.onClose(); break; default: commandDelegate.onAirshipCommand(uri.getHost(), uri); break; } return true; } }
NativeBridge { @SuppressLint("LambdaLast") public boolean onHandleCommand(@Nullable String url, @NonNull JavaScriptExecutor javaScriptExecutor, @NonNull ActionRunRequestExtender actionRunRequestExtender, @NonNull CommandDelegate commandDelegate) { if (url == null) { return false; } Uri uri = Uri.parse(url); if (uri.getHost() == null || !UA_ACTION_SCHEME.equals(uri.getScheme())) { return false; } Logger.verbose("Intercepting: %s", url); switch (uri.getHost()) { case RUN_BASIC_ACTIONS_COMMAND: Logger.info("Running run basic actions command for URL: %s", url); runActions(actionRunRequestExtender, decodeActionArguments(uri, true)); break; case RUN_ACTIONS_COMMAND: Logger.info("Running run actions command for URL: %s", url); runActions(actionRunRequestExtender, decodeActionArguments(uri, false)); break; case RUN_ACTIONS_COMMAND_CALLBACK: Logger.info("Running run actions command with callback for URL: %s", url); List<String> paths = uri.getPathSegments(); if (paths.size() == 3) { Logger.info("Action: %s, Args: %s, Callback: %s", paths.get(0), paths.get(1), paths.get(2)); runAction(actionRunRequestExtender, javaScriptExecutor, paths.get(0), paths.get(1), paths.get(2)); } else { Logger.error("Unable to run action, invalid number of arguments."); } break; case CLOSE_COMMAND: Logger.info("Running close command for URL: %s", url); commandDelegate.onClose(); break; default: commandDelegate.onAirshipCommand(uri.getHost(), uri); break; } return true; } NativeBridge();  NativeBridge(@NonNull ActionRunRequestFactory actionRunRequestFactory); @VisibleForTesting  NativeBridge(ActionRunRequestFactory actionRunRequestFactory, @NonNull Executor executor); }
NativeBridge { @SuppressLint("LambdaLast") public boolean onHandleCommand(@Nullable String url, @NonNull JavaScriptExecutor javaScriptExecutor, @NonNull ActionRunRequestExtender actionRunRequestExtender, @NonNull CommandDelegate commandDelegate) { if (url == null) { return false; } Uri uri = Uri.parse(url); if (uri.getHost() == null || !UA_ACTION_SCHEME.equals(uri.getScheme())) { return false; } Logger.verbose("Intercepting: %s", url); switch (uri.getHost()) { case RUN_BASIC_ACTIONS_COMMAND: Logger.info("Running run basic actions command for URL: %s", url); runActions(actionRunRequestExtender, decodeActionArguments(uri, true)); break; case RUN_ACTIONS_COMMAND: Logger.info("Running run actions command for URL: %s", url); runActions(actionRunRequestExtender, decodeActionArguments(uri, false)); break; case RUN_ACTIONS_COMMAND_CALLBACK: Logger.info("Running run actions command with callback for URL: %s", url); List<String> paths = uri.getPathSegments(); if (paths.size() == 3) { Logger.info("Action: %s, Args: %s, Callback: %s", paths.get(0), paths.get(1), paths.get(2)); runAction(actionRunRequestExtender, javaScriptExecutor, paths.get(0), paths.get(1), paths.get(2)); } else { Logger.error("Unable to run action, invalid number of arguments."); } break; case CLOSE_COMMAND: Logger.info("Running close command for URL: %s", url); commandDelegate.onClose(); break; default: commandDelegate.onAirshipCommand(uri.getHost(), uri); break; } return true; } NativeBridge();  NativeBridge(@NonNull ActionRunRequestFactory actionRunRequestFactory); @VisibleForTesting  NativeBridge(ActionRunRequestFactory actionRunRequestFactory, @NonNull Executor executor); @SuppressLint("LambdaLast") boolean onHandleCommand(@Nullable String url,
                                   @NonNull JavaScriptExecutor javaScriptExecutor,
                                   @NonNull ActionRunRequestExtender actionRunRequestExtender,
                                   @NonNull CommandDelegate commandDelegate); void setActionCompletionCallback(@Nullable ActionCompletionCallback actionCompletionCallback); @NonNull Cancelable loadJavaScriptEnvironment(@NonNull final Context context,
                                                @NonNull final JavaScriptEnvironment javaScriptEnvironment,
                                                @NonNull final JavaScriptExecutor javaScriptExecutor); }
NativeBridge { @SuppressLint("LambdaLast") public boolean onHandleCommand(@Nullable String url, @NonNull JavaScriptExecutor javaScriptExecutor, @NonNull ActionRunRequestExtender actionRunRequestExtender, @NonNull CommandDelegate commandDelegate) { if (url == null) { return false; } Uri uri = Uri.parse(url); if (uri.getHost() == null || !UA_ACTION_SCHEME.equals(uri.getScheme())) { return false; } Logger.verbose("Intercepting: %s", url); switch (uri.getHost()) { case RUN_BASIC_ACTIONS_COMMAND: Logger.info("Running run basic actions command for URL: %s", url); runActions(actionRunRequestExtender, decodeActionArguments(uri, true)); break; case RUN_ACTIONS_COMMAND: Logger.info("Running run actions command for URL: %s", url); runActions(actionRunRequestExtender, decodeActionArguments(uri, false)); break; case RUN_ACTIONS_COMMAND_CALLBACK: Logger.info("Running run actions command with callback for URL: %s", url); List<String> paths = uri.getPathSegments(); if (paths.size() == 3) { Logger.info("Action: %s, Args: %s, Callback: %s", paths.get(0), paths.get(1), paths.get(2)); runAction(actionRunRequestExtender, javaScriptExecutor, paths.get(0), paths.get(1), paths.get(2)); } else { Logger.error("Unable to run action, invalid number of arguments."); } break; case CLOSE_COMMAND: Logger.info("Running close command for URL: %s", url); commandDelegate.onClose(); break; default: commandDelegate.onAirshipCommand(uri.getHost(), uri); break; } return true; } NativeBridge();  NativeBridge(@NonNull ActionRunRequestFactory actionRunRequestFactory); @VisibleForTesting  NativeBridge(ActionRunRequestFactory actionRunRequestFactory, @NonNull Executor executor); @SuppressLint("LambdaLast") boolean onHandleCommand(@Nullable String url,
                                   @NonNull JavaScriptExecutor javaScriptExecutor,
                                   @NonNull ActionRunRequestExtender actionRunRequestExtender,
                                   @NonNull CommandDelegate commandDelegate); void setActionCompletionCallback(@Nullable ActionCompletionCallback actionCompletionCallback); @NonNull Cancelable loadJavaScriptEnvironment(@NonNull final Context context,
                                                @NonNull final JavaScriptEnvironment javaScriptEnvironment,
                                                @NonNull final JavaScriptExecutor javaScriptExecutor);  }