LoggingCallback extends Callback<T> { @Override public void failure(TwitterException exception) { logger.e(TweetUi.LOGTAG, exception.getMessage(), exception); if (cb != null) { cb.failure(exception); } } LoggingCallback(Callback cb, Logger logger); @Override void failure(TwitterException exception);  }
@Test public void testFailure_callsCb() { final Callback<Tweet> developerCallback = mock(Callback.class); final LoggingCallback<Tweet> cb = new TestLoggingCallback<>(developerCallback, mock(Logger.class)); cb.failure(mock(TwitterException.class)); verify(developerCallback).failure(any(TwitterException.class)); }
@Test public void testFailure_handlesNullCb() { final Logger logger = mock(Logger.class); final LoggingCallback<Tweet> cb = new TestLoggingCallback<>(null, logger); try { cb.failure(new TwitterException(TEST_MESSAGE)); verify(logger).e(any(String.class), any(String.class), any(Throwable.class)); } catch (NullPointerException e) { fail("Should have handled null callback"); } }
@Test public void testFailure_logsFailure() { final Callback<Tweet> developerCallback = mock(Callback.class); final Logger logger = mock(Logger.class); final LoggingCallback<Tweet> cb = new TestLoggingCallback<>(developerCallback, logger); cb.failure(new TwitterException(TEST_MESSAGE)); verify(logger).e(any(String.class), any(String.class), any(Throwable.class)); }