BindBlockDeviceMappingToIndexedFormParams implements Binder { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof Map, "this binder is only valid for Map"); Map<String, BlockDevice> blockDeviceMapping = (Map<String, BlockDevice>) input; Multimap<String, String> original = queryParser().apply(request.getPayload().getRawContent().toString()); ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder(); builder.putAll("Action", "ModifyInstanceAttribute"); int amazonOneBasedIndex = 1; for (Entry<String, BlockDevice> ebsBlockDeviceName : blockDeviceMapping.entrySet()) { builder.put(format(deviceNamePattern, amazonOneBasedIndex), ebsBlockDeviceName.getKey()); builder.put(format(deleteOnTerminationPattern, amazonOneBasedIndex), String.valueOf(ebsBlockDeviceName.getValue().isDeleteOnTermination())); builder.put(format(volumeIdPattern, amazonOneBasedIndex), ebsBlockDeviceName.getValue().getVolumeId()); amazonOneBasedIndex++; } builder.putAll("InstanceId", original.get("InstanceId")); request.setPayload(newUrlEncodedFormPayload(builder.build())); return request; }  @SuppressWarnings("unchecked") @Override R bindToRequest(R request, Object input);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testMustBeBlockDeviceMapping() { HttpRequest request = HttpRequest.builder().method("POST").endpoint("http: binder.bindToRequest(request, new File("foo")); }
@Test(expectedExceptions = NullPointerException.class) public void testNullIsBad() { HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: binder.bindToRequest(request, null); }