@Test
 public void shouldOnUpdateDisplayNameNotUpdateAnythingIfErrors() {
   DisplayName expectedDisplayName = new DisplayName("Super Cool New Name");
   setUpPlayerProfile();
   when(bindingResult.hasErrors()).thenReturn(true);
   underTest.updateDisplayName(
       request, response, false, expectedDisplayName, bindingResult, modelMap);
   verifyNoUpdatesDone();
 }
 @Test
 public void shouldOnErrorsForDisplayNameReturnPlayerObjectAgain() {
   DisplayName expectedDisplayName = new DisplayName("Super Cool New Name");
   PlayerProfile expectedUserProfile = setUpPlayerProfile();
   when(bindingResult.hasErrors()).thenReturn(true);
   underTest.updateDisplayName(
       request, response, false, expectedDisplayName, bindingResult, modelMap);
   assertModelMapContainsPlayerObject(expectedUserProfile);
 }
 @Test
 public void shouldOnErrorsForDisplayNameReturnMainFormAgain() {
   DisplayName expectedDisplayName = new DisplayName("Super Cool New Name");
   setUpPlayerProfile();
   when(bindingResult.hasErrors()).thenReturn(true);
   assertMainProfilePageViewName(
       underTest.updateDisplayName(
           request, response, false, expectedDisplayName, bindingResult, modelMap));
 }
 @Test
 public void shouldOnUpdateDisplayNameReturnCorrectPartialValue() {
   DisplayName expectedDisplayName = new DisplayName("Super Cool New Name");
   setUpPlayerProfile();
   when(bindingResult.hasErrors()).thenReturn(false);
   ModelAndView modelAndView =
       underTest.updateDisplayName(
           request, response, true, expectedDisplayName, bindingResult, modelMap);
   assertTrue(((RedirectView) modelAndView.getView()).getUrl().endsWith("?partial=true"));
 }
  @Test
  public void shouldUpdateDisplayNameForUserAndRedirectToOriginalForm() {
    DisplayName expectedDisplayName = new DisplayName("Super Cool New Name");
    setupUpdateDisplayName(expectedDisplayName.getDisplayName());

    assertRedirectToMainProfilePage(
        underTest.updateDisplayName(
            request, response, false, expectedDisplayName, bindingResult, modelMap));
    assertModelMapIsEmptyToAvoidQueryStringOnRedirect(modelMap);
  }
  @Test
  public void shouldClearPlayerProfileCacheOnUpdateOfDisplayNameForUser() {
    final DisplayName expectedDisplayName = new DisplayName("Super Cool New Name");
    final PlayerProfile userProfile = setupUpdateDisplayName(expectedDisplayName.getDisplayName());

    underTest.updateDisplayName(
        request, response, false, expectedDisplayName, bindingResult, modelMap);

    verify(playerProfileCacheRemovalListener).playerUpdated(userProfile.getPlayerId());
  }
  @Test
  public void shouldUpdateDisplayNameForUser() {
    DisplayName expectedDisplayName = new DisplayName("Super Cool New Name");
    PlayerProfile userProfile = setupUpdateDisplayName(expectedDisplayName.getDisplayName());

    underTest.updateDisplayName(
        request, response, false, expectedDisplayName, bindingResult, modelMap);

    verify(playerProfileService)
        .updateDisplayName(userProfile.getPlayerId(), expectedDisplayName.getDisplayName());
  }