ResetTweetCallback extends Callback<Tweet> { @Override public void success(Result<Tweet> result) { tweetRepository.updateCache(result.data); baseTweetView.setTweet(result.data); if (cb != null) { cb.success(result); } } ResetTweetCallback(BaseTweetView baseTweetView, TweetRepository tweetRepository,
                        Callback<Tweet> cb); @Override void success(Result<Tweet> result); @Override void failure(TwitterException exception);  }
@Test public void testSuccess() { final Callback<Tweet> developerCallback = mock(Callback.class); final ResetTweetCallback resetCallback = new ResetTweetCallback(mockTweetView, mockTweetRepository, developerCallback); final Result<Tweet> successResult = new Result<>(TestFixtures.TEST_TWEET, null); resetCallback.success(successResult); verify(mockTweetRepository).updateCache(TestFixtures.TEST_TWEET); verify(mockTweetView).setTweet(TestFixtures.TEST_TWEET); verify(developerCallback).success(successResult); }
@Test public void testSuccess_handlesNullCallback() { final Callback<Tweet> developerCallback = mock(Callback.class); final ResetTweetCallback resetCallback = new ResetTweetCallback(mockTweetView, mockTweetRepository, null); final Result<Tweet> successResult = new Result<>(TestFixtures.TEST_TWEET, null); try { resetCallback.success(successResult); } catch (NullPointerException e) { fail("Should have handled null callback"); } verify(mockTweetRepository).updateCache(TestFixtures.TEST_TWEET); verify(mockTweetView).setTweet(TestFixtures.TEST_TWEET); }