@Test
public void updateFromSocialLogin() {
UserService userService = new UserServiceImpl(usersConnectionRepository, validator, applicationConfig);
((UserServiceImpl)userService).setUserRepository(userRepository);
UserProfileBuilder builder = new UserProfileBuilder();
UserProfile profile = builder.setFirstName("Tom").setLastName("Tucker").setEmail("tt@example.com").setUsername("ttucker").build();
when(connection.fetchUserProfile()).thenReturn(profile);
userService.socialLogin(connection);
//login again and update
profile = builder.setFirstName("Foo").setLastName("Bar").setEmail("foobar@example.com").setUsername("foobar").build();
when(connection.fetchUserProfile()).thenReturn(profile);
AuthenticatedUserToken token = userService.socialLogin(connection);
ExternalUser user = userService.getUser(new ExternalUser(token.getUserId()), token.getUserId());
assertThat(user, is(notNullValue()));
assertThat(user.getEmailAddress(), is("foobar@example.com"));