107 {
108
109
110 FlutterLoader mockFlutterLoader = mock(FlutterLoader.class);
111 FlutterJNI mockFlutterJni = mock(FlutterJNI.class);
112 when(mockFlutterJni.isAttached()).thenReturn(true);
114 FlutterEngineCache.getInstance().put("my_flutter_engine", cachedEngine);
115
116
117 FlutterPlugin mockPlugin =
118 mock(FlutterPlugin.class, withSettings().extraInterfaces(ActivityAware.class));
119 ActivityAware activityAwarePlugin = (ActivityAware) mockPlugin;
120 ActivityPluginBinding.OnSaveInstanceStateListener mockSaveStateListener =
121 mock(ActivityPluginBinding.OnSaveInstanceStateListener.class);
122
123
124 doAnswer(
125 new Answer() {
126 @Override
127 public Object answer(InvocationOnMock invocation) throws Throwable {
128 ActivityPluginBinding binding =
129 (ActivityPluginBinding) invocation.getArguments()[0];
130 binding.addOnSaveStateListener(mockSaveStateListener);
131 return null;
132 }
133 })
134 .when(activityAwarePlugin)
135 .onAttachedToActivity(
any(ActivityPluginBinding.class));
136
137 cachedEngine.getPlugins().add(mockPlugin);
138
139
140 FlutterActivityAndFragmentDelegate.Host fakeHost = new FakeHost(cachedEngine);
141
142 FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(fakeHost);
143
144
145
146 delegate.onAttach(ctx);
147
148
149 ArgumentCaptor<ActivityPluginBinding> pluginBindingCaptor =
150 ArgumentCaptor.forClass(ActivityPluginBinding.class);
151 verify(activityAwarePlugin,
times(1)).onAttachedToActivity(pluginBindingCaptor.capture());
152 ActivityPluginBinding binding = pluginBindingCaptor.getValue();
153 assertNotNull(binding.getActivity());
154 assertNotNull(binding.getLifecycle());
155
156 delegate.onRestoreInstanceState(null);
157
158
159 verify(mockSaveStateListener,
times(1)).onRestoreInstanceState(isNull());
160
161 delegate.onCreateView(null, null, null, 0, true);
162 delegate.onStart();
163 delegate.onResume();
164 delegate.onPause();
165 delegate.onStop();
166 delegate.onSaveInstanceState(mock(Bundle.class));
167
168
169 verify(mockSaveStateListener,
times(1)).onSaveInstanceState(
any(Bundle.class));
170
171 delegate.onDestroyView();
172 delegate.onDetach();
173
174
175 verify(activityAwarePlugin,
times(1)).onDetachedFromActivity();
176 }
static SkISize times(const SkISize &size, float factor)
SIT bool any(const Vec< 1, T > &x)