@Test
public void testUserTokenWithInvalidAuthorizedService() throws CryptoException {

    long issueTime = System.currentTimeMillis() / 1000;
    // Create and sign token
    List<String> authorizedServices = new ArrayList<>();
    authorizedServices.add("coretech.storage");
    PrincipalToken userTokenToSign = new PrincipalToken.Builder(usrVersion, usrDomain, usrName)
        .salt(salt).issueTime(issueTime).expirationWindow(expirationTime)
        .authorizedServices(authorizedServices).build();
    userTokenToSign.sign(servicePrivateKeyStringK0);
    // now let's sign the token for an authorized service. we must get
    // back illegal argument exception because of service name mismatch
    try {
        userTokenToSign.signForAuthorizedService("weather.storage", "0", servicePrivateKeyStringK0);
        fail();
    } catch (Exception ex) {
        assertEquals(ex.getClass(), IllegalArgumentException.class);
    }
    authorizedServices.add("media.storage");
    PrincipalToken userTokenToSign2 = new PrincipalToken.Builder(usrVersion, usrDomain, usrName)
        .salt(salt).issueTime(issueTime).expirationWindow(expirationTime)
        .authorizedServices(authorizedServices).build();
    userTokenToSign2.sign(servicePrivateKeyStringK0);
    // now let's sign the token for an authorized service. we must get
    // back illegal argument exception because of service name mismatch
    try {
        userTokenToSign2.signForAuthorizedService("weather.storage", "0", servicePrivateKeyStringK0);
        fail();
    } catch (Exception ex) {
        assertEquals(ex.getClass(), IllegalArgumentException.class);
    }
}