DeleteFileCallback implements Callback<Object> { @Override public void success(Object o, Response response) { try { context.deleteFile(storedExceptionFileName); } catch(Exception ex){ utils.logIssue("Could not delete file [" + storedExceptionFileName + "]", ex); } } DeleteFileCallback(Context context, String storedExceptionFileName); @Override void success(Object o, Response response); @Override void failure(RetrofitError error);  }
@Test public void testSuccessMethod() { Context mockContext = mock(Context.class); DeleteFileCallback deleteFileCallback = new DeleteFileCallback(mockContext, "unit_testing_file_name.txt"); deleteFileCallback.success(null, null); verify(mockContext).deleteFile(eq("unit_testing_file_name.txt")); }
@Test public void testSuccessError() { Context mockContext = mock(Context.class); Exception exceptionToThrow = new RuntimeException("Unit Testing"); when(mockContext.deleteFile(anyString())).thenThrow(exceptionToThrow); DeleteFileCallback deleteFileCallback = new DeleteFileCallback(mockContext, "unit_testing_file_name.txt"); Utils mockUtils = UnitTestUtils.mockUtils(); deleteFileCallback.utils = mockUtils; deleteFileCallback.success(null, null); verify(mockUtils).logIssue(startsWith("Could not delete file"), eq(exceptionToThrow)); }