reset method

void reset()

Fresh doubles and a clean slate of process-wide state, for the current test.

This deliberately does not touch bifrostServiceLocator. An app already has a dependency-injection container, and its own bindings already point the locator at it — so assigning one here created a second injection system racing the first, where which one won depended on whether reset() or the app's bindings ran last. Tests should resolve services the same way production does; to observe one, register a double through the app's own container:

bifrostTestEnv.reset();
Bind.put<SystemNotifier>(bifrostTestEnv.notifier, permanent: true);

A package with no container of its own — this one included — can call installDoubles instead.

Implementation

void reset() {
  storage = MockStorage();
  notifier = MockNotifier();
  connectionChecker = MockConnectionChecker();
  analytics = MockAnalyticsService();
  entitlements.dispose();
  entitlements = MockEntitlementService();
  paywalls = MockPaywallPresenter();
  attribution = MockAttributionService();

  bifrostClock = DateTime.now;

  // The transport and the store, not just the doubles above.
  //
  // Both are process-wide state a test can change, so putting them back is
  // part of "reset", not something every app should have to remember in its
  // own `setUp`. `useMockStorage` also has to repeat per test: the mock store
  // is a *static* platform instance, so a value one test writes is still
  // readable in the next until it is cleared.
  //
  // Clearing the responder returns mocked requests to `useMockClient`'s own
  // shouldFail/responseFactory behaviour, so one test's responder cannot leak
  // into the next.
  bifrostMockResponder = null;
  useMockClient();
  useMockStorage();
  bifrostJsonDecode = (body) async => jsonDecode(body);
  bifrostPerformanceTracker = const NoOpPerformanceTracker();
}