HockeyApp extends ServiceImpl implements CrashReportingService { Callback<Response> createLogEventCallback(final Callback<Object> deleteStoredExceptionCallback, final File logFile) { return new Callback<Response>() { @Override public void success(Response resp, Response response) { if(!logFile.delete()){ utils.logIssue("Unable to clean up temp HockeyApp file", null); } if(deleteStoredExceptionCallback != null) { deleteStoredExceptionCallback.success(resp, response); } } @Override public void failure(RetrofitError error) { if(!logFile.delete()){ utils.logIssue("Unable to clean up temp HockeyApp file", null); } if(deleteStoredExceptionCallback != null) { deleteStoredExceptionCallback.failure(error); } } }; } 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 testCreateLogEventCallbackSuccess() { HockeyApp hockeyApp = new HockeyApp(null); Callback mockDeleteStoredExceptionCallback = mock(Callback.class); File tempFile = createTempFile(); Callback callback = hockeyApp.createLogEventCallback(mockDeleteStoredExceptionCallback, tempFile); assertTrue(tempFile.exists()); callback.success(null, null); assertFalse(tempFile.exists()); verify(mockDeleteStoredExceptionCallback).success(any(Response.class), any(Response.class)); }
@Test @SuppressWarnings("unchecked") public void testCreateLogEventCallbackFailure() { HockeyApp hockeyApp = new HockeyApp(null); Callback mockDeleteStoredExceptionCallback = mock(Callback.class); File tempFile = createTempFile(); Callback callback = hockeyApp.createLogEventCallback(mockDeleteStoredExceptionCallback, tempFile); assertTrue(tempFile.exists()); callback.failure(null); assertFalse(tempFile.exists()); verify(mockDeleteStoredExceptionCallback).failure(any(RetrofitError.class)); }