HostResourcesService { protected void calculateHostResourcesAllocated(HostResources host) { List<VmResources> vmsFromHost = host.getVmsResources(); long usedCpu = 0; long usedMemory = 0; for (VmResources vm : vmsFromHost) { usedMemory += vm.getMemoryInMegaBytes(); usedCpu += vm.getCpuSpeed() * vm.getNumberOfCpus(); } host.setUsedCpu(usedCpu); host.setUsedMemoryInMegaBytes(usedMemory); }  HostResources createAndConfigureHostResources(HostVO hostVo); HostResources createHostResources(HostVO hostVO);  }
@Test public void calculateHostResourcesAllocatedTest() { HostResources hostResources = new HostResources(); hostResourcesUtils.createHostWithSmallVms(hostResources, 1); hostResourcesService.calculateHostResourcesAllocated(hostResources); Assert.assertEquals(512l, hostResources.getUsedMemoryInMegaBytes()); Assert.assertEquals(1000l, hostResources.getUsedCpu()); }