@Test(expectedExceptions = InvalidImageStateException.class)
 public void testNullImageSizeThrowsInvalidImageStateException() throws Throwable {
   AttachedDiskCreateSpec disk = new AttachedDiskCreateSpec();
   disk.setBootDisk(true);
   ImageEntity image = new ImageEntity();
   image.setSize(null);
   List<Throwable> warnings = new ArrayList<>();
   VmDcpBackend.updateBootDiskCapacity(Arrays.asList(disk), image, warnings);
 }
  /**
   * This method creates a VmCreateSpec object for creating an VM.
   *
   * @param vmState Supplies the state object of the VmService entity.
   * @param hostState Supplies the state object of the HostService entity.
   * @param imageState Supplies the state object of the ImageService entity.
   * @param vmFlavorState Supplies the state object of the FlavorService entity.
   * @param diskFlavorState Supplies the state object of the FlavorService entity.
   * @return Returns the VmCreateSpec object.
   */
  private VmCreateSpec composeVmCreateSpec(
      final VmService.State vmState,
      final HostService.State hostState,
      final ImageService.State imageState,
      final FlavorService.State vmFlavorState,
      final FlavorService.State diskFlavorState) {

    // Craft the VM creation spec.
    VmCreateSpec spec = new VmCreateSpec();
    spec.setName(vmState.name);
    spec.setFlavor(vmFlavorState.name);

    spec.setSourceImageId(ServiceUtils.getIDFromDocumentSelfLink(imageState.documentSelfLink));

    List<AttachedDiskCreateSpec> attachedDisks = new ArrayList<>();

    AttachedDiskCreateSpec bootDisk = new AttachedDiskCreateSpec();
    bootDisk.setName(vmState.name + "-bootdisk");
    bootDisk.setBootDisk(true);
    bootDisk.setFlavor(diskFlavorState.name);
    bootDisk.setKind(EphemeralDisk.KIND);
    attachedDisks.add(bootDisk);

    spec.setAttachedDisks(attachedDisks);

    Map<String, String> environment = new HashMap<>();
    spec.setEnvironment(environment);

    List<LocalitySpec> affinities = new ArrayList<>();

    LocalitySpec hostSpec = new LocalitySpec();
    hostSpec.setId(hostState.hostAddress);
    hostSpec.setKind("host");
    affinities.add(hostSpec);

    LocalitySpec datastoreSpec = new LocalitySpec();
    datastoreSpec.setId(
        hostState.metadata.get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_DATASTORE));
    datastoreSpec.setKind("datastore");
    affinities.add(datastoreSpec);

    LocalitySpec portGroupSpec = new LocalitySpec();
    portGroupSpec.setId(
        hostState.metadata.get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_PORTGROUP));
    portGroupSpec.setKind("portGroup");
    affinities.add(portGroupSpec);

    spec.setAffinities(affinities);

    return spec;
  }