### Question:
ResourcePartitionAntiAffinityConstraint extends UsageSoftConstraint { @Override protected double getAssignmentScore(AssignableNode node, AssignableReplica replica, ClusterContext clusterContext) { String resource = replica.getResourceName(); int curPartitionCountForResource = node.getAssignedPartitionsByResource(resource).size(); int estimatedMaxPartitionCountForResource = clusterContext.getEstimatedMaxPartitionByResource(resource); return computeUtilizationScore(estimatedMaxPartitionCountForResource, curPartitionCountForResource); }    }### Answer:
@Test public void testGetAssignmentScore() { when(_testReplica.getResourceName()).thenReturn(TEST_RESOURCE); when(_testNode.getAssignedPartitionsByResource(TEST_RESOURCE)).thenReturn( ImmutableSet.of(TEST_PARTITION + "1", TEST_PARTITION + "2", TEST_PARTITION + "3")); when(_clusterContext.getEstimatedMaxPartitionByResource(TEST_RESOURCE)).thenReturn(10); double score = _constraint.getAssignmentScore(_testNode, _testReplica, _clusterContext); double normalizedScore = _constraint.getAssignmentNormalizedScore(_testNode, _testReplica, _clusterContext); Assert.assertEquals(score, 0.3); Assert.assertTrue(normalizedScore > 0.99); }
@Test public void testGetAssignmentScoreMaxScore() { when(_testReplica.getResourceName()).thenReturn(TEST_RESOURCE); when(_testNode.getAssignedPartitionsByResource(TEST_RESOURCE)).thenReturn(Collections.emptySet()); when(_clusterContext.getEstimatedMaxPartitionByResource(TEST_RESOURCE)).thenReturn(10); double score = _constraint.getAssignmentScore(_testNode, _testReplica, _clusterContext); double normalizedScore = _constraint.getAssignmentNormalizedScore(_testNode, _testReplica, _clusterContext); Assert.assertEquals(score, 0.0); Assert.assertEquals(normalizedScore, 1.0); }