@Test
public void testSendGroupMemberExpiryReminders() {

    DBService dbsvc = Mockito.mock(DBService.class);
    NotificationService mockNotificationService =  Mockito.mock(NotificationService.class);
    NotificationServiceFactory testfact = () -> mockNotificationService;
    List<GroupMember> memberGroups = new ArrayList<>();
    memberGroups.add(new GroupMember().setGroupName("group1")
            .setDomainName("athenz1")
            .setMemberName("user.joe")
            .setExpiration(Timestamp.fromMillis(100)));
    DomainGroupMember domainGroupMember = new DomainGroupMember()
            .setMemberName("user.joe")
            .setMemberGroups(memberGroups);
    Map<String, DomainGroupMember> expiryMembers = new HashMap<>();
    expiryMembers.put("user.joe", domainGroupMember);
    // we're going to return null for our first thread which will
    // run during init call and then the real data for the second
    // call
    Mockito.when(dbsvc.getGroupExpiryMembers(1))
            .thenReturn(null)
            .thenReturn(expiryMembers);
    NotificationManager notificationManager = getNotificationManager(dbsvc, testfact);
    ZMSTestUtils.sleep(1000);
    AthenzDomain domain = new AthenzDomain("athenz1");
    List<RoleMember> roleMembers = new ArrayList<>();
    roleMembers.add(new RoleMember().setMemberName("user.jane"));
    Role adminRole = new Role().setName("athenz1:role.admin").setRoleMembers(roleMembers);
    List<Role> roles = new ArrayList<>();
    roles.add(adminRole);
    domain.setRoles(roles);
    Mockito.when(dbsvc.getRolesByDomain("athenz1")).thenReturn(domain.getRoles());
    List<Notification> notifications = new GroupMemberExpiryNotificationTask(dbsvc, USER_DOMAIN_PREFIX)
            .getNotifications();
    // we should get 2 notifications - one for user and one for domain
    assertEquals(notifications.size(), 2);
    // Verify contents of notifications is as expected
    Notification expectedFirstNotification = new Notification();
    expectedFirstNotification.addRecipient("user.joe");
    expectedFirstNotification.addDetails(NOTIFICATION_DETAILS_ROLES_LIST, "athenz1;group1;1970-01-01T00:00:00.100Z");
    expectedFirstNotification.addDetails("member", "user.joe");
    expectedFirstNotification.setNotificationToEmailConverter(new GroupMemberExpiryNotificationTask.GroupExpiryPrincipalNotificationToEmailConverter());
    expectedFirstNotification.setType("group_membership_expiry");
    Notification expectedSecondNotification = new Notification();
    expectedSecondNotification.addRecipient("user.jane");
    expectedSecondNotification.addDetails(NOTIFICATION_DETAILS_MEMBERS_LIST, "user.joe;group1;1970-01-01T00:00:00.100Z");
    expectedSecondNotification.addDetails("domain", "athenz1");
    expectedSecondNotification.setNotificationToEmailConverter(new GroupMemberExpiryNotificationTask.GroupExpiryDomainNotificationToEmailConverter());
    expectedSecondNotification.setType("group_membership_expiry");
    assertEquals(notifications.get(0), expectedFirstNotification);
    assertEquals(notifications.get(1), expectedSecondNotification);
    notificationManager.shutdown();
}