@Test
 public void validateCurrentUserPassword() throws DatabaseException {
   MolgenisUser existingMolgenisUser = mock(MolgenisUser.class);
   when(existingMolgenisUser.getId()).thenReturn(1);
   when(existingMolgenisUser.getPassword()).thenReturn("encrypted-password");
   when(existingMolgenisUser.getUsername()).thenReturn("username");
   when(passwordEncoder.matches("password", "encrypted-password")).thenReturn(true);
   assertTrue(userAccountServiceImpl.validateCurrentUserPassword("password"));
   assertFalse(userAccountServiceImpl.validateCurrentUserPassword("wrong-password"));
 }
  @Test
  public void getCurrentUser() throws DatabaseException {
    when(authentication.getPrincipal()).thenReturn(USERNAME_USER);

    MolgenisUser existingMolgenisUser = mock(MolgenisUser.class);
    when(molgenisUserService.getUser(USERNAME_USER)).thenReturn(existingMolgenisUser);
    assertEquals(userAccountServiceImpl.getCurrentUser(), existingMolgenisUser);
  }
  @Test(expectedExceptions = RuntimeException.class)
  public void updateCurrentUser_wrongUser() throws DatabaseException {
    MolgenisUser existingMolgenisUser = mock(MolgenisUser.class);
    when(existingMolgenisUser.getId()).thenReturn(1);
    when(existingMolgenisUser.getPassword()).thenReturn("encrypted-password");

    when(molgenisUserService.getUser(USERNAME_USER)).thenReturn(existingMolgenisUser);

    MolgenisUser updatedMolgenisUser = mock(MolgenisUser.class);
    when(updatedMolgenisUser.getId()).thenReturn(1);
    when(updatedMolgenisUser.getUsername()).thenReturn("wrong-username");
    when(updatedMolgenisUser.getPassword()).thenReturn("encrypted-password");

    userAccountServiceImpl.updateCurrentUser(updatedMolgenisUser);
  }
  @Test
  public void updateCurrentUser() {
    MolgenisUser existingMolgenisUser = mock(MolgenisUser.class);
    when(existingMolgenisUser.getId()).thenReturn(1);
    when(existingMolgenisUser.getUsername()).thenReturn(USERNAME_USER);
    when(existingMolgenisUser.getPassword()).thenReturn("encrypted-password");

    when(molgenisUserService.getUser(USERNAME_USER)).thenReturn(existingMolgenisUser);

    MolgenisUser updatedMolgenisUser = mock(MolgenisUser.class);
    when(updatedMolgenisUser.getId()).thenReturn(1);
    when(updatedMolgenisUser.getUsername()).thenReturn("username");
    when(updatedMolgenisUser.getPassword()).thenReturn("encrypted-password");

    userAccountServiceImpl.updateCurrentUser(updatedMolgenisUser);
    verify(passwordEncoder, never()).encode("encrypted-password");
  }
  @Test
  public void updateCurrentUser_changePassword() throws DatabaseException {
    when(passwordEncoder.matches("new-password", "encrypted-password")).thenReturn(true);
    MolgenisUser existingMolgenisUser = mock(MolgenisUser.class);
    when(existingMolgenisUser.getId()).thenReturn(1);
    when(existingMolgenisUser.getPassword()).thenReturn("encrypted-password");
    when(existingMolgenisUser.getUsername()).thenReturn("username");

    when(molgenisUserService.getUser(USERNAME_USER)).thenReturn(existingMolgenisUser);

    MolgenisUser updatedMolgenisUser = mock(MolgenisUser.class);
    when(updatedMolgenisUser.getId()).thenReturn(1);
    when(updatedMolgenisUser.getPassword()).thenReturn("new-password");
    when(updatedMolgenisUser.getUsername()).thenReturn("username");

    userAccountServiceImpl.updateCurrentUser(updatedMolgenisUser);
    verify(passwordEncoder, times(1)).encode("new-password");
  }