Graphite extends ServiceImpl implements EventTrackingService { @Override public void logEvent(Context context, String event) { StringBuilder eventData = new StringBuilder(); if(utils.isNotBlank(apiKey)){ eventData.append(apiKey); eventData.append("."); } eventData.append(utils.getApplicationPackageName(context)); eventData.append("."); eventData.append(event); eventData.append(" 1 "); eventData.append(getTimeStamp()); eventData.append("\n"); sendData(eventData.toString()); } Graphite(Context context); @Override void enable(String url); @Override boolean isEnabled(); @Override ServiceType getServiceType(); @Override void logEvent(Context context, String event);  }
@Test public void testLogEvent() { Graphite graphite = mock(Graphite.class); graphite.utils = UnitTestUtils.mockUtils(); doCallRealMethod().when(graphite).logEvent(any(Context.class), anyString()); when(graphite.getTimeStamp()).thenReturn(140000000L); graphite.logEvent(null, "unit_test_event"); String expectedMessage = "com.percolate.foam.unit.testing.unit_test_event 1 140000000\n"; verify(graphite).sendData(eq(expectedMessage)); }