LifecycleUtil { public static void closeOnDestroy( final @NonNull LifecycleOwner owner, final @NonNull Scope scope) { owner .getLifecycle() .addObserver( new DefaultLifecycleObserver() { @Override public void onDestroy(@NonNull LifecycleOwner owner) { closeScope(scope.getName()); } }); } private  LifecycleUtil(); static void closeOnDestroy(
      final @NonNull LifecycleOwner owner, final @NonNull Scope scope);  }
@Test public void testCloseOnDestroy() { ActivityController<FragmentActivity> activityController = Robolectric.buildActivity(FragmentActivity.class).create(); FragmentActivity activity = activityController.get(); Application application = ApplicationProvider.getApplicationContext(); Scope activityScope = Toothpick.openScopes(application, activity); LifecycleUtil.closeOnDestroy(activity, activityScope); activityController.destroy(); assertThat(Toothpick.isScopeOpen(activity), is(false)); }