### Question:
AWSRunInstancesOptions extends RunInstancesOptions { @Override public AWSRunInstancesOptions withBlockDeviceMappings(Set<? extends BlockDeviceMapping> mappings) { launchSpecificationBuilder.blockDeviceMappings(mappings); return AWSRunInstancesOptions.class.cast(super.withBlockDeviceMappings(mappings)); }  AWSRunInstancesOptions inPlacementGroup(String placementGroup); AWSRunInstancesOptions withTenancy(Tenancy tenancy); AWSRunInstancesOptions withDedicatedHostId(String hostId); AWSRunInstancesOptions enableMonitoring(); AWSRunInstancesOptions withSubnetId(String subnetId); AWSRunInstancesOptions withSecurityGroupId(String securityGroup); AWSRunInstancesOptions withSecurityGroupIds(Iterable<String> securityGroupIds); AWSRunInstancesOptions withSecurityGroupIds(String... securityGroupIds); @SinceApiVersion("2012-06-01") AWSRunInstancesOptions withIAMInstanceProfileArn(String arn); @SinceApiVersion("2012-06-01") AWSRunInstancesOptions withIAMInstanceProfileName(String name); AWSRunInstancesOptions withPrivateIpAddress(String address); @Override AWSRunInstancesOptions withBlockDeviceMappings(Set<? extends BlockDeviceMapping> mappings); @Override AWSRunInstancesOptions withKernelId(String kernelId); @Override AWSRunInstancesOptions withKeyName(String keyName); @Override AWSRunInstancesOptions withRamdisk(String ramDiskId); @Override AWSRunInstancesOptions withSecurityGroup(String securityGroup); @Override AWSRunInstancesOptions withSecurityGroups(Iterable<String> securityGroups); @Override AWSRunInstancesOptions withSecurityGroups(String... securityGroups); @Override AWSRunInstancesOptions withUserData(byte[] unencodedData); @Override AWSRunInstancesOptions asType(String type); synchronized LaunchSpecification.Builder getLaunchSpecificationBuilder(); static final AWSRunInstancesOptions NONE; }### Answer:
@Test public void testWithBlockDeviceMapping() { BlockDeviceMapping mapping = new BlockDeviceMapping.MapNewVolumeToDevice("/dev/sda1", 120, true, "gp2", 10, true); AWSRunInstancesOptions options = new AWSRunInstancesOptions().withBlockDeviceMappings(ImmutableSet .<BlockDeviceMapping> of(mapping)); assertEquals(options.buildFormParameters().get("BlockDeviceMapping.1.DeviceName"), ImmutableList.of("/dev/sda1")); assertEquals(options.buildFormParameters().get("BlockDeviceMapping.1.Ebs.VolumeSize"), ImmutableList.of("120")); assertEquals(options.buildFormParameters().get("BlockDeviceMapping.1.Ebs.DeleteOnTermination"), ImmutableList.of("true")); assertEquals(options.buildFormParameters().get("BlockDeviceMapping.1.Ebs.VolumeType"), ImmutableList.of("gp2")); assertEquals(options.buildFormParameters().get("BlockDeviceMapping.1.Ebs.Iops"), ImmutableList.of("10")); assertEquals(options.buildFormParameters().get("BlockDeviceMapping.1.Ebs.Encrypted"), ImmutableList.of("true")); }
@Test public void testWithBlockDeviceMappingStatic() { BlockDeviceMapping mapping = new BlockDeviceMapping.MapNewVolumeToDevice("/dev/sda1", 120, true, null, null, false); AWSRunInstancesOptions options = withBlockDeviceMappings(ImmutableSet.<BlockDeviceMapping> of(mapping)); assertEquals(options.buildFormParameters().get("BlockDeviceMapping.1.DeviceName"), ImmutableList.of("/dev/sda1")); assertEquals(options.buildFormParameters().get("BlockDeviceMapping.1.Ebs.VolumeSize"), ImmutableList.of("120")); assertEquals(options.buildFormParameters().get("BlockDeviceMapping.1.Ebs.DeleteOnTermination"), ImmutableList.of("true")); }
@Test(expectedExceptions = NullPointerException.class) public void testWithBlockDeviceMappingNPE() { withBlockDeviceMappings(null); }