public boolean hasProjectSubscribersForTypes(String projectUuid, Set<Class<? extends Notification>> notificationTypes) {
    Set<String> dispatcherKeys = handlers.stream()
      .filter(handler -> notificationTypes.stream().anyMatch(notificationType -> handler.getNotificationClass() == notificationType))
      .map(NotificationHandler::getMetadata)
      .filter(Optional::isPresent)
      .map(Optional::get)
      .map(NotificationDispatcherMetadata::getDispatcherKey)
      .collect(Collectors.toSet());

    return dbClient.propertiesDao().hasProjectNotificationSubscribersForDispatchers(projectUuid, dispatcherKeys);
  }
@Test
  public void hasProjectSubscribersForType_checks_property_for_each_dispatcher_key_supporting_Notification_type() {
    String dispatcherKey1A = randomAlphabetic(5);
    String dispatcherKey1B = randomAlphabetic(6);
    String projectUuid = randomAlphabetic(7);

    NotificationHandler<Notification1> handler1A = getMockOfNotificationHandlerForType(Notification1.class);
    when(handler1A.getMetadata()).thenReturn(Optional.of(NotificationDispatcherMetadata.create(dispatcherKey1A)));

    NotificationHandler<Notification1> handler1B = getMockOfNotificationHandlerForType(Notification1.class);
    when(handler1B.getMetadata()).thenReturn(Optional.of(NotificationDispatcherMetadata.create(dispatcherKey1B)));

    NotificationHandler<Notification2> handler2 = getMockOfNotificationHandlerForType(Notification2.class);
    when(handler2.getMetadata()).thenReturn(Optional.empty());

    boolean expected = true;
    when(propertiesDao.hasProjectNotificationSubscribersForDispatchers(projectUuid, ImmutableSet.of(dispatcherKey1A, dispatcherKey1B)))
      .thenReturn(expected);
    NotificationService underTest = new NotificationService(dbClient, new NotificationHandler[]{handler1A, handler1B, handler2});

    boolean flag = underTest.hasProjectSubscribersForTypes(projectUuid, ImmutableSet.of(Notification1.class));

    verify(propertiesDao).hasProjectNotificationSubscribersForDispatchers(projectUuid, ImmutableSet.of(dispatcherKey1A, dispatcherKey1B));
    verifyNoMoreInteractions(propertiesDao);
    assertThat(flag).isEqualTo(expected);

    flag = underTest.hasProjectSubscribersForTypes(projectUuid, ImmutableSet.of(Notification1.class, Notification2.class));

    verify(propertiesDao, times(2)).hasProjectNotificationSubscribersForDispatchers(projectUuid, ImmutableSet.of(dispatcherKey1A, dispatcherKey1B));
    verifyNoMoreInteractions(propertiesDao);
    assertThat(flag).isEqualTo(expected);
  }