### Question:
ParseCredentialsFromJsonResponse implements
      Function<HttpResponse, Credentials> { @Override public Credentials apply(HttpResponse input) { Map<String, Credentials> returnVal = parser.apply(input); checkState(!(returnVal.size() > 1), "expecting only 1 credential in response, but had more: " + returnVal.keySet()); return (!returnVal.isEmpty()) ? Iterables.getOnlyElement(returnVal.values()) : null; } @Inject  ParseCredentialsFromJsonResponse(
         ParseServerNameToCredentialsMapFromJsonResponse parser); @Override Credentials apply(HttpResponse input);  }### Answer:
@Test(expectedExceptions = IllegalStateException.class) public void testFailWhenTooManyPasswords() throws UnknownHostException { InputStream is = getClass().getResourceAsStream("/test_credentials_list.json"); HttpResponse response = HttpResponse.builder().statusCode(200).message("ok").payload(is).build(); ParseCredentialsFromJsonResponse parser = i.getInstance(ParseCredentialsFromJsonResponse.class); parser.apply(response); }
@Test public void testValid() throws UnknownHostException { InputStream is = getClass().getResourceAsStream("/test_credential.json"); HttpResponse response = HttpResponse.builder().statusCode(200).message("ok").payload(is).build(); ParseCredentialsFromJsonResponse parser = i.getInstance(ParseCredentialsFromJsonResponse.class); Credentials creds = parser.apply(response); assertEquals(creds.identity, "root"); assertEquals(creds.credential, "zot40ced"); }