@Override
  public void handle(final Callback[] callbacks)
      throws IOException, UnsupportedCallbackException {
    for (final Callback callback : callbacks) {
      if (callback instanceof NameCallback) {
        final NameCallback nc = (NameCallback) callback;
        nc.setName(getUserName());
      } else if (callback instanceof ObjectCallback) {
        final ObjectCallback oc = (ObjectCallback)callback;
        oc.setObject(getCredential());
      } else if (callback instanceof PasswordCallback) {
        final PasswordCallback pc = (PasswordCallback) callback;
        pc.setPassword(((String) getCredential()).toCharArray());
      } else if (callback instanceof TextOutputCallback) {
        final TextOutputCallback toc = (TextOutputCallback) callback;
        switch (toc.getMessageType()) {
          case TextOutputCallback.ERROR:
            log.error(toc.getMessage());
            break;
          case TextOutputCallback.WARNING:
            log.warn(toc.getMessage());
            break;
          case TextOutputCallback.INFORMATION:
            log.info(toc.getMessage());
            break;
          default:
            throw new IOException("Unsupported message type: " + toc.getMessageType());
        }
      } else {
        // We ignore unknown callback types - e.g. Jetty implementation might pass us Jetty specific
        // stuff which we can't deal with
      }
    }
  }
@Test
  public void shouldHandlePasswordCallback() throws Exception {
    // When:
    callbackHandler.handle(new Callback[]{nameCallback, passwordCallback});
    // Then:
    verify(nameCallback).setName(USERNAME);
    verify(passwordCallback).setPassword(PASSWORD.toCharArray());
  }