ClipboardModule extends ReactContextBaseJavaModule { @SuppressLint("DeprecatedMethod") @ReactMethod public void setString(String text) { ReactApplicationContext reactContext = getReactApplicationContext(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ClipData clipdata = ClipData.newPlainText(null, text); ClipboardManager clipboard = getClipboardService(); clipboard.setPrimaryClip(clipdata); } else { ClipboardManager clipboard = getClipboardService(); clipboard.setText(text); } } ClipboardModule(ReactApplicationContext reactContext); @Override String getName(); @ReactMethod void getString(Promise promise); @SuppressLint("DeprecatedMethod") @ReactMethod void setString(String text);  }
@Test public void testSetString() { mClipboardModule.setString(TEST_CONTENT); assertTrue(mClipboardManager.getText().equals(TEST_CONTENT)); mClipboardModule.setString(null); assertFalse(mClipboardManager.hasText()); mClipboardModule.setString(""); assertFalse(mClipboardManager.hasText()); mClipboardModule.setString(" "); assertTrue(mClipboardManager.hasText()); }