EventTracker { public void start() { if(context instanceof Application){ ((Application) context).registerActivityLifecycleCallbacks(callbacks); callbacksIsRegistered = true; } else { utils.logIssue("EventTracker could not start. Context is not of type Application", null); } } EventTracker(Context context, List<EventTrackingService> services, boolean wifiOnly); void start();  }
@Test public void testStart() { Application mockContext = mock(Application.class); final Application.ActivityLifecycleCallbacks mockCallbacks = mock(Application.ActivityLifecycleCallbacks.class); EventTracker eventTracker = new EventTracker(mockContext, null, false){ @Override Application.ActivityLifecycleCallbacks createActivityLifecycleCallback() { return mockCallbacks; } }; eventTracker.start(); verify(mockContext).registerActivityLifecycleCallbacks(mockCallbacks); }
@Test public void testStartFailure() { Context mockContext = mock(Context.class); EventTracker eventTracker = new EventTracker(mockContext, null, false); Utils mockUtils = UnitTestUtils.mockUtils(); eventTracker.utils = mockUtils; eventTracker.start(); verify(mockUtils).logIssue(startsWith("EventTracker could not start"), isNull(Throwable.class)); }