22
33import static org .junit .Assert .assertTrue ;
44import static org .mockito .Mockito .mock ;
5+ import static org .mockito .Mockito .spy ;
6+ import static org .mockito .Mockito .verify ;
57import static org .mockito .Mockito .when ;
68
79import android .app .Activity ;
10+ import android .content .res .AssetManager ;
811import android .content .ClipboardManager ;
912import android .view .View ;
1013import android .view .Window ;
14+ import io .flutter .embedding .engine .FlutterJNI ;
15+ import io .flutter .embedding .engine .dart .DartExecutor ;
1116import io .flutter .embedding .engine .systemchannels .PlatformChannel ;
17+ import io .flutter .embedding .engine .systemchannels .TextInputChannel ;
18+ import io .flutter .plugin .common .MethodCall ;
19+ import io .flutter .plugin .common .MethodChannel ;
20+ import java .util .HashMap ;
21+ import java .util .Map ;
22+ import org .json .JSONException ;
23+ import org .json .JSONObject ;
1224import org .junit .Test ;
1325import org .junit .runner .RunWith ;
26+ import org .mockito .ArgumentCaptor ;
27+ import org .mockito .Matchers ;
1428import org .robolectric .RobolectricTestRunner ;
1529import org .robolectric .RuntimeEnvironment ;
1630import org .robolectric .annotation .Config ;
@@ -37,22 +51,24 @@ public void itIgnoresNewHapticEventsOnOldAndroidPlatforms() {
3751 }
3852
3953 @ Test
40- public void platformPlugin_hasStrings () {
41- View fakeDecorView = mock (View .class );
42- Window fakeWindow = mock (Window .class );
43- when ( fakeWindow . getDecorView ()). thenReturn ( fakeDecorView );
44- Activity fakeActivity = mock ( Activity . class );
45- when ( fakeActivity . getWindow ()). thenReturn ( fakeWindow );
46- PlatformChannel fakePlatformChannel = mock ( PlatformChannel . class );
47- PlatformPlugin platformPlugin = new PlatformPlugin ( fakeActivity , fakePlatformChannel ) ;
48-
49- ClipboardManager clipboardManager =
50- RuntimeEnvironment . application . getSystemService ( ClipboardManager .class );
51- clipboardManager . setText ( "iamastring" );
54+ public void platformPlugin_hasStringsMessage () {
55+ MethodChannel rawChannel = mock (MethodChannel .class );
56+ FlutterJNI mockFlutterJNI = mock (FlutterJNI .class );
57+ DartExecutor dartExecutor = new DartExecutor ( mockFlutterJNI , mock ( AssetManager . class ) );
58+ PlatformChannel fakePlatformChannel = new PlatformChannel ( dartExecutor );
59+ PlatformChannel . PlatformMessageHandler mockMessageHandler = mock ( PlatformChannel . PlatformMessageHandler . class );
60+ fakePlatformChannel . setPlatformMessageHandler ( mockMessageHandler );
61+ Boolean returnValue = true ;
62+ when ( mockMessageHandler . clipboardHasStrings ()). thenReturn ( returnValue );
63+ MethodCall methodCall = new MethodCall ( "Clipboard.hasStrings" , null );
64+ MethodChannel . Result mockResult = mock ( MethodChannel . Result .class );
65+ fakePlatformChannel . parsingMethodCallHandler . onMethodCall ( methodCall , mockResult );
5266
53- // TODO(justinmc): Can't do this because mPlatformMessageHandler is private.
54- // How can I send a message to the platform plugin?
55- //boolean hasStrings = platformPlugin.mPlatformMessageHandler.clipboardHasStrings();
56- //assertTrue(hasStrings);
67+ JSONObject expected = new JSONObject ();
68+ try {
69+ expected .put ("value" , returnValue );
70+ } catch (JSONException e ) {
71+ }
72+ verify (mockResult ).success (Matchers .refEq (expected ));
5773 }
5874}
0 commit comments