ClusterManagementDummyAlgorithm implements ClusterAdministrationHeuristicAlgorithm { protected List<HostResources> cloneListOfHosts(List<HostResources> hosts) { List<HostResources> clonedHostList = new ArrayList<>(); for (HostResources host : hosts) { try { HostResources clonedHost = (HostResources) host.clone(); clonedHost.setVmsResources(cloneHostVmsList(host)); clonedHostList.add(clonedHost); } catch (CloneNotSupportedException e) { logger.error("Problems while clonning objects", e); } } return clonedHostList; }  @Override int getClusterIntervalBetweenConsolidation(); @Override List<HostResources> rankHosts(List<HostResources> hosts); @Override Map<Long, HostResources> mapVMsToHost(List<HostResources> rankedHosts); @Override List<HostResources> rankHostToPowerOff(List<HostResources> idleHosts); @Override boolean canPowerOffHost(HostResources hostToPowerOff, CloudResources cloudResources); @Override boolean canPowerOffAnotherHostInCloud(CloudResources cloudResources); @Override boolean canHeuristicShutdownHosts();  }
@Test public void cloneListOfHostsTest() { VmResources vm1Host1 = new VmResources(0, 0, 0, 0); List<VmResources> vmsHost = new ArrayList<VmResources>(); vmsHost.add(vm1Host1); HostResources host = new HostResources(); host.setHostId(1l); host.setVmsResources(vmsHost); List<HostResources> hosts = new ArrayList<HostResources>(); hosts.add(host); List<HostResources> clonedHosts = spyAlgorithm.cloneListOfHosts(hosts); Assert.assertNotNull(clonedHosts); Assert.assertEquals(hosts.size(), clonedHosts.size()); Assert.assertNotEquals(hosts, clonedHosts); HostResources clonedHost = clonedHosts.get(0); Assert.assertNotNull(clonedHost); Assert.assertEquals(host.getHostId(), clonedHost.getHostId()); Assert.assertNotEquals(host, clonedHost); Assert.assertNotNull(clonedHost.getVmsResources()); Assert.assertEquals(vmsHost.size(), clonedHost.getVmsResources().size()); Assert.assertEquals(vmsHost.get(0), clonedHost.getVmsResources().get(0)); Mockito.verify(spyAlgorithm).cloneHostVmsList(host); }