@Test
public void testGetUserAuthorityExpiry() {

    Role role = new Role().setUserAuthorityExpiration("elevated-clearance");
    Authority savedAuthority = zms.userAuthority;
    zms.userAuthority = null;
    // with authority null we always get null
    assertNull(zms.getUserAuthorityExpiry("user.john", role.getUserAuthorityExpiration(), "unit-test"));
    Authority authority = Mockito.mock(Authority.class);
    Mockito.when(authority.getDateAttribute("user.john", "elevated-clearance"))
            .thenReturn(new Date());
    Mockito.when(authority.getDateAttribute("user.joe", "elevated-clearance"))
            .thenReturn(null);
    zms.userAuthority = authority;
    assertNotNull(zms.getUserAuthorityExpiry("user.john", role.getUserAuthorityExpiration(), "unit-test"));
    try {
        zms.getUserAuthorityExpiry("user.joe", role.getUserAuthorityExpiration(), "unit-test");
        fail();
    } catch (ResourceException ex) {
        assertTrue(ex.getMessage().contains("User does not have required user authority expiry configured"));
    }
    zms.userAuthority = savedAuthority;
}