GoogleAnalytics extends ServiceImpl implements EventTrackingService { public void logEvent(Context context, String event){ try { String payload = createPayloadData(event); createService().createEvent(payload, new NoOpCallback()); } catch (Exception ex) { utils.logIssue("Could not send google analytics data", ex); } } GoogleAnalytics(Context context); @Override void enable(String trackingId); @Override boolean isEnabled(); @Override ServiceType getServiceType(); void logEvent(Context context, String event);  }
@Test public void testLogEvent() { GoogleAnalytics googleAnalytics = new GoogleAnalytics(null){ @Override String createPayloadData(String event) { return "test_payload"; } }; GoogleAnalytics.GoogleAnalyticsService mockService = mock(GoogleAnalytics.GoogleAnalyticsService.class); googleAnalytics.googleAnalyticsService = mockService; googleAnalytics.logEvent(null, "test_event"); verify(mockService).createEvent(eq("test_payload"), any(NoOpCallback.class)); }