public void sendNotifications() {
    if (!emailComposer.areEmailSettingsSet()) {
      LOG.debug("Emails for token expiration notification have not been sent because email settings are not configured.");
      return;
    }
    try (var dbSession = dbClient.openSession(false)) {
      var expiringTokens = dbClient.userTokenDao().selectTokensExpiredInDays(dbSession, 7);
      var expiredTokens = dbClient.userTokenDao().selectTokensExpiredInDays(dbSession, 0);
      var tokensToNotify = Stream.concat(expiringTokens.stream(), expiredTokens.stream()).toList();
      var usersToNotify = tokensToNotify.stream().map(UserTokenDto::getUserUuid).collect(Collectors.toSet());
      Map<String, String> userUuidToEmail = dbClient.userDao().selectByUuids(dbSession, usersToNotify).stream()
        .collect(Collectors.toMap(UserDto::getUuid, UserDto::getEmail));
      tokensToNotify.stream().map(token -> new TokenExpirationEmail(userUuidToEmail.get(token.getUserUuid()), token)).forEach(emailComposer::send);
    }
  }
@Test
  public void send_notification() {
    var expiringToken = new UserTokenDto().setUserUuid("admin");
    var expiredToken = new UserTokenDto().setUserUuid("admin");
    var user = mock(UserDto.class);
    when(user.getUuid()).thenReturn("admin");
    when(user.getEmail()).thenReturn("admin@admin.com");
    var userTokenDao = mock(UserTokenDao.class);
    var userDao = mock(UserDao.class);
    when(userDao.selectByUuids(any(), any())).thenReturn(List.of(user));
    when(userTokenDao.selectTokensExpiredInDays(any(), eq(7L))).thenReturn(List.of(expiringToken));
    when(userTokenDao.selectTokensExpiredInDays(any(), eq(0L))).thenReturn(List.of(expiredToken));
    when(dbClient.userTokenDao()).thenReturn(userTokenDao);
    when(dbClient.userDao()).thenReturn(userDao);
    when(emailComposer.areEmailSettingsSet()).thenReturn(true);

    underTest.sendNotifications();

    var argumentCaptor = ArgumentCaptor.forClass(TokenExpirationEmail.class);
    verify(emailComposer, times(2)).send(argumentCaptor.capture());
    List<TokenExpirationEmail> emails = argumentCaptor.getAllValues();
    assertThat(emails).hasSize(2);
    assertThat(emails.get(0).getRecipients()).containsOnly("admin@admin.com");
    assertThat(emails.get(0).getUserToken()).isEqualTo(expiringToken);
    assertThat(emails.get(1).getRecipients()).containsOnly("admin@admin.com");
    assertThat(emails.get(1).getUserToken()).isEqualTo(expiredToken);
  }