@Test
public void testUpdateGroupMemberUserAuthorityExpiry() {

    Group group = new Group().setUserAuthorityExpiration("elevated-clearance");
    List<GroupMember> members = new ArrayList<>();
    members.add(new GroupMember().setMemberName("user.john"));
    members.add(new GroupMember().setMemberName("user.joe"));
    group.setGroupMembers(members);
    Authority savedAuthority = zms.userAuthority;
    zms.userAuthority = null;
    // with authority null we always get no changes
    zms.updateGroupMemberUserAuthorityExpiry(group, "unit-test");
    assertNull(group.getGroupMembers().get(0).getExpiration());
    assertNull(group.getGroupMembers().get(1).getExpiration());
    Authority authority = Mockito.mock(Authority.class);
    Mockito.when(authority.getDateAttribute("user.john", "elevated-clearance"))
            .thenReturn(new Date());
    Mockito.when(authority.getDateAttribute("user.jane", "elevated-clearance"))
            .thenReturn(new Date());
    Mockito.when(authority.getDateAttribute("user.joe", "elevated-clearance"))
            .thenReturn(null);
    zms.userAuthority = authority;
    // with one valid and one invalid we should get an exception
    try {
        zms.updateGroupMemberUserAuthorityExpiry(group, "unit-test");
        fail();
    } catch (ResourceException ex) {
        assertTrue(ex.getMessage().contains("Invalid member: user.joe"));
    }
    // let's have one valid user and one service
    members = new ArrayList<>();
    members.add(new GroupMember().setMemberName("user.john"));
    members.add(new GroupMember().setMemberName("sports.api"));
    group.setGroupMembers(members);
    // the user will have an expiration while service is skipped
    zms.updateGroupMemberUserAuthorityExpiry(group, "unit-test");
    assertNotNull(group.getGroupMembers().get(0).getExpiration());
    assertNull(group.getGroupMembers().get(1).getExpiration());
    // now let's have only user members
    members = new ArrayList<>();
    members.add(new GroupMember().setMemberName("user.john"));
    members.add(new GroupMember().setMemberName("user.jane"));
    group.setGroupMembers(members);
    zms.updateGroupMemberUserAuthorityExpiry(group, "unit-test");
    assertNotNull(group.getGroupMembers().get(0).getExpiration());
    assertNotNull(group.getGroupMembers().get(1).getExpiration());
    zms.userAuthority = savedAuthority;
}