ClipboardAction extends Action { @NonNull @Override public ActionResult perform(@NonNull final ActionArguments arguments) { final String text, label; if (arguments.getValue().getMap() != null) { text = arguments.getValue().getMap().opt(TEXT_KEY).getString(); label = arguments.getValue().getMap().opt(LABEL_KEY).getString(); } else { text = arguments.getValue().getString(); label = null; } new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { ClipboardManager clipboardManager = (ClipboardManager) UAirship.getApplicationContext().getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(label, text); clipboardManager.setPrimaryClip(clip); } }); return ActionResult.newResult(arguments.getValue()); }  @Override boolean acceptsArguments(@NonNull ActionArguments arguments); @NonNull @Override ActionResult perform(@NonNull final ActionArguments arguments); @Override boolean shouldRunOnMainThread(); @NonNull
    static final String DEFAULT_REGISTRY_NAME; @NonNull
    static final String DEFAULT_REGISTRY_SHORT_NAME; @NonNull
    static final String LABEL_KEY; @NonNull
    static final String TEXT_KEY; }
@Test @SuppressLint("NewApi") public void testPerformWithMap() { Map<String, String> clipboardMap = new HashMap<>(); clipboardMap.put("label", "clipboard label"); clipboardMap.put("text", "clipboard text"); ActionArguments args = ActionTestUtils.createArgs(Action.SITUATION_PUSH_OPENED, clipboardMap); ActionResult result = action.perform(args); assertEquals(args.getValue(), result.getValue()); ClipData clipData = clipboardManager.getPrimaryClip(); assertEquals(clipData.getDescription().getLabel(), "clipboard label"); assertEquals(clipData.getItemAt(0).getText(), "clipboard text"); }
@Test @SuppressLint("NewApi") public void testPerformWithString() { ActionArguments args = ActionTestUtils.createArgs(Action.SITUATION_PUSH_OPENED, "clipboard text"); ActionResult result = action.perform(args); assertEquals(args.getValue(), result.getValue()); ClipData clipData = clipboardManager.getPrimaryClip(); assertNull(clipData.getDescription().getLabel()); assertEquals(clipData.getItemAt(0).getText(), "clipboard text"); }