### Question:
TwitterAdapter implements ApiAdapter<Twitter> { public UserProfile fetchUserProfile(Twitter twitter) { TwitterProfile profile = twitter.userOperations().getUserProfile(); return new UserProfileBuilder().setName(profile.getName()).setUsername(profile.getScreenName()).build(); }  boolean test(Twitter twitter); void setConnectionValues(Twitter twitter, ConnectionValues values); UserProfile fetchUserProfile(Twitter twitter); void updateStatus(Twitter twitter, String message);  }### Answer:
@Test public void fetchProfile() { UserOperations userOperations = Mockito.mock(UserOperations.class); Mockito.when(twitter.userOperations()).thenReturn(userOperations); Mockito.when(userOperations.getUserProfile()).thenReturn(new TwitterProfile(123L, "kdonald", "Keith Donald", "https: UserProfile profile = apiAdapter.fetchUserProfile(twitter); assertEquals("Keith Donald", profile.getName()); assertEquals("Keith", profile.getFirstName()); assertEquals("Donald", profile.getLastName()); assertNull(profile.getEmail()); assertEquals("kdonald", profile.getUsername()); }
@Test public void fetchProfileFirstNameOnly() { UserOperations userOperations = Mockito.mock(UserOperations.class); Mockito.when(twitter.userOperations()).thenReturn(userOperations); Mockito.when(userOperations.getUserProfile()).thenReturn(new TwitterProfile(123L, "kdonald", "Keith", "https: UserProfile profile = apiAdapter.fetchUserProfile(twitter); assertEquals("Keith", profile.getName()); assertEquals("Keith", profile.getFirstName()); assertNull(profile.getLastName()); assertNull(profile.getEmail()); assertEquals("kdonald", profile.getUsername()); }
@Test public void fetchProfileMiddleName() { UserOperations userOperations = Mockito.mock(UserOperations.class); Mockito.when(twitter.userOperations()).thenReturn(userOperations); Mockito.when(userOperations.getUserProfile()).thenReturn(new TwitterProfile(123L, "kdonald", "Keith Preston Donald", "https: UserProfile profile = apiAdapter.fetchUserProfile(twitter); assertEquals("Keith Preston Donald", profile.getName()); assertEquals("Keith", profile.getFirstName()); assertEquals("Donald", profile.getLastName()); assertNull(profile.getEmail()); assertEquals("kdonald", profile.getUsername()); }
@Test public void fetchProfileExtraWhitespace() { UserOperations userOperations = Mockito.mock(UserOperations.class); Mockito.when(twitter.userOperations()).thenReturn(userOperations); Mockito.when(userOperations.getUserProfile()).thenReturn(new TwitterProfile(123L, "kdonald", "Keith Preston Donald", "https: UserProfile profile = apiAdapter.fetchUserProfile(twitter); assertEquals("Keith Preston Donald", profile.getName()); assertEquals("Keith", profile.getFirstName()); assertEquals("Donald", profile.getLastName()); assertNull(profile.getEmail()); assertEquals("kdonald", profile.getUsername()); }
@Test @Ignore public void fetchProfile_IOError() { UserOperations userOperations = Mockito.mock(UserOperations.class); Mockito.when(twitter.userOperations()).thenReturn(userOperations); Mockito.when(userOperations.getUserProfile()).thenThrow(new ResourceAccessException("Resource access exception")); apiAdapter.fetchUserProfile(twitter); }