### Question:
SecurityUtil { public static void logInUser(User user) { LOGGER.info("Logging in user: {}", user); ExampleUserDetails userDetails = ExampleUserDetails.getBuilder() .firstName(user.getFirstName()) .id(user.getId()) .lastName(user.getLastName()) .password(user.getPassword()) .role(user.getRole()) .socialSignInProvider(user.getSignInProvider()) .username(user.getEmail()) .build(); LOGGER.debug("Logging in principal: {}", userDetails); Authentication authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); SecurityContextHolder.getContext().setAuthentication(authentication); LOGGER.info("User: {} has been logged in.", userDetails); }  static void logInUser(User user);  }### Answer:
@Test public void logInUser_UserRegisteredByUsingFormRegistration_ShouldAddUserDetailsToSecurityContext() { User user = new UserBuilder() .email(EMAIL) .firstName(FIRST_NAME) .id(ID) .lastName(LAST_NAME) .password(PASSWORD) .build(); SecurityUtil.logInUser(user); assertThat(SecurityContextHolder.getContext()) .loggedInUserIs(user) .loggedInUserHasPassword(PASSWORD) .loggedInUserIsRegisteredByUsingNormalRegistration(); }
@Test public void logInUser_UserSignInByUsingSocialSignInProvider_ShouldAddUserDetailsToSecurityContext() { User user = new UserBuilder() .email(EMAIL) .firstName(FIRST_NAME) .id(ID) .lastName(LAST_NAME) .signInProvider(SocialMediaService.TWITTER) .build(); SecurityUtil.logInUser(user); assertThat(SecurityContextHolder.getContext()) .loggedInUserIs(user) .loggedInUserIsSignedInByUsingSocialProvider(SocialMediaService.TWITTER); }