HockeyApp extends ServiceImpl implements CrashReportingService { @SuppressWarnings("ResultOfMethodCallIgnored") void createLogEvent(String appId, StoredException storedException, final Callback<Object> deleteStoredExceptionCallback) { final File logFile = writeHockeyAppCrashLog(storedException.stackTrace); if(logFile != null && logFile.exists()) { final TypedFile log = new TypedFile("text/plain", logFile); createService().createEvent( appId, log, createLogEventCallback(deleteStoredExceptionCallback, logFile) ); } } HockeyApp(Context context); @Override void enable(String apiKey); @Override boolean isEnabled(); @Override ServiceType getServiceType(); void logEvent(final StoredException storedException, final Callback<Object> deleteStoredExceptionCallback); HockeyAppService createService();  }
@Test @SuppressWarnings("unchecked") public void testCreateLogEvent() { final Callback mockLogEventCallback = mock(Callback.class); final File tempFile = createTempFile(); HockeyApp hockeyApp = new HockeyApp(null){ @Override File writeHockeyAppCrashLog(String stackTrace) { return tempFile; } @Override Callback<Response> createLogEventCallback(Callback<Object> deleteStoredExceptionCallback, File logFile) { return mockLogEventCallback; } }; StoredException storedException = new StoredException(ServiceType.HOCKEYAPP, "test message", "test threadName", "test\nstack\ntrace"); HockeyApp.HockeyAppService mockService = mock(HockeyApp.HockeyAppService.class); hockeyApp.hockeyAppService = mockService; hockeyApp.createLogEvent("UnitTestingAppId", storedException, null); ArgumentCaptor<TypedFile> typedFileArgumentCaptor = ArgumentCaptor.forClass(TypedFile.class); verify(mockService).createEvent(eq("UnitTestingAppId"), typedFileArgumentCaptor.capture(), eq(mockLogEventCallback)); assertEquals(tempFile, typedFileArgumentCaptor.getValue().file()); assertTrue("Failed to clean up temp file [" + tempFile.getAbsolutePath() + "].", tempFile.delete()); }