@Test
public void test() throws Exception {

    // Mock REST client
    final User user = new User();
    user.setEnabled(true);
    user.setGroups(ImmutableSet.of("designers", "operators"));
    user.setSystemName("dladmin");
    final JerseyRestClient client = Mockito.mock(JerseyRestClient.class);
    Mockito.when(client.get(any(Invocation.Builder.class), eq(User.class))).thenReturn(user);
    // Mock callback handler
    final CallbackHandler callbackHandler = callbacks -> Arrays.stream(callbacks).forEach(callback -> {
        if (callback instanceof NameCallback) {
            ((NameCallback) callback).setName("dladmin");
        } else if (callback instanceof PasswordCallback) {
            ((PasswordCallback) callback).setPassword("thinkbig".toCharArray());
        }
    });
    // Mock login module
    final KyloRestLoginModule module = new KyloRestLoginModule() {
        @Nonnull
        @Override
        JerseyRestClient getClient(@Nonnull LoginJerseyClientConfig config) {
            return client;
        }
    };
    // Test login
    final Subject subject = new Subject();
    Map<String, Object> options = new HashMap<>();
    options.put(KyloRestLoginModule.REST_CLIENT_CONFIG, new LoginJerseyClientConfig());
    options.put(KyloRestLoginModule.SERVICES_LOGOUT, false);
    
    module.initialize(subject, callbackHandler, Collections.emptyMap(), options);
    Assert.assertTrue(module.login());
    Assert.assertTrue(module.commit());
    // Verify subject
    final Principal[] principals = subject.getPrincipals().toArray(new Principal[0]);
    Assert.assertEquals(3, principals.length);
    Arrays.sort(principals, Comparator.comparing(Principal::getName));
    Assert.assertEquals("designers", principals[0].getName());
    Assert.assertEquals("dladmin", principals[1].getName());
    Assert.assertEquals("operators", principals[2].getName());
}