### Question:
BasicUserValidator implements UserValidator { @Override public Optional<User> getUserFromUserId(String userId) throws UserValidationException { if (userId != null) { try { return userStore.userForId(userId); } catch (AuthenticationUnavailableException e) { throw new UserValidationException(e); } } return Optional.empty(); } 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 getUserFromUserIdReturnsEmptyWhenIdIsNull() throws Exception { Optional<User> user = basicUserValidator.getUserFromUserId(null); assertThat(user, is(Optional.empty())); }
@Test public void getUserFromUserIdReturnsUserWhenIdIsValid() throws Exception { given(userStore.userForId("testUserId")).willReturn(Optional.of(anyUser())); Optional<User> user = basicUserValidator.getUserFromUserId("testUserId"); assertThat(user, is(OptionalPresentMatcher.present())); }