### Question:
FakeCloudMiddleware implements CloudMiddleware { @Override public void migrate(String vmId, String destinationNodeHostName) { VmDeployed vmToMigrate = getVmById(vmId); if (vmToMigrate != null) { HostFake oldHost = getHost(vmToMigrate.getHostName()); HostFake newHost = getHost(destinationNodeHostName); if (newHost != null) { vmToMigrate.setHostName(destinationNodeHostName); oldHost.updateAssignedResourcesAfterVmDeleted(vmToMigrate); newHost.updateAssignedResourcesAfterVmDeployed(vmToMigrate); } } } FakeCloudMiddleware(List<HostFake> hosts); @Override String deploy(Vm vm, String hostname); @Override String deployWithVolume(Vm vm, String hostname, String isoPath); @Override void destroy(String vmId); @Override void migrate(String vmId, String destinationNodeHostName); @Override List<String> getAllVMsIds(); @Override List<String> getScheduledNonDeployedVmsIds(); @Override VmDeployed getVM(String vmId); @Override boolean existsVm(String vmId); @Override void rebootHardVm(String vmId); @Override void rebootSoftVm(String vmId); @Override void startVm(String vmId); @Override void stopVm(String vmId); @Override void suspendVm(String vmId); @Override void resumeVm(String vmId); @Override List<ImageUploaded> getVmImages(); @Override String createVmImage(ImageToUpload imageToUpload); @Override ImageUploaded getVmImage(String imageId); @Override void deleteVmImage(String id); @Override void assignFloatingIp(String vmId); void deleteAllVmImages(); HostFake getHost(String hostname); void addHost(HostFake host); @Override Map<String, String> getFlavours(); @Override void resize(String vmId, VmRequirements vm); @Override void confirmResize(String vmId); @Override Map<String, HardwareInfo> getHypervisors(String region); @Override Host createHost(String hostname);  }### Answer:
@Test public void migrate() { String newImageId = fakeCloudMiddleware.createVmImage(new ImageToUpload("newImage", "fakeUrl")); String idDeployedVm = fakeCloudMiddleware.deploy(new Vm("testVm", newImageId, 1, 1024, 1, null, null), "host1"); fakeCloudMiddleware.migrate(idDeployedVm, "host2"); Assert.assertEquals("host2", fakeCloudMiddleware.getVM(idDeployedVm).getHostName()); HostFake oldHost = fakeCloudMiddleware.getHost("host1"); Assert.assertTrue(oldHost.getAssignedCpus() == 0); Assert.assertTrue(oldHost.getAssignedMemoryMb() == 0); Assert.assertTrue(oldHost.getAssignedDiskGb() == 0); HostFake newHost = fakeCloudMiddleware.getHost("host2"); Assert.assertTrue(newHost.getAssignedCpus() == 1); Assert.assertTrue(newHost.getAssignedMemoryMb() == 1024); Assert.assertTrue(newHost.getAssignedDiskGb() == 1); }
@Test public void migrateNonExistingVmDoesNothingAndDoesNotRaiseException() { fakeCloudMiddleware.migrate("NonExistingVm", "host1"); }