### Question:
NodeMaxPartitionLimitConstraint extends HardConstraint { @Override boolean isAssignmentValid(AssignableNode node, AssignableReplica replica, ClusterContext clusterContext) { boolean exceedMaxPartitionLimit = node.getMaxPartition() < 0 || node.getAssignedReplicaCount() < node.getMaxPartition(); boolean exceedResourceMaxPartitionLimit = replica.getResourceMaxPartitionsPerInstance() < 0 || node.getAssignedPartitionsByResource(replica.getResourceName()).size() < replica .getResourceMaxPartitionsPerInstance(); return exceedMaxPartitionLimit && exceedResourceMaxPartitionLimit; }    }### Answer:
@Test public void testConstraintValid() { when(_testNode.getAssignedReplicaCount()).thenReturn(0); when(_testNode.getMaxPartition()).thenReturn(10); when(_testNode.getAssignedPartitionsByResource(TEST_RESOURCE)) .thenReturn(Collections.emptySet()); when(_testReplica.getResourceMaxPartitionsPerInstance()).thenReturn(5); Assert.assertTrue(_constraint.isAssignmentValid(_testNode, _testReplica, _clusterContext)); }
@Test public void testConstraintInvalid() { when(_testNode.getAssignedReplicaCount()).thenReturn(10); when(_testNode.getMaxPartition()).thenReturn(5); Assert.assertFalse(_constraint.isAssignmentValid(_testNode, _testReplica, _clusterContext)); }