@Test
public void updateUserDataDeletesAllAndSavesNew() {

    // given
    var firstUserId = "first-user";
    var expectedFirstDepartment = "first-department";
    var expectedFirstDivision = "first-division";
    var expectedFirstGivenName = "first-given-name";
    var expectedFirstSurname = "first-surname";
    var expectedFirstName = "first-full-name";
    var expectedFirstMail = "first@mail.com";
    var secondUserId = "second-user";
    var expectedSecondDepartment = "second-department";
    var expectedSecondDivision = "second-division";
    var expectedSecondGivenName = "second-given-name";
    var expectedSecondSurname = "second-surname";
    var expectedSecondName = "second-full-name";
    var expectedSecondMail = "second@mail.com";
    var firstUser = new User(firstUserId);
    var secondUser = new User(secondUserId);
    var firstNode = new LdapUserNode()
            .setId(firstUserId)
            .setDepartment(expectedFirstDepartment)
            .setDivision(expectedFirstDivision)
            .setGivenName(expectedFirstGivenName)
            .setSurname(expectedFirstSurname)
            .setName(expectedFirstName)
            .setMail(expectedFirstMail);
    var secondNode = new LdapUserNode()
            .setId(secondUserId)
            .setDepartment(expectedSecondDepartment)
            .setDivision(expectedSecondDivision)
            .setGivenName(expectedSecondGivenName)
            .setSurname(expectedSecondSurname)
            .setName(expectedSecondName)
            .setMail(expectedSecondMail);
    var firstExpected = new UserData(firstUser, expectedFirstGivenName, expectedFirstSurname, expectedFirstMail, expectedFirstDivision);
    var secondExpected = new UserData(secondUser, expectedSecondGivenName, expectedSecondSurname, expectedSecondMail, expectedSecondDivision);
    given(repoUserServiceMock.getOrCreateUserById(firstUserId)).willReturn(firstUser);
    given(repoUserServiceMock.getOrCreateUserById(secondUserId)).willReturn(secondUser);
    given(normalizerMock.normalize(List.of(firstExpected, secondExpected))).willReturn(List.of(firstExpected, secondExpected));
    // when
    userUpdater.updateUserData(List.of(firstNode, secondNode));
    // then
    verify(userDataRepoMock).deleteAll();
    verify(userDataRepoMock).flush();
    verify(userDataRepoMock).saveAll(userDataCaptor.capture());
    verify(normalizerMock).normalize(List.of(firstExpected, secondExpected));
    assertThat(userDataCaptor.getValue()).containsExactlyInAnyOrder(firstExpected, secondExpected);
}