private PlayerProfile setupUpdateEmailAddress(String emailAddress) {
   PlayerProfile userProfile = getUserProfile();
   when(lobbySessionCache.getActiveSession(request)).thenReturn(getLobbySession(userProfile));
   PlayerProfile finalUserProfile = getUserProfileWithEmailAddress(emailAddress);
   when(lobbySessionCache.getActiveSession(request)).thenReturn(getLobbySession(finalUserProfile));
   when(playerProfileService.findByPlayerId(userProfile.getPlayerId()))
       .thenReturn(finalUserProfile);
   return finalUserProfile;
 }
 private PlayerProfile setupUpdateDisplayName(String displayName) {
   PlayerProfile userProfile = getUserProfile();
   when(lobbySessionCache.getActiveSession(request)).thenReturn(getLobbySession(userProfile));
   PlayerProfile finalUserProfile = getUserProfileWithDisplayName(displayName);
   when(lobbySessionCache.getActiveSession(request)).thenReturn(getLobbySession(finalUserProfile));
   when(playerProfileService.findByPlayerId(userProfile.getPlayerId()))
       .thenReturn(finalUserProfile);
   return finalUserProfile;
 }
  private LobbySession getVerifiedSession(final HttpServletRequest request)
      throws RequestException {
    final LobbySession activeSession = lobbySessionCache.getActiveSession(request);

    if (activeSession == null) {
      LOG.warn("PaymentController could not load session for player {}", request);
      throw new RequestException(HttpStatus.UNAUTHORIZED.value(), "no session");
    }
    return activeSession;
  }
  private PlayerProfile setUpUserProfileInfo(
      final String avatarUrl,
      final String gender,
      final String country,
      final DateTime dateOfBirth) {

    PlayerProfile userProfile = getUserProfile();
    when(lobbySessionCache.getActiveSession(request)).thenReturn(getLobbySession(userProfile));
    PlayerProfile finalUserProfile =
        PlayerProfile.copy(userProfile)
            .withGender(Gender.getById(gender))
            .withCountry(country)
            .withDateOfBirth(dateOfBirth)
            .asProfile();

    when(lobbySessionCache.getActiveSession(request)).thenReturn(getLobbySession(finalUserProfile));
    when(playerProfileService.findByPlayerId(userProfile.getPlayerId()))
        .thenReturn(finalUserProfile);
    return finalUserProfile;
  }
  @Before
  public void setUp() throws IOException {
    underTest =
        new CreditCardAPIPaymentController(
            webApiResponses, json, lobbySessionCache, creditCardService, logoutHelper);

    when(request.isSecure()).thenReturn(true);
    when(request.getRemoteAddr()).thenReturn("10.9.8.11");
    when(request.getSession()).thenReturn(session);
    final Cookie[] cookies = new Cookie[0];
    when(request.getCookies()).thenReturn(cookies);
    when(lobbySessionCache.getActiveSession(request)).thenReturn(aLobbySession());
  }
  @RequestMapping({
    "/lobby/inviteFriends/FACEBOOK",
    "/lobby/inviteFacebookFriends",
    "/friends/inviteFromFacebook"
  })
  public String inviteFriends(final ModelMap model, final HttpServletRequest request) {
    final LobbySession lobbySession = lobbySessionCache.getActiveSession(request);
    notNull(lobbySession, "No session found");

    model.addAttribute("referringPlayerId", lobbySession.getPlayerId());
    final String[] toExclude = getIdsToExcludeFromInvitations(lobbySession.getPlayerId());
    model.addAttribute("excludedFriendIds", StringUtils.join(toExclude, ","));
    model.addAttribute("source", "FACEBOOK_FORM");

    return "facebookInviteFriend";
  }
  @RequestMapping({
    "/inviteFriendsViaFacebook",
    "/lobby/inviteFriendsViaFacebook",
    "/friends/inviteViaFacebook"
  })
  public String inviteFriendsViaFacebook(
      final ModelMap model,
      final HttpServletRequest request,
      @RequestParam(value = "source", required = false) final String source,
      @RequestParam(value = "targetFriendId", required = false) final String targetFriendId) {
    final LobbySession lobbySession = lobbySessionCache.getActiveSession(request);
    notNull(lobbySession, "No session found");

    model.addAttribute("referringPlayerId", lobbySession.getPlayerId());
    final String[] toExclude = getIdsToExcludeFromInvitations(lobbySession.getPlayerId());
    model.addAttribute("excludedFriendIds", StringUtils.join(toExclude, ","));
    model.addAttribute("source", source);
    LOG.info("TARGET FRIEND ID = " + targetFriendId);
    model.addAttribute("targetFriendId", targetFriendId);

    model.addAttribute("inviteMessage", getInvitationTextForGameType(source));

    return "partials/inviteFriendsViaFacebook";
  }
 private BigDecimal findIssuingPlayerId(final HttpServletRequest request) {
   final LobbySession lobbySession = lobbySessionCache.getActiveSession(request);
   return lobbySession.getPlayerId();
 }
 private PlayerProfile setUpPlayerProfile() {
   PlayerProfile userProfile = getUserProfile();
   when(lobbySessionCache.getActiveSession(request)).thenReturn(getLobbySession(userProfile));
   when(playerProfileService.findByPlayerId(userProfile.getPlayerId())).thenReturn(userProfile);
   return userProfile;
 }