@Test
public void testExpiryPrincipalGetNotificationDetails() {

    DBService dbsvc = Mockito.mock(DBService.class);
    RoleMemberNotificationCommon roleMemberNotificationCommon = new RoleMemberNotificationCommon(dbsvc, USER_DOMAIN_PREFIX);
    // Verify no details for member without member roles
    DomainRoleMember roleMember = new DomainRoleMember();
    roleMember.setMemberName("user.joe");
    Map<String, DomainRoleMember> members = new HashMap<>();
    members.put("user.joe", roleMember);
    List<Notification> notification = roleMemberNotificationCommon.getNotificationDetails(
            members,
            new RoleMemberExpiryNotificationTask.RoleExpiryPrincipalNotificationToEmailConverter(),
            new RoleMemberExpiryNotificationTask.RoleExpiryDomainNotificationToEmailConverter(),
            new RoleMemberExpiryNotificationTask.ExpiryRoleMemberDetailStringer(),
            "testNotification");
    assertEquals(1, notification.size());
    assertTrue(notification.get(0).getDetails().isEmpty());
    assertEquals(notification.get(0).getType(), "testNotification");
    // Verify the same result when setting the memberRoles to an empty collection
    roleMember.setMemberRoles(Collections.emptyList());
    notification = roleMemberNotificationCommon.getNotificationDetails(
            members,
            new RoleMemberExpiryNotificationTask.RoleExpiryPrincipalNotificationToEmailConverter(),
            new RoleMemberExpiryNotificationTask.RoleExpiryDomainNotificationToEmailConverter(),
            new RoleMemberExpiryNotificationTask.ExpiryRoleMemberDetailStringer(),
            "testNotification");
    assertEquals(1, notification.size());
    assertTrue(notification.get(0).getDetails().isEmpty());
    assertEquals(notification.get(0).getType(), "testNotification");
    final Timestamp expirationTs = Timestamp.fromMillis(100);
    final Timestamp reviewTs = Timestamp.fromMillis(50);
    List<MemberRole> memberRoles = new ArrayList<>();
    memberRoles.add(new MemberRole().setRoleName("role1").setDomainName("athenz1").setMemberName("user.joe")
            .setExpiration(expirationTs).setReviewReminder(reviewTs));
    roleMember.setMemberRoles(memberRoles);
    notification = roleMemberNotificationCommon.getNotificationDetails(
            members,
            new RoleMemberExpiryNotificationTask.RoleExpiryPrincipalNotificationToEmailConverter(),
            new RoleMemberExpiryNotificationTask.RoleExpiryDomainNotificationToEmailConverter(),
            new RoleMemberExpiryNotificationTask.ExpiryRoleMemberDetailStringer(),
            "testNotification");
    assertEquals(1, notification.size());
    assertEquals(2, notification.get(0).getDetails().size());
    assertEquals(notification.get(0).getType(), "testNotification");
    assertEquals(notification.get(0).getDetails().get(NOTIFICATION_DETAILS_ROLES_LIST),
            "athenz1;role1;" + expirationTs);
    assertEquals(notification.get(0).getDetails().get(NOTIFICATION_DETAILS_MEMBER), "user.joe");
    memberRoles.add(new MemberRole().setRoleName("role1").setDomainName("athenz2").setMemberName("user.joe")
            .setExpiration(expirationTs).setReviewReminder(reviewTs));
    memberRoles.add(new MemberRole().setRoleName("role2").setDomainName("athenz2").setMemberName("user.joe")
            .setExpiration(expirationTs).setReviewReminder(reviewTs));
    notification = roleMemberNotificationCommon.getNotificationDetails(
            members,
            new RoleMemberExpiryNotificationTask.RoleExpiryPrincipalNotificationToEmailConverter(),
            new RoleMemberExpiryNotificationTask.RoleExpiryDomainNotificationToEmailConverter(),
            new RoleMemberExpiryNotificationTask.ExpiryRoleMemberDetailStringer(),
            "testNotification");
    assertEquals(notification.get(0).getType(), "testNotification");
    assertEquals(1, notification.size());
    assertEquals(2, notification.get(0).getDetails().size());
    assertEquals(notification.get(0).getDetails().get(NOTIFICATION_DETAILS_ROLES_LIST),
            "athenz1;role1;" + expirationTs + "|athenz2;role1;" + expirationTs + "|athenz2;role2;" + expirationTs);
    assertEquals(notification.get(0).getDetails().get(NOTIFICATION_DETAILS_MEMBER), "user.joe");
    assertEquals(notification.get(0).getDetails().get(NOTIFICATION_DETAILS_ROLES_LIST),
            "athenz1;role1;" + expirationTs + "|athenz2;role1;" + expirationTs + "|athenz2;role2;" + expirationTs);
}