Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6e06964

Browse files
committed
Test real hasStrings call but not working due to inability to mock ClipboardManager
1 parent 5d5c9b2 commit 6e06964

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public class PlatformPlugin {
3030
private PlatformChannel.SystemChromeStyle currentTheme;
3131
private int mEnabledOverlays;
3232

33-
private final PlatformChannel.PlatformMessageHandler mPlatformMessageHandler =
33+
@VisibleForTesting
34+
final PlatformChannel.PlatformMessageHandler mPlatformMessageHandler =
3435
new PlatformChannel.PlatformMessageHandler() {
3536
@Override
3637
public void playSystemSound(@NonNull PlatformChannel.SoundType soundType) {

shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.flutter.plugin.platform;
22

33
import static org.junit.Assert.assertTrue;
4+
import static org.junit.Assert.assertFalse;
45
import static org.mockito.Mockito.mock;
56
import static org.mockito.Mockito.spy;
67
import static org.mockito.Mockito.verify;
@@ -28,8 +29,9 @@
2829
import org.robolectric.RobolectricTestRunner;
2930
import org.robolectric.RuntimeEnvironment;
3031
import org.robolectric.annotation.Config;
32+
import org.robolectric.shadows.ShadowClipboardManager;
3133

32-
@Config(manifest = Config.NONE)
34+
@Config(manifest = Config.NONE, shadows = ShadowClipboardManager.class)
3335
@RunWith(RobolectricTestRunner.class)
3436
public class PlatformPluginTest {
3537
@Config(sdk = 16)
@@ -71,4 +73,23 @@ public void platformPlugin_hasStringsMessage() {
7173
}
7274
verify(mockResult).success(Matchers.refEq(expected));
7375
}
76+
77+
@Test
78+
public void platformPlugin_hasStrings() {
79+
View fakeDecorView = mock(View.class);
80+
Window fakeWindow = mock(Window.class);
81+
when(fakeWindow.getDecorView()).thenReturn(fakeDecorView);
82+
Activity fakeActivity = mock(Activity.class);
83+
when(fakeActivity.getWindow()).thenReturn(fakeWindow);
84+
PlatformChannel fakePlatformChannel = mock(PlatformChannel.class);
85+
PlatformPlugin platformPlugin = new PlatformPlugin(fakeActivity, fakePlatformChannel);
86+
87+
ClipboardManager clipboardManager =
88+
RuntimeEnvironment.application.getSystemService(ClipboardManager.class);
89+
clipboardManager.setText("iamastring");
90+
assertTrue(platformPlugin.mPlatformMessageHandler.clipboardHasStrings());
91+
92+
clipboardManager.setText("");
93+
assertFalse(platformPlugin.mPlatformMessageHandler.clipboardHasStrings());
94+
}
7495
}

0 commit comments

Comments
 (0)