mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
refactor: re-write clipboard module test to kotlin (#37726)
Summary: Migrates the **ClipboardModuleTest** Java class to Kotlin. It also changes the import for **ClipboardManager** from `android.text.ClipboardManager` to `android.content.ClipboardManager`. Since the import from `android.text` is deprecated and in the [ClipboardManager.java](https://github.com/facebook/react-native/blob/main/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/clipboard/ClipboardModule.java) the import refers to `android.content`, so it's safe to update the import in test file as well. It's a sub-task of the umbrella issue [here](https://github.com/facebook/react-native/issues/37708) ## Changelog: [INTERNAL] [CHANGED] ClipboardModuleTest class migrated from Java to Kotlin <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests Pull Request resolved: https://github.com/facebook/react-native/pull/37726 Test Plan: 🟢 Test passes when running the following: ```sh ./gradlew :packages:react-native:ReactAndroid:test ``` Reviewed By: cortinico Differential Revision: D46486129 Pulled By: mdvacca fbshipit-source-id: 10ca6efdeea1236162dc40871cc0159cbe492335
This commit is contained in:
committed by
Facebook GitHub Bot
parent
84a3b898d5
commit
767b97c4da
-57
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.modules.clipboard;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.text.ClipboardManager;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@SuppressLint({"ClipboardManager", "DeprecatedClass"})
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"})
|
||||
public class ClipboardModuleTest {
|
||||
|
||||
private static final String TEST_CONTENT = "test";
|
||||
|
||||
private ClipboardModule mClipboardModule;
|
||||
private ClipboardManager mClipboardManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mClipboardModule =
|
||||
new ClipboardModule(new ReactApplicationContext(RuntimeEnvironment.application));
|
||||
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());
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.modules.clipboard
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import com.facebook.react.bridge.ReactApplicationContext
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@SuppressLint("ClipboardManager", "DeprecatedClass")
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class ClipboardModuleTest {
|
||||
private lateinit var clipboardModule: ClipboardModule
|
||||
private lateinit var clipboardManager: ClipboardManager
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
clipboardModule = ClipboardModule(ReactApplicationContext(RuntimeEnvironment.application))
|
||||
clipboardManager =
|
||||
RuntimeEnvironment.application.getSystemService(Context.CLIPBOARD_SERVICE)
|
||||
as ClipboardManager
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSetString() {
|
||||
clipboardModule.setString(TEST_CONTENT)
|
||||
assertTrue(clipboardManager.text == TEST_CONTENT)
|
||||
clipboardModule.setString(null)
|
||||
assertFalse(clipboardManager.hasText())
|
||||
clipboardModule.setString("")
|
||||
assertFalse(clipboardManager.hasText())
|
||||
clipboardModule.setString(" ")
|
||||
assertTrue(clipboardManager.hasText())
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TEST_CONTENT = "test"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user