### Question:
JsonBasedUserStore implements UserStore, UserCreator { @Override public User createUser(String pid, String email, String givenName, String surname, String organization) throws UserCreationException { User user = User.create(String.format("%s %s", givenName, surname), pid); try { Optional<User> userForPid = userAccess.getUserForPid(pid); if (userForPid.isPresent()) { return userForPid.get(); } else { userAccess.addUser(user); return user; } } catch (AuthenticationUnavailableException e) { throw new UserCreationException(e); } } JsonBasedUserStore(UserAccess userAccess); @Override Optional<User> userFor(String pid); @Override Optional<User> userForId(String userId); @Override User saveNew(String displayName, String persistentId); @Override User createUser(String pid, String email, String givenName, String surname, String organization); static final Logger LOG; }### Answer:
@Test public void createUserLetsTheUserBeCreatedOnlyOnce() throws Exception { User user1 = instance.createUser("pid", "email", "givenName", "surname", "organization"); User user2 = instance.createUser("pid", "email", "givenName", "surname", "organization"); assertThat(user1.getId(), is(user2.getId())); }
@Test public void createUserThrowsAUserCreationExceptionWhenTheUsersFileCannotBeRead() throws Exception { Path nonExistingUsersFile = Paths.get("src", "test", "resources", "users1.json"); JsonBasedUserStore instance = forFile(nonExistingUsersFile); expectedException.expect(UserCreationException.class); instance.createUser("pid", "email", "givenName", "surname", "organization"); }