BindToJsonPayloadWrappedWith implements MapBinder { @Override public <R extends HttpRequest> R bindToRequest(R request, Object payload) { return jsonBinder.bindToRequest(request, (Object) ImmutableMap.of(envelope, checkNotNull(payload, "payload"))); } @Inject  BindToJsonPayloadWrappedWith(BindToJsonPayload jsonBinder, @Assisted String envelope); @Override R bindToRequest(R request, Object payload); @Override R bindToRequest(R request, Map<String, Object> postParams);  }
@Test public void testCorrect() throws SecurityException, NoSuchMethodException { BindToJsonPayloadWrappedWith binder = new BindToJsonPayloadWrappedWith(injector .getInstance(BindToJsonPayload.class), "envelope"); HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: request = binder.bindToRequest(request, ImmutableMap.of("imageName", "foo", "serverId", "2")); assertEquals(request.getPayload().getRawContent(), "{\"envelope\":{\"imageName\":\"foo\",\"serverId\":\"2\"}}"); }
@Test public void testFactoryCorrect() throws SecurityException, NoSuchMethodException { BindToJsonPayloadWrappedWith binder = injector.getInstance(BindToJsonPayloadWrappedWith.Factory.class).create( "envelope"); HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: request = binder.bindToRequest(request, ImmutableMap.of("imageName", "foo", "serverId", "2")); assertEquals(request.getPayload().getRawContent(), "{\"envelope\":{\"imageName\":\"foo\",\"serverId\":\"2\"}}"); }
@Test(expectedExceptions = NullPointerException.class) public void testNullIsBad() { BindToJsonPayloadWrappedWith binder = new BindToJsonPayloadWrappedWith(injector .getInstance(BindToJsonPayload.class), "envelope"); binder.bindToRequest(HttpRequest.builder().method("GET").endpoint("http: }