ConsolidationScoredPreferenceForSmallHosts extends ConsolidationAlgorithmBase { protected double calculateHostScore(HostResources host) { HostProfile hostProfile = profiler.hostVMsResourceProportion(host); return hostProfile.getCpuSpeedProfile() * hostProfile.getCpusProfile() * hostProfile.getMemoryProfile(); }  @Override List<HostResources> rankHosts(List<HostResources> hostsList); @Override List<HostResources> rankHostToPowerOff(List<HostResources> idleHosts);  }
@Test public void calculateHostScoreTest() { List<HostResources> hosts = createHosts(); HostProfile hostProfile = Mockito.mock(HostProfile.class); Mockito.when(hostProfile.getCpuSpeedProfile()).thenReturn(5.0); Mockito.when(hostProfile.getCpusProfile()).thenReturn(2.0); Mockito.when(hostProfile.getMemoryProfile()).thenReturn(1.0); HostProfiler spyProfiler = Mockito.spy(new HostProfiler(hosts)); spyAlgorithm.profiler = spyProfiler; Mockito.doReturn(hostProfile).when(spyProfiler).hostVMsResourceProportion(Mockito.any(HostResources.class)); double result = spyAlgorithm.calculateHostScore(hosts.get(0)); Assert.assertEquals(10.0, result, 0.0); Mockito.verify(spyProfiler).hostVMsResourceProportion(Mockito.any(HostResources.class)); Mockito.verify(hostProfile).getCpuSpeedProfile(); Mockito.verify(hostProfile).getCpusProfile(); Mockito.verify(hostProfile).getMemoryProfile(); }