68 {
69 Context context = mock(Context.class);
70
72 PlatformViewsController platformViewsController = mock(PlatformViewsController.class);
73 when(flutterEngine.getPlatformViewsController()).thenReturn(platformViewsController);
74
75 FlutterLoader flutterLoader = mock(FlutterLoader.class);
76
77 ExclusiveAppComponent appComponent = mock(ExclusiveAppComponent.class);
78 Activity activity = mock(Activity.class);
79 when(appComponent.getAppComponent()).thenReturn(activity);
80
81 Intent intent = mock(Intent.class);
82 when(activity.getIntent()).thenReturn(intent);
83
84 Lifecycle lifecycle = mock(Lifecycle.class);
85 AtomicBoolean isFirstCall = new AtomicBoolean(true);
86
87
88 FlutterEngineConnectionRegistry registry =
89 new FlutterEngineConnectionRegistry(context, flutterEngine, flutterLoader, null);
90 FakeActivityAwareFlutterPlugin fakePlugin = new FakeActivityAwareFlutterPlugin();
91 registry.add(fakePlugin);
92 registry.attachToActivity(appComponent, lifecycle);
93
94
95 FakeActivityResultListener listener1 =
96 new FakeActivityResultListener(isFirstCall, fakePlugin.binding);
97 FakeActivityResultListener listener2 =
98 new FakeActivityResultListener(isFirstCall, fakePlugin.binding);
99
100 fakePlugin.binding.addActivityResultListener(listener1);
101 fakePlugin.binding.addActivityResultListener(listener2);
102
103
104 registry.onActivityResult(0, 0, intent);
105
106 assertEquals(1, listener1.callCount);
107 assertEquals(1, listener2.callCount);
108
109
110 registry.onActivityResult(0, 0, intent);
111
112
113 assertEquals(3, listener1.callCount + listener2.callCount);
114 }