@Test
public void testAuthenticateSuccess() throws Exception {

    Headers respHeader = new Headers();
    final Subject subject = new Subject();
    HttpExchange ex = createHttpExchange(respHeader, subject, "Authorization", "Basic cm9sYW5kOnMhY3IhdA==");
    JaasAuthenticator successAuth = new JaasAuthenticator("jolokia") {
        @Override
        protected LoginContext createLoginContext(String realm, CallbackHandler handler) throws LoginException {
            LoginContext mockLogin = EasyMock.mock(LoginContext.class);
            mockLogin.login();
            expect(mockLogin.getSubject()).andReturn(subject);
            EasyMock.replay(mockLogin);
            return mockLogin;
        }
    };
    Authenticator.Result result = successAuth.authenticate(ex);
    HttpPrincipal principal = ((Authenticator.Success) result).getPrincipal();
    assertEquals(principal.getRealm(),"jolokia");
    assertEquals(principal.getUsername(),"roland");
}