GitHubAdapter implements ApiAdapter<GitHub> { public UserProfile fetchUserProfile(GitHub github) { GitHubUserProfile profile = github.userOperations().getUserProfile(); return new UserProfileBuilder().setName(profile.getName()).setEmail(profile.getEmail()).setUsername(profile.getLogin()).build(); }  boolean test(GitHub github); void setConnectionValues(GitHub github, ConnectionValues values); UserProfile fetchUserProfile(GitHub github); void updateStatus(GitHub github, String message);  }
@Test public void fetchProfile() { UserOperations userOperations = Mockito.mock(UserOperations.class); when(github.userOperations()).thenReturn(userOperations); when(userOperations.getUserProfile()).thenReturn(createProfile(123456L, "habuma", "Craig Walls", "Plano, TX", "SpringSource", null, "cwalls@vmware.com", null, null)); UserProfile profile = apiAdapter.fetchUserProfile(github); assertEquals("Craig Walls", profile.getName()); assertEquals("Craig", profile.getFirstName()); assertEquals("Walls", profile.getLastName()); assertEquals("cwalls@vmware.com", profile.getEmail()); assertEquals("habuma", profile.getUsername()); }
@Test public void fetchProfileFirstNameOnly() { UserOperations userOperations = Mockito.mock(UserOperations.class); when(github.userOperations()).thenReturn(userOperations); when(userOperations.getUserProfile()).thenReturn(createProfile(123456L, "habuma", "Craig", "Plano, TX", "SpringSource", null, "cwalls@vmware.com", null, null)); UserProfile profile = apiAdapter.fetchUserProfile(github); assertEquals("Craig", profile.getName()); assertEquals("Craig", profile.getFirstName()); assertNull(profile.getLastName()); assertEquals("cwalls@vmware.com", profile.getEmail()); assertEquals("habuma", profile.getUsername()); }
@Test public void fetchProfileMiddleName() { UserOperations userOperations = Mockito.mock(UserOperations.class); when(github.userOperations()).thenReturn(userOperations); when(userOperations.getUserProfile()).thenReturn(createProfile(123456L, "habuma", "Michael Craig Walls", "Plano, TX", "SpringSource", null, "cwalls@vmware.com", null, null)); UserProfile profile = apiAdapter.fetchUserProfile(github); assertEquals("Michael Craig Walls", profile.getName()); assertEquals("Michael", profile.getFirstName()); assertEquals("Walls", profile.getLastName()); assertEquals("cwalls@vmware.com", profile.getEmail()); assertEquals("habuma", profile.getUsername()); }
@Test public void fetchProfileExtraWhitespace() { UserOperations userOperations = Mockito.mock(UserOperations.class); when(github.userOperations()).thenReturn(userOperations); when(userOperations.getUserProfile()).thenReturn(createProfile(123456L, "habuma", "Michael Craig Walls", "Plano, TX", "SpringSource", null, "cwalls@vmware.com", null, null)); UserProfile profile = apiAdapter.fetchUserProfile(github); assertEquals("Michael Craig Walls", profile.getName()); assertEquals("Michael", profile.getFirstName()); assertEquals("Walls", profile.getLastName()); assertEquals("cwalls@vmware.com", profile.getEmail()); assertEquals("habuma", profile.getUsername()); }