### Question:
FaultZoneAwareConstraint extends HardConstraint { @Override boolean isAssignmentValid(AssignableNode node, AssignableReplica replica, ClusterContext clusterContext) { if (!node.hasFaultZone()) { return true; } return !clusterContext .getPartitionsForResourceAndFaultZone(replica.getResourceName(), node.getFaultZone()) .contains(replica.getPartitionName()); }    }### Answer:
@Test public void inValidWhenFaultZoneAlreadyAssigned() { when(_testNode.hasFaultZone()).thenReturn(true); when(_clusterContext.getPartitionsForResourceAndFaultZone(TEST_RESOURCE, TEST_ZONE)).thenReturn( ImmutableSet.of(TEST_PARTITION)); Assert.assertFalse( _faultZoneAwareConstraint.isAssignmentValid(_testNode, _testReplica, _clusterContext)); }
@Test public void validWhenEmptyAssignment() { when(_testNode.hasFaultZone()).thenReturn(true); when(_clusterContext.getPartitionsForResourceAndFaultZone(TEST_RESOURCE, TEST_ZONE)).thenReturn(Collections.emptySet()); Assert.assertTrue( _faultZoneAwareConstraint.isAssignmentValid(_testNode, _testReplica, _clusterContext)); }
@Test public void validWhenNoFaultZone() { when(_testNode.hasFaultZone()).thenReturn(false); Assert.assertTrue( _faultZoneAwareConstraint.isAssignmentValid(_testNode, _testReplica, _clusterContext)); }