UserPasswordAuthenticator extends BasicAuthenticator { public boolean checkCredentials(String pUserGiven, String pPasswordGiven) { return user.equals(pUserGiven) && password.equals(pPasswordGiven); } UserPasswordAuthenticator(String pRealm, String pUser, String pPassword); boolean checkCredentials(String pUserGiven, String pPasswordGiven); @Override Result authenticate(HttpExchange httpExchange);  }
@Test public void testCheckCredentials() throws Exception { UserPasswordAuthenticator auth = new UserPasswordAuthenticator("jolokia","roland","s!cr!t"); assertTrue(auth.checkCredentials("roland","s!cr!t")); assertFalse(auth.checkCredentials("roland", "bla")); assertFalse(auth.checkCredentials(null, "bla")); assertFalse(auth.checkCredentials("roland", null)); assertFalse(auth.checkCredentials(null, null)); }