public <T extends Notification> int deliverEmails(Collection<T> notifications) {
    if (handlers.isEmpty()) {
      return 0;
    }

    Class<T> aClass = typeClassOf(notifications);
    if (aClass == null) {
      return 0;
    }

    checkArgument(aClass != Notification.class, "Type of notification objects must be a subtype of " + Notification.class.getSimpleName());
    return handlers.stream()
      .filter(t -> t.getNotificationClass() == aClass)
      .map(t -> (NotificationHandler<T>) t)
      .mapToInt(handler -> handler.deliver(notifications))
      .sum();
  }
@Test
  public void deliverEmails_collection_returns_0_if_collection_is_empty() {
    NotificationHandler<Notification1> handler1 = getMockOfNotificationHandlerForType(Notification1.class);
    NotificationHandler<Notification2> handler2 = getMockOfNotificationHandlerForType(Notification2.class);
    NotificationService underTest = new NotificationService(dbClient,
      new NotificationHandler[]{handler1, handler2});

    assertThat(underTest.deliverEmails(Collections.emptyList())).isZero();
    verifyNoInteractions(handler1, handler2);
  }