206 {
207 DartExecutor mockBinaryMessenger = mock(DartExecutor.class);
208 PackageManager mockPackageManager = mock(PackageManager.class);
209 ProcessTextChannel processTextChannel =
210 new ProcessTextChannel(mockBinaryMessenger, mockPackageManager);
211
212
213 ResolveInfo action1 = createFakeResolveInfo("Action1", mockPackageManager);
214 ResolveInfo action2 = createFakeResolveInfo("Action2", mockPackageManager);
215 List<ResolveInfo> infos =
new ArrayList<ResolveInfo>(Arrays.asList(action1, action2));
216 when(mockPackageManager.queryIntentActivities(
217 any(Intent.class),
any(PackageManager.ResolveInfoFlags.class)))
218 .thenReturn(infos);
219
220
221 ProcessTextPlugin processTextPlugin = new ProcessTextPlugin(processTextChannel);
222 Map<String, String> textActions = processTextPlugin.queryTextActions();
223 final String action1Id = "mockActivityName.Action1";
224 final String action2Id = "mockActivityName.Action2";
225 assertEquals(textActions, Map.of(action1Id, "Action1", action2Id, "Action2"));
226
227
228 ActivityPluginBinding mockActivityPluginBinding = mock(ActivityPluginBinding.class);
229 Activity mockActivity = mock(Activity.class);
230 when(mockActivityPluginBinding.getActivity()).thenReturn(mockActivity);
231 processTextPlugin.onAttachedToActivity(mockActivityPluginBinding);
232
233
234 String textToBeProcessed = "Flutter!";
235 MethodChannel.Result
result = mock(MethodChannel.Result.class);
236 processTextPlugin.processTextAction(action1Id, textToBeProcessed,
false,
result);
237
238
239 ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
240 verify(mockActivity,
times(1)).startActivityForResult(intentCaptor.capture(), anyInt());
241 Intent intent = intentCaptor.getValue();
242 assertEquals(intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT), textToBeProcessed);
243
244
245 final int externalRequestCode = 42;
246 processTextPlugin.onActivityResult(externalRequestCode, Activity.RESULT_OK, new Intent());
247
248
249 String processedText = "Flutter!!!";
250 Intent resultIntent = new Intent();
251 resultIntent.putExtra(Intent.EXTRA_PROCESS_TEXT, processedText);
252 processTextPlugin.onActivityResult(
result.hashCode(), Activity.RESULT_OK, resultIntent);
253
254
255 verify(
result).success(processedText);
256 }
static SkISize times(const SkISize &size, float factor)
SIT bool any(const Vec< 1, T > &x)