ProductOrderToJson implements Binder { @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkNotNull(input, "order"); ProductOrder order = ProductOrder.class.cast(input); request.setPayload(buildJson(order)); return request; } @Inject  ProductOrderToJson(Json json); @Override R bindToRequest(R request, Object input);  }
@Test(expectedExceptions = NullPointerException.class) public void testNullOrder() { binder.bindToRequest(request, null); }
@Test public void testCorrect() { ProductItemPrice price1 = ProductItemPrice.builder().id(100).build(); ProductItemPrice price2 = ProductItemPrice.builder().id(101).build(); VirtualGuest guest = VirtualGuest.builder().hostname("myhost") .domain("mydomain") .build(); ProductOrder order = ProductOrder.builder() .packageId(123) .location("loc456") .quantity(99) .useHourlyPricing(true) .prices(ImmutableSet.of(price1,price2)) .virtualGuests(guest) .build(); String expected = String.format(FORMAT.replaceAll("'","\""), 123,"loc456",100,101,"myhost","mydomain",99,true); HttpRequest req = binder.bindToRequest(request, order); assertEquals(req.getPayload().getRawContent(), expected); }