Use the new Android Clipboard module

Summary:
public

- Open source the unit test for `ClipboardModule`, start using the `ReactTestHelper` in two unit tests
- Fixes a few references to "pasteboard" in strings

Reviewed By: bestander

Differential Revision: D2739614

fb-gh-sync-id: e076940a3ae5c22314e181a37fe2c3f77a18cf85
This commit is contained in:
Martin Konicek 2015-12-09 15:16:15 -08:00 committed by facebook-github-bot-8
parent 139f9945df
commit 2aa3e0dd1a
3 changed files with 64 additions and 11 deletions

View File

@ -24,7 +24,7 @@ import static org.mockito.Mockito.when;
/**
* Utility for creating pre-configured instances of core react components for tests.
*/
public class CatalystTestHelper {
public class ReactTestHelper {
/**
* @return a ReactApplicationContext that has a CatalystInstance mock returned by

View File

@ -0,0 +1,61 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.modules.clipboard;
import android.annotation.SuppressLint;
import android.content.Context;
import android.text.ClipboardManager;
import com.facebook.react.bridge.ReactTestHelper;
import com.facebook.react.modules.clipboard.ClipboardModule;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
@SuppressLint({"ClipboardManager", "DeprecatedClass"})
@RunWith(RobolectricTestRunner.class)
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "android.*"})
public class ClipboardModuleTest {
private static final String TEST_CONTENT = "test";
private ClipboardModule mClipboardModule;
private ClipboardManager mClipboardManager;
@Before
public void setUp() {
mClipboardModule = new ClipboardModule(ReactTestHelper.createCatalystContextForTest());
mClipboardManager =
(ClipboardManager) RuntimeEnvironment.application.getSystemService(Context.CLIPBOARD_SERVICE);
}
@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());
}
}

View File

@ -20,12 +20,12 @@ import android.content.ContextWrapper;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactTestHelper;
import com.facebook.react.bridge.SimpleArray;
import com.facebook.react.bridge.SimpleMap;
import com.facebook.react.modules.storage.AsyncStorageModule;
import com.facebook.react.modules.storage.ReactDatabaseSupplier;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
@ -60,13 +60,6 @@ public class AsyncStorageModuleTest {
private AsyncStorageModule mStorage;
private SimpleArray mEmptyArray;
private static class FakeFragmentContext extends ContextWrapper {
public FakeFragmentContext(Context base) {
super(base);
}
}
@Rule
public PowerMockRule rule = new PowerMockRule();
@ -90,8 +83,7 @@ public class AsyncStorageModuleTest {
});
// don't use Robolectric before initializing mocks
mStorage = new AsyncStorageModule(new ReactApplicationContext(
new FakeFragmentContext(RuntimeEnvironment.application)));
mStorage = new AsyncStorageModule(ReactTestHelper.createCatalystContextForTest());
mEmptyArray = new SimpleArray();
}