### Question:
SamePartitionOnInstanceConstraint extends HardConstraint { @Override boolean isAssignmentValid(AssignableNode node, AssignableReplica replica, ClusterContext clusterContext) { return !node.getAssignedPartitionsByResource(replica.getResourceName()) .contains(replica.getPartitionName()); }    }### Answer:
@Test public void testConstraintValid() { when(_testNode.getAssignedPartitionsByResource(TEST_RESOURCE)) .thenReturn(ImmutableSet.of("dummy")); when(_testReplica.getResourceName()).thenReturn(TEST_RESOURCE); when(_testReplica.getPartitionName()).thenReturn(TEST_PARTITIOIN); Assert.assertTrue(_constraint.isAssignmentValid(_testNode, _testReplica, _clusterContext)); }
@Test public void testConstraintInValid() { when(_testNode.getAssignedPartitionsByResource(TEST_RESOURCE)) .thenReturn(ImmutableSet.of(TEST_PARTITIOIN)); when(_testReplica.getResourceName()).thenReturn(TEST_RESOURCE); when(_testReplica.getPartitionName()).thenReturn(TEST_PARTITIOIN); Assert.assertFalse(_constraint.isAssignmentValid(_testNode, _testReplica, _clusterContext)); }