@Test public void test_createUser_userExists() { String NAME = "name"; String FIRST_NAME = "firstname"; String LAST_NAME = "lastName"; String EMAIL = "email"; String USERNAME = "username"; String PROVIDER_ID = "providerId"; String PROVIDER_USER_ID = "providerUserId"; String EXISTING_USERNAME = USERNAME + "_" + PROVIDER_ID; String NEW_USERNAME = "newuser_providerId"; UserProfile profile = new UserProfile(USER_ID, NAME, FIRST_NAME, LAST_NAME, EMAIL, USERNAME); User user = new User(); user.setUsername(EXISTING_USERNAME); Mockito.when(userManager.findUser(EXISTING_USERNAME)).thenReturn(user); Mockito.when(userManager.getUniqueUsername(PROVIDER_ID)).thenReturn(NEW_USERNAME); Mockito.when(connection.fetchUserProfile()).thenReturn(profile); Mockito.when(connection.getKey()).thenReturn(new ConnectionKey(PROVIDER_ID, PROVIDER_USER_ID)); User createdUser = helperToTest.createUser(connection); Assert.assertNotNull(createdUser); Assert.assertEquals(NAME, createdUser.getName()); Assert.assertEquals(FIRST_NAME, createdUser.getFirstname()); Assert.assertEquals(LAST_NAME, createdUser.getLastname()); Assert.assertEquals(EMAIL, createdUser.getEmail()); Assert.assertEquals(NEW_USERNAME, createdUser.getUsername()); Assert.assertEquals(PROVIDER_ID, createdUser.getProvider()); Assert.assertEquals(PROVIDER_USER_ID, createdUser.getUserIdOfProvider()); Assert.assertEquals(AccountStatus.ADDED, createdUser.getAccountStatus()); }
@Override public User createUser(Connection<?> connection) { UserProfile profile = connection.fetchUserProfile(); String username = profile.getUsername() + "_" + connection.getKey().getProviderId(); User user = new User(); User userWithUsername = userManager.findUser(username); if (userWithUsername == null) { user.setUsername(username); } else { user.setUsername(userManager.getUniqueUsername(connection.getKey().getProviderId())); } user.setFirstname(profile.getFirstName()); user.setLastname(profile.getLastName()); user.setName(profile.getName()); user.setEmail(profile.getEmail()); user.setProvider(connection.getKey().getProviderId()); user.setUserIdOfProvider(connection.getKey().getProviderUserId()); user.setAccountStatus(AccountStatus.ADDED); return user; }
UserHelper implements IUserHelper { @Override public User createUser(Connection<?> connection) { UserProfile profile = connection.fetchUserProfile(); String username = profile.getUsername() + "_" + connection.getKey().getProviderId(); User user = new User(); User userWithUsername = userManager.findUser(username); if (userWithUsername == null) { user.setUsername(username); } else { user.setUsername(userManager.getUniqueUsername(connection.getKey().getProviderId())); } user.setFirstname(profile.getFirstName()); user.setLastname(profile.getLastName()); user.setName(profile.getName()); user.setEmail(profile.getEmail()); user.setProvider(connection.getKey().getProviderId()); user.setUserIdOfProvider(connection.getKey().getProviderUserId()); user.setAccountStatus(AccountStatus.ADDED); return user; } }
UserHelper implements IUserHelper { @Override public User createUser(Connection<?> connection) { UserProfile profile = connection.fetchUserProfile(); String username = profile.getUsername() + "_" + connection.getKey().getProviderId(); User user = new User(); User userWithUsername = userManager.findUser(username); if (userWithUsername == null) { user.setUsername(username); } else { user.setUsername(userManager.getUniqueUsername(connection.getKey().getProviderId())); } user.setFirstname(profile.getFirstName()); user.setLastname(profile.getLastName()); user.setName(profile.getName()); user.setEmail(profile.getEmail()); user.setProvider(connection.getKey().getProviderId()); user.setUserIdOfProvider(connection.getKey().getProviderUserId()); user.setAccountStatus(AccountStatus.ADDED); return user; }  }
UserHelper implements IUserHelper { @Override public User createUser(Connection<?> connection) { UserProfile profile = connection.fetchUserProfile(); String username = profile.getUsername() + "_" + connection.getKey().getProviderId(); User user = new User(); User userWithUsername = userManager.findUser(username); if (userWithUsername == null) { user.setUsername(username); } else { user.setUsername(userManager.getUniqueUsername(connection.getKey().getProviderId())); } user.setFirstname(profile.getFirstName()); user.setLastname(profile.getLastName()); user.setName(profile.getName()); user.setEmail(profile.getEmail()); user.setProvider(connection.getKey().getProviderId()); user.setUserIdOfProvider(connection.getKey().getProviderUserId()); user.setAccountStatus(AccountStatus.ADDED); return user; }  @Override User createUser(Connection<?> connection); }
UserHelper implements IUserHelper { @Override public User createUser(Connection<?> connection) { UserProfile profile = connection.fetchUserProfile(); String username = profile.getUsername() + "_" + connection.getKey().getProviderId(); User user = new User(); User userWithUsername = userManager.findUser(username); if (userWithUsername == null) { user.setUsername(username); } else { user.setUsername(userManager.getUniqueUsername(connection.getKey().getProviderId())); } user.setFirstname(profile.getFirstName()); user.setLastname(profile.getLastName()); user.setName(profile.getName()); user.setEmail(profile.getEmail()); user.setProvider(connection.getKey().getProviderId()); user.setUserIdOfProvider(connection.getKey().getProviderUserId()); user.setAccountStatus(AccountStatus.ADDED); return user; }  @Override User createUser(Connection<?> connection);  }