@Test
  public void shouldReturnDefaultFormOnErrorWhenAvatarHasAnInvalidExtension() throws Exception {
    setUpPlayerProfile();
    MultipartFile multipartFile = mock(MultipartFile.class);
    when(multipartFile.getBytes()).thenReturn("file".getBytes());
    when(multipartFile.getOriginalFilename()).thenReturn("aFile.pdf");
    when(avatarRepository.storeAvatar("aFile.pdf", "file".getBytes()))
        .thenThrow(new IllegalArgumentException("Invalid extension"));

    assertMainProfilePageViewName(
        underTest.updateUserAvatar(request, response, false, multipartFile, modelMap));
    assertThat((String) modelMap.get("avatarHasErrors"), is(equalTo("true")));
  }
  @Test
  public void shouldClearPlayerProfileCacheOnAvatarUpdate() throws Exception {
    final PlayerProfile playerProfile = setUpPlayerProfile();

    final MultipartFile multipartFile = mock(MultipartFile.class);
    final String expectedOriginalFilename = "WORD";
    final byte[] expectedBytes = expectedOriginalFilename.getBytes();

    when(multipartFile.getBytes()).thenReturn(expectedBytes);
    when(multipartFile.getOriginalFilename()).thenReturn(expectedOriginalFilename);

    when(avatarRepository.storeAvatar(expectedOriginalFilename, expectedBytes))
        .thenReturn(new Avatar("one", "two"));

    underTest.updateUserAvatar(request, response, true, multipartFile, modelMap);

    verify(playerProfileCacheRemovalListener).playerUpdated(playerProfile.getPlayerId());
  }
  @Test
  public void shouldUpdateAvatarUrl() throws Exception {
    PlayerProfile userProfile = setUpPlayerProfile();

    MultipartFile multipartFile = mock(MultipartFile.class);
    String expectedOriginalFilename = "WORD";
    byte[] expectedBytes = expectedOriginalFilename.getBytes();

    when(multipartFile.getBytes()).thenReturn(expectedBytes);
    when(multipartFile.getOriginalFilename()).thenReturn(expectedOriginalFilename);

    Avatar expectedAvatar = new Avatar("one", "two");
    when(avatarRepository.storeAvatar(expectedOriginalFilename, expectedBytes))
        .thenReturn(expectedAvatar);

    underTest.updateUserAvatar(request, response, false, multipartFile, modelMap);

    verify(playerProfileService).updateAvatar(userProfile.getPlayerId(), expectedAvatar);
  }