### Question:
NamePasswordCallbackHandler implements CallbackHandler { public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (int i = 0; i < callbacks.length; i++) { Callback callback = callbacks[i]; if (handleCallback(callback)) { continue; } else if (callback instanceof NameCallback) { ((NameCallback) callback).setName(username); } else if (callback instanceof PasswordCallback) { PasswordCallback pwCallback = (PasswordCallback) callback; pwCallback.setPassword(password.toCharArray()); } else if (!invokePasswordCallback(callback)) { org.apache.cxf.common.i18n.Message errorMsg = new org.apache.cxf.common.i18n.Message("UNSUPPORTED_CALLBACK_TYPE", BUNDLE, callbacks[i].getClass().getName()); LOG.info(errorMsg.toString()); throw new UnsupportedCallbackException(callbacks[i], errorMsg.toString()); } } } NamePasswordCallbackHandler(String username, String password);  NamePasswordCallbackHandler(String username, String password, String passwordCallbackName); void handle(Callback[] callbacks);  }### Answer:
@Test public void testHandleCallback2() throws Exception { NamePasswordCallbackHandler handler = new NamePasswordCallbackHandler("Barry", "dog"); Callback[] callbacks = new Callback[]{new NameCallback("name"), new ObjectCallback()}; handler.handle(callbacks); assertEquals("Barry", ((NameCallback)callbacks[0]).getName()); Object pwobj = ((ObjectCallback)callbacks[1]).getObject(); assertTrue(pwobj instanceof char[]); assertEquals("dog", new String((char[])pwobj)); }
@Test public void testHandleCallback3() throws Exception { NamePasswordCallbackHandler handler = new NamePasswordCallbackHandler("Barry", "dog"); Callback[] callbacks = new Callback[]{new NameCallback("name"), new StringObjectCallback()}; handler.handle(callbacks); assertEquals("Barry", ((NameCallback)callbacks[0]).getName()); assertEquals("dog", ((StringObjectCallback)callbacks[1]).getObject()); }
@Test public void testHandleCallback4() throws Exception { NamePasswordCallbackHandler handler = new NamePasswordCallbackHandler("Barry", "dog", "setValue"); Callback[] callbacks = new Callback[]{new NameCallback("name"), new CharArrayCallback()}; handler.handle(callbacks); assertEquals("Barry", ((NameCallback)callbacks[0]).getName()); assertEquals("dog", new String(((CharArrayCallback)callbacks[1]).getValue())); }