### Question:
BasicUserValidator implements UserValidator { @Override public Optional<User> getUserFromPersistentId(String persistentId) throws UserValidationException { if (persistentId == null) { return Optional.empty(); } try { return userStore.userFor(persistentId); } catch (AuthenticationUnavailableException e) { throw new UserValidationException(e); } } BasicUserValidator(UserStore userStore, LoggedInUsers loggedInUsers); @Override Optional<User> getUserFromAccessToken(String accessToken); @Override Optional<User> getUserFromUserId(String userId); @Override Optional<User> getUserFromPersistentId(String persistentId);  }### Answer:
@Test public void getUserFromPersistentIdReturnsEmptyWhenTheIdIsNull() throws Exception { Optional<User> user = basicUserValidator.getUserFromPersistentId(null); assertThat(user, is(Optional.empty())); }
@Test public void getUserFromPersistentIdReturnsEmptyWhenTheCannotBeFound() throws Exception { given(userStore.userFor("pid")).willReturn(Optional.empty()); Optional<User> user = basicUserValidator.getUserFromPersistentId("userId"); assertThat(user, is(Optional.empty())); }
@Test public void getUserFromPersistentIdReturnsUserWhenIdIsValid() throws Exception { given(userStore.userFor("pid")).willReturn(Optional.of(anyUser())); Optional<User> user = basicUserValidator.getUserFromPersistentId("pid"); assertThat(user, is(OptionalPresentMatcher.present())); }