@Test
public void testValidHosts() {

    Date currentDate = new Date();
    List<X509CertRecord> records = new ArrayList<>();
    System.setProperty(ZTS_PROP_NOTIFICATION_CERT_FAIL_PROVIDER_LIST, "provider");
    // Create 6 mock records. Only even records host are valid
    boolean isValidHost = true;
    for (int i = 0; i < 6; ++i) {
        X509CertRecord record = getMockX509CertRecord(currentDate, i);
        records.add(record);
        NotificationTestsCommon.mockDomainData(i, dataStore);
        Mockito.when(hostnameResolver.isValidHostname(eq("hostName" + i))).thenReturn(isValidHost);
        isValidHost = !isValidHost;
    }
    // Make a 7th record with no host (but make it valid)
    X509CertRecord record = getMockX509CertRecord(currentDate, 7);
    record.setHostName(null);
    records.add(record);
    NotificationTestsCommon.mockDomainData(7, dataStore);
    Mockito.when(hostnameResolver.isValidHostname(eq(null))).thenReturn(true);
    Mockito.when(instanceCertManager.getUnrefreshedCertsNotifications(eq(serverName), anyString())).thenReturn(records);
    CertFailedRefreshNotificationTask certFailedRefreshNotificationTask = new CertFailedRefreshNotificationTask(
            instanceCertManager,
            dataStore,
            hostnameResolver,
            userDomainPrefix,
            serverName,
            httpsPort);
    List<Notification> notifications = certFailedRefreshNotificationTask.getNotifications();
    assertEquals(4, notifications.size());
    assertEquals("domain7", notifications.get(0).getDetails().get("domain"));
    assertEquals("domain4", notifications.get(1).getDetails().get("domain"));
    assertEquals("domain2", notifications.get(2).getDetails().get("domain"));
    assertEquals("domain0", notifications.get(3).getDetails().get("domain"));
    System.clearProperty(ZTS_PROP_NOTIFICATION_CERT_FAIL_PROVIDER_LIST);
}