ToastAction extends Action { @NonNull @Override public ActionResult perform(@NonNull ActionArguments arguments) { final String text; final int length; if (arguments.getValue().getMap() != null) { length = arguments.getValue().getMap().opt(LENGTH_KEY).getInt(Toast.LENGTH_SHORT); text = arguments.getValue().getMap().opt(TEXT_KEY).getString(); } else { text = arguments.getValue().getString(); length = Toast.LENGTH_SHORT; } if (length == Toast.LENGTH_LONG) { Toast.makeText(UAirship.getApplicationContext(), text, Toast.LENGTH_LONG).show(); } else { Toast.makeText(UAirship.getApplicationContext(), text, Toast.LENGTH_SHORT).show(); } return ActionResult.newResult(arguments.getValue()); }  @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 @SuppressLint("NewApi") public void testPerformWithMap() { Map<String, Object> toastMap = new HashMap<>(); toastMap.put("length", Toast.LENGTH_LONG); toastMap.put("text", "totes"); ActionArguments args = ActionTestUtils.createArgs(Action.SITUATION_PUSH_OPENED, toastMap); ActionResult result = action.perform(args); assertEquals(args.getValue(), result.getValue()); assertEquals("totes", ShadowToast.getTextOfLatestToast()); assertEquals(Toast.LENGTH_LONG, ShadowToast.getLatestToast().getDuration()); }
@Test @SuppressLint("NewApi") public void testPerformWithString() { ActionArguments args = ActionTestUtils.createArgs(Action.SITUATION_PUSH_OPENED, "totes"); ActionResult result = action.perform(args); assertEquals(args.getValue(), result.getValue()); assertEquals("totes", ShadowToast.getTextOfLatestToast()); assertEquals(Toast.LENGTH_SHORT, ShadowToast.getLatestToast().getDuration()); }