### Question:
VirtualGuestToJson implements Binder { @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(input instanceof VirtualGuest); VirtualGuest virtualGuest = VirtualGuest.class.cast(checkNotNull(input, "input")); request.setPayload(buildJson(virtualGuest)); return request; } @Inject  VirtualGuestToJson(Json json); @Override R bindToRequest(R request, Object input); static final String USER_DATA_KEY; }### Answer:
@Test public void testVirtualGuestWithOperatingSystem() { HttpRequest request = HttpRequest.builder().method("POST").endpoint("https: VirtualGuestToJson binder = new VirtualGuestToJson(json); VirtualGuest virtualGuestWithOS = VirtualGuest.builder() .hostname("hostname") .domain("domain") .startCpus(1) .maxMemory(1024) .datacenter(Datacenter.builder() .name("datacenterName") .build()) .operatingSystem(OperatingSystem.builder().id("123456789") .operatingSystemReferenceCode("UBUNTU_12_64") .build()) .localDiskFlag(true) .networkComponents(ImmutableSet.<VirtualGuestNetworkComponent>of()) .build(); request = binder.bindToRequest(request, virtualGuestWithOS); assertEquals(request.getPayload().getRawContent(), "{" + "\"parameters\":[{\"hostname\":\"hostname\",\"domain\":\"domain\",\"startCpus\":1,\"maxMemory\":1024,\"hourlyBillingFlag\":false,\"localDiskFlag\":true,\"dedicatedAccountHostOnlyFlag\":false,\"privateNetworkOnlyFlag\":false,\"operatingSystemReferenceCode\":\"UBUNTU_12_64\",\"datacenter\":{\"name\":\"datacenterName\"}}]}"); }
@Test public void testVirtualGuestWithVirtualGuestBlockDeviceTemplateGroup() { HttpRequest request = HttpRequest.builder().method("POST").endpoint("https: VirtualGuestToJson binder = new VirtualGuestToJson(json); VirtualGuest virtualGuestWithVirtualGuestBlockDeviceTemplateGroup = VirtualGuest.builder() .hostname("hostname") .domain("domain") .startCpus(1) .maxMemory(1024) .datacenter(Datacenter.builder() .name("datacenterName") .build()) .blockDeviceTemplateGroup(VirtualGuestBlockDeviceTemplateGroup.builder() .globalIdentifier("ffaafa98-4b4a-4fa7-b9f7-b1bad5ec50f0") .build()) .localDiskFlag(true) .networkComponents(ImmutableSet.<VirtualGuestNetworkComponent>of()) .build(); request = binder.bindToRequest(request, virtualGuestWithVirtualGuestBlockDeviceTemplateGroup); assertEquals(request.getPayload().getRawContent(), "{" + "\"parameters\":[{" + "\"hostname\":\"hostname\"," + "\"domain\":\"domain\"," + "\"startCpus\":1," + "\"maxMemory\":1024," + "\"hourlyBillingFlag\":false," + "\"localDiskFlag\":true," + "\"dedicatedAccountHostOnlyFlag\":false," + "\"privateNetworkOnlyFlag\":false," + "\"blockDeviceTemplateGroup\":{\"globalIdentifier\":\"ffaafa98-4b4a-4fa7-b9f7-b1bad5ec50f0\"}," + "\"datacenter\":{\"name\":\"datacenterName\"}}]}"); }