HostCapacity { public NodeResources freeCapacityOf(Node host) { return freeCapacityOf(host, false); } HostCapacity(NodeList allNodes, HostResourcesCalculator hostResourcesCalculator); NodeList allNodes(); Set<Node> findSpareHosts(List<Node> candidates, int count); NodeResources freeCapacityOf(Node host);  }
@Test public void freeCapacityOf() { assertEquals(new NodeResources(5, 40, 80, 2, NodeResources.DiskSpeed.fast, NodeResources.StorageType.remote), capacity.freeCapacityOf(host1, false)); assertEquals(new NodeResources(5, 60, 80, 4.5, NodeResources.DiskSpeed.fast, NodeResources.StorageType.remote), capacity.freeCapacityOf(host3, false)); doAnswer(invocation -> { NodeResources totalHostResources = ((Flavor) invocation.getArguments()[0]).resources(); return totalHostResources.subtract(new NodeResources(1, 2, 3, 0.5, NodeResources.DiskSpeed.any)); }).when(hostResourcesCalculator).advertisedResourcesOf(any()); assertEquals(new NodeResources(4, 38, 77, 1.5, NodeResources.DiskSpeed.fast, NodeResources.StorageType.remote), capacity.freeCapacityOf(host1, false)); assertEquals(new NodeResources(4, 58, 77, 4, NodeResources.DiskSpeed.fast, NodeResources.StorageType.remote), capacity.freeCapacityOf(host3, false)); }