### Question:
SecurityContextServiceImpl implements SecurityContextService { @Override public Optional<Authentication> getLoggedInUser() { return Optional.ofNullable(securityContextHolder.getContext().getAuthentication()); } SecurityContextServiceImpl(final SecurityContextHolderSpringDelegate securityContextHolder, final ProfileService profileService); @Override Optional<Authentication> getLoggedInUser(); @Override boolean isUserFullyAuthenticated(); @Override Optional<UserProfile> getLoggedInUserProfile();  }### Answer:
@Test public void getLoggedInUser_present() { final Authentication expected = mock(Authentication.class); when(securityContextHolder.getContext().getAuthentication()).thenReturn(expected); final Optional<Authentication> loggedInUser = securityContextService.getLoggedInUser(); assertThat(loggedInUser).containsSame(expected); }
@Test public void getLoggedInUser_notPresent() { when(securityContextHolder.getContext().getAuthentication()).thenReturn(null); final Optional<Authentication> loggedInUser = securityContextService.getLoggedInUser(); assertThat(loggedInUser).isEmpty(); }