### Question:
NodeCapacityConstraint extends HardConstraint { @Override boolean isAssignmentValid(AssignableNode node, AssignableReplica replica, ClusterContext clusterContext) { Map<String, Integer> nodeCapacity = node.getRemainingCapacity(); Map<String, Integer> replicaCapacity = replica.getCapacity(); for (String key : replicaCapacity.keySet()) { if (nodeCapacity.containsKey(key)) { if (nodeCapacity.get(key) < replicaCapacity.get(key)) { return false; } } } return true; }    }### Answer:
@Test public void testConstraintValidWhenNodeHasEnoughSpace() { String key = "testKey"; when(_testNode.getRemainingCapacity()).thenReturn(ImmutableMap.of(key, 10)); when(_testReplica.getCapacity()).thenReturn(ImmutableMap.of(key, 5)); Assert.assertTrue(_constraint.isAssignmentValid(_testNode, _testReplica, _clusterContext)); }
@Test public void testConstraintInValidWhenNodeHasInsufficientSpace() { String key = "testKey"; when(_testNode.getRemainingCapacity()).thenReturn(ImmutableMap.of(key, 1)); when(_testReplica.getCapacity()).thenReturn(ImmutableMap.of(key, 5)); Assert.assertFalse(_constraint.isAssignmentValid(_testNode, _testReplica, _clusterContext)); }