### Question:
Host extends AbstractPersistable { public HostUsage getUsage(List<Vm> vms) { int ncpusUsed = 0; int ramMbUsed = 0; int diskGbUsed = 0; for (Vm vm: vms) { if (this.equals(vm.getHost())) { ncpusUsed += vm.getNcpus(); ramMbUsed += vm.getRamMb(); diskGbUsed += vm.getDiskGb(); } } return new HostUsage(ncpusUsed, ramMbUsed, diskGbUsed); } Host(Long id, String hostname, int ncpus, double ramMb, double diskGb, boolean initiallyOff); HostUsage getUsage(List<Vm> vms); double getOverCapacityScore(List<Vm> vms); boolean missingFixedVMs(List<Vm> vms); String getHostname(); int getNcpus(); double getRamMb(); double getDiskGb(); void addFixedVm(long vmId); boolean wasOffInitiallly(); @Override String toString();  }### Answer:
@Test public void getUsage() { List<Vm> vms = new ArrayList<>(); Vm vm1 = new Vm.Builder((long) 1, 1, 1024, 1).build(); vm1.setHost(host); Vm vm2 = new Vm.Builder((long) 2, 2, 2048, 2).build(); vms.add(vm1); vms.add(vm2); HostUsage hostUsage = host.getUsage(vms); assertEquals(1, hostUsage.getNcpusUsed()); assertEquals(1024, hostUsage.getRamMbUsed()); assertEquals(1, hostUsage.getDiskGbUsed()); }