@@ -378,21 +378,31 @@ public void itDoesNotAttachFlutterToTheActivityIfNotDesired() {
378
378
// Declare that the host does NOT want Flutter to attach to the surrounding Activity.
379
379
when (mockHost .shouldAttachEngineToActivity ()).thenReturn (false );
380
380
381
+ // getActivity() returns null if the activity is not attached
382
+ when (mockHost .getActivity ()).thenReturn (null );
383
+
381
384
// Create the real object that we're testing.
382
385
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate (mockHost );
383
386
384
387
// --- Execute the behavior under test ---
385
388
// Flutter is attached to the surrounding Activity in onAttach.
386
389
delegate .onAttach (RuntimeEnvironment .application );
387
390
388
- // Verify that the ActivityControlSurface was NOT told to attach to an Activity.
389
- verify (mockFlutterEngine .getActivityControlSurface (), never ())
390
- .attachToActivity (any (Activity .class ), any (Lifecycle .class ));
391
+ // Make sure all of the other lifecycle methods can run safely as well
392
+ // without a valid Activity
393
+ delegate .onCreateView (null , null , null );
394
+ delegate .onStart ();
395
+ delegate .onResume ();
396
+ delegate .onPause ();
397
+ delegate .onStop ();
398
+ delegate .onDestroyView ();
391
399
392
400
// Flutter is detached from the surrounding Activity in onDetach.
393
401
delegate .onDetach ();
394
402
395
- // Verify that the ActivityControlSurface was NOT told to detach from the Activity.
403
+ // Verify that the ActivityControlSurface was NOT told to attach or detach to an Activity.
404
+ verify (mockFlutterEngine .getActivityControlSurface (), never ())
405
+ .attachToActivity (any (Activity .class ), any (Lifecycle .class ));
396
406
verify (mockFlutterEngine .getActivityControlSurface (), never ()).detachFromActivity ();
397
407
}
398
408
0 commit comments