|
1 | 1 | package io.flutter.plugin.platform; |
2 | 2 |
|
3 | 3 | import static org.junit.Assert.assertTrue; |
| 4 | +import static org.junit.Assert.assertFalse; |
4 | 5 | import static org.mockito.Mockito.mock; |
5 | 6 | import static org.mockito.Mockito.spy; |
6 | 7 | import static org.mockito.Mockito.verify; |
|
28 | 29 | import org.robolectric.RobolectricTestRunner; |
29 | 30 | import org.robolectric.RuntimeEnvironment; |
30 | 31 | import org.robolectric.annotation.Config; |
| 32 | +import org.robolectric.shadows.ShadowClipboardManager; |
31 | 33 |
|
32 | | -@Config(manifest = Config.NONE) |
| 34 | +@Config(manifest = Config.NONE, shadows = ShadowClipboardManager.class) |
33 | 35 | @RunWith(RobolectricTestRunner.class) |
34 | 36 | public class PlatformPluginTest { |
35 | 37 | @Config(sdk = 16) |
@@ -71,4 +73,23 @@ public void platformPlugin_hasStringsMessage() { |
71 | 73 | } |
72 | 74 | verify(mockResult).success(Matchers.refEq(expected)); |
73 | 75 | } |
| 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 | + } |
74 | 95 | } |
0 commit comments