@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"); }
@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; }
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; } }
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); }
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); }
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);  }