ToastAction extends Action { @Override public boolean acceptsArguments(@NonNull ActionArguments arguments) { switch (arguments.getSituation()) { case SITUATION_BACKGROUND_NOTIFICATION_ACTION_BUTTON: case SITUATION_FOREGROUND_NOTIFICATION_ACTION_BUTTON: case SITUATION_PUSH_OPENED: case SITUATION_MANUAL_INVOCATION: case SITUATION_WEB_VIEW_INVOCATION: case SITUATION_AUTOMATION: if (arguments.getValue().getMap() != null) { return arguments.getValue().getMap().opt(TEXT_KEY).isString(); } return arguments.getValue().getString() != null; case SITUATION_PUSH_RECEIVED: default: return false; } }  @Override boolean acceptsArguments(@NonNull ActionArguments arguments); @NonNull @Override ActionResult perform(@NonNull ActionArguments arguments); @Override boolean shouldRunOnMainThread(); @NonNull
    static final String DEFAULT_REGISTRY_NAME; @NonNull
    static final String TEXT_KEY; @NonNull
    static final String LENGTH_KEY; }
@Test public void testAcceptsArgumentWithMap() { Map<String, Object> toastMap = new HashMap<>(); toastMap.put("length", Toast.LENGTH_LONG); toastMap.put("text", "toast text"); for (@Action.Situation int situation : acceptedSituations) { ActionArguments args = ActionTestUtils.createArgs(situation, toastMap); assertTrue("Should accept arguments in situation " + situation, action.acceptsArguments(args)); } for (@Action.Situation int situation : rejectedSituations) { ActionArguments args = ActionTestUtils.createArgs(situation, toastMap); assertFalse("Should reject arguments in situation " + situation, action.acceptsArguments(args)); } }
@Test public void testAcceptsArgumentWithString() { String toastText = "oh hi"; for (@Action.Situation int situation : acceptedSituations) { ActionArguments args = ActionTestUtils.createArgs(situation, toastText); assertTrue("Should accept arguments in situation " + situation, action.acceptsArguments(args)); } for (@Action.Situation int situation : rejectedSituations) { ActionArguments args = ActionTestUtils.createArgs(situation, toastText); assertFalse("Should reject arguments in situation " + situation, action.acceptsArguments(args)); } }