### Question:
JsonBasedUserStore implements UserStore, UserCreator { @Override public Optional<User> userFor(String pid) throws AuthenticationUnavailableException { return userAccess.getUserForPid(pid); } 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 userForReturnsAnEmptyOptionalForAnUnknownUser() throws AuthenticationUnavailableException { Optional<User> unknownUser = instance.userFor("pidOfUnknownUser"); assertThat(unknownUser, is(not(present()))); }
@Test public void userForReturnsAnOptionalWithAUserForAKnownUser() throws AuthenticationUnavailableException { Optional<User> knownUser = instance.userFor("pidOfKnownUser"); assertThat(knownUser, is(present())); }
@Test public void ifTheDatabaseContainsOneUserWithNullAsPidThatUserIsReturnedWhenQueryingForNull() throws AuthenticationUnavailableException { Optional<User> knownUser = instance.userFor(null); assertThat(knownUser, is(present())); }
@Test public void userForThrowsAnAuthenticationUnavailableExceptionWhenTheUsersFileCannotBeRead() throws AuthenticationUnavailableException { JsonBasedUserStore instance = forFile(Paths.get("nonExistingUserFile")); expectedException.expect(AuthenticationUnavailableException.class); instance.userFor("pid"); }