### Question:
ProfilesExpressionObject { public Optional<UserProfile> findByUserId(final String userId) { try { return StringUtils.isBlank(userId) ? Optional.empty() : Optional.ofNullable(profileService.getNonLoggedInUserProfile(userId)); } catch (Exception e) { LOGGER.error("Error getting profile for: \"" + userId + "\"", e); return Optional.empty(); } } ProfilesExpressionObject(final ProfileService profileService); Optional<UserProfile> findByUserId(final String userId); Function<UserProfile, String> getName();  }### Answer:
@Test public void findByUserId() { final UserProfile expected = mock(UserProfile.class); Principal principal = PrincipalMother.davyvanroy(); when(profileService.getNonLoggedInUserProfile(principal.getName())).thenReturn(expected); final Optional<UserProfile> result = profiles.findByUserId(principal.getName()); assertThat(result).contains(expected); }
@Test public void findByUserId_profileNull() { final String userId = "hgj"; when(profileService.getUserProfile(() -> userId)).thenReturn(null); final Optional<UserProfile> result = profiles.findByUserId(userId); assertThat(result).isEmpty(); }
@Test public void findByUserId_inputNull() { final Optional<UserProfile> result = profiles.findByUserId(null); verifyZeroInteractions(profileService); assertThat(result).isEmpty(); }