### Question:
ValidGroupTagConstraint extends HardConstraint { @Override boolean isAssignmentValid(AssignableNode node, AssignableReplica replica, ClusterContext clusterContext) { if (!replica.hasResourceInstanceGroupTag()) { return true; } return node.getInstanceTags().contains(replica.getResourceInstanceGroupTag()); }    }### Answer:
@Test public void testConstraintValid() { when(_testReplica.hasResourceInstanceGroupTag()).thenReturn(true); when(_testReplica.getResourceInstanceGroupTag()).thenReturn(TEST_TAG); when(_testNode.getInstanceTags()).thenReturn(ImmutableSet.of(TEST_TAG)); Assert.assertTrue(_constraint.isAssignmentValid(_testNode, _testReplica, _clusterContext)); }
@Test public void testConstraintInValid() { when(_testReplica.hasResourceInstanceGroupTag()).thenReturn(true); when(_testReplica.getResourceInstanceGroupTag()).thenReturn(TEST_TAG); when(_testNode.getInstanceTags()).thenReturn(Collections.emptySet()); Assert.assertFalse(_constraint.isAssignmentValid(_testNode, _testReplica, _clusterContext)); }
@Test public void testConstraintWhenReplicaHasNoTag() { when(_testReplica.hasResourceInstanceGroupTag()).thenReturn(false); Assert.assertTrue(_constraint.isAssignmentValid(_testNode, _testReplica, _clusterContext)); }