EventTracker { void trackEvent(Context context, String event) { for (EventTrackingService service : services) { if (service.isEnabled()) { service.logEvent(context, event); } } } EventTracker(Context context, List<EventTrackingService> services, boolean wifiOnly); void start();  }
@Test public void testTrackEvent() { Context mockContext = mock(Context.class); List<EventTrackingService> mockServices = new ArrayList<>(); EventTrackingService mockService1 = mock(EventTrackingService.class); EventTrackingService mockService2 = mock(EventTrackingService.class); EventTrackingService mockService3 = mock(EventTrackingService.class); when(mockService1.isEnabled()).thenReturn(true); when(mockService2.isEnabled()).thenReturn(false); when(mockService3.isEnabled()).thenReturn(true); mockServices.add(mockService1); mockServices.add(mockService2); mockServices.add(mockService3); EventTracker eventTracker = new EventTracker(mockContext, mockServices, false); eventTracker.trackEvent(mockContext, "unit_testing_event"); verify(mockService1, times(1)).logEvent(eq(mockContext), eq("unit_testing_event")); verify(mockService2, never()).logEvent(eq(mockContext), eq("unit_testing_event")); verify(mockService3, times(1)).logEvent(eq(mockContext), eq("unit_testing_event")); }