Mixpanel extends ServiceImpl implements EventTrackingService { @Override public void logEvent(Context context, String eventName) { MixpanelEvent event = new MixpanelEvent(); event.event = eventName; event.properties.put("token", projectToken); event.properties.put("distinct_id", utils.getAndroidId(context)); String data = eventObjToBase64(event); createService().trackEvent(data, new NoOpCallback()); } Mixpanel(Context context); @Override void enable(String projectToken); @Override boolean isEnabled(); @Override ServiceType getServiceType(); @Override void logEvent(Context context, String eventName);  }
@Test @SuppressWarnings("unchecked") public void testLogEvent() { Mixpanel.MixpanelService mockMixpanelService = mock(Mixpanel.MixpanelService.class); Mixpanel mixpanel = new Mixpanel(null){ @Override protected String toBase64(byte[] data) { return new String(data); } }; mixpanel.utils = UnitTestUtils.mockUtils(); mixpanel.mixpanelService = mockMixpanelService; mixpanel.logEvent(null, "unittest_event"); String expectedJson = "{\"event\":\"unittest_event\",\"properties\":{\"distinct_id\":\"123456789\"}}"; verify(mockMixpanelService).trackEvent(eq(expectedJson), any(NoOpCallback.class)); }