### Question:
AadUserListUpdater { public void updateAadUserList() throws AzureUserFetchException, AzureApiException { String accessToken = this.azureApiCaller.getAccessToken(); Collection<AadUser> aadUserList = azureUserFetcher.fetchAzureUsers(accessToken); logger.info("Updating " + aadUserList.size() + " users..."); for (AadUser aadUser : aadUserList) { aadUser.setMail(aadUser.getMail().toLowerCase()); String photoAsBase64 = azurePhotoFetcher.getPhotoForUserId(accessToken, aadUser.getId()); aadUser.setPhoto(photoAsBase64); } this.updateUserList(aadUserList); } @Autowired  AadUserListUpdater(
      AzureUserFetcher azureUserFetcher,
      AadUserRepository aadUserRepository,
      AzurePhotoFetcher azurePhotoFetcher,
      AzureApiCaller azureApiCaller); void updateAadUserList();  }### Answer:
@Test public void testUpdateAadUserListShouldFetchUsers() throws AzureApiException, AzureUserFetchException { String accessToken = "testToken"; AadUser firstUser = new AadUser(); AadUser secondUser = new AadUser(); firstUser.setMail("test"); secondUser.setMail("test2"); when(azureApiCaller.getAccessToken()).thenReturn(accessToken); when(azureUserFetcher.fetchAzureUsers(accessToken)) .thenReturn(Arrays.asList(firstUser, secondUser)); aadUserListUpdater.updateAadUserList(); verify(azureApiCaller).getAccessToken(); verify(azureUserFetcher).fetchAzureUsers(accessToken); }
@Test public void testUpdateAadUserListShouldUpdateUsers() throws AzureApiException, AzureUserFetchException { final String accessToken = "testToken"; final AadUser updatingUser = new AadUser(); final String expectedNewEmail = "user1@test.mail"; updatingUser.setId(UUID.randomUUID()); updatingUser.setMail("test"); when(azureApiCaller.getAccessToken()).thenReturn(accessToken); when(azureUserFetcher.fetchAzureUsers(accessToken)) .thenReturn(Collections.singletonList(updateUserMail(updatingUser, expectedNewEmail))); aadUserListUpdater.updateAadUserList(); verify(azureApiCaller).getAccessToken(); verify(azureUserFetcher).fetchAzureUsers(accessToken); assertEquals(updatingUser.getMail(), expectedNewEmail); }
@Test public void testUpdateAadUserListShouldMailSetToLowerCase() throws AzureApiException, AzureUserFetchException { final String accessToken = "testToken"; final AadUser updatingUser = new AadUser(); final String expectedNewEmail = "user1@test.mail"; updatingUser.setId(UUID.randomUUID()); updatingUser.setMail("User1@Test.Mail"); when(azureApiCaller.getAccessToken()).thenReturn(accessToken); when(azureUserFetcher.fetchAzureUsers(accessToken)) .thenReturn(Collections.singletonList(updatingUser)); aadUserListUpdater.updateAadUserList(); verify(azureApiCaller).getAccessToken(); verify(azureUserFetcher).fetchAzureUsers(accessToken); assertEquals(updatingUser.getMail(), expectedNewEmail); }