### Question:
AssignableReplica implements Comparable<AssignableReplica> { public Map<String, Integer> getCapacity() { return _capacityUsage; } AssignableReplica(ClusterConfig clusterConfig, ResourceConfig resourceConfig,
      String partitionName, String replicaState, int statePriority); Map<String, Integer> getCapacity(); String getPartitionName(); String getReplicaState(); boolean isReplicaTopState(); int getStatePriority(); String getResourceName(); String getResourceInstanceGroupTag(); boolean hasResourceInstanceGroupTag(); int getResourceMaxPartitionsPerInstance(); @Override String toString(); @Override int compareTo(AssignableReplica replica); @Override boolean equals(Object obj); static String generateReplicaKey(String resourceName, String partitionName, String state);  }### Answer:
@Test public void testDefaultPartitionWeight() { Map<String, Integer> defaultWeightDataMapResource = new HashMap<>(); defaultWeightDataMapResource.put("item1", 3); defaultWeightDataMapResource.put("item2", 6); ClusterConfig testClusterConfig = new ClusterConfig("testClusterConfigId"); testClusterConfig .setInstanceCapacityKeys(new ArrayList<>(defaultWeightDataMapResource.keySet())); testClusterConfig.setDefaultPartitionWeightMap(defaultWeightDataMapResource); ResourceConfig testResourceConfigResource = new ResourceConfig(resourceName); AssignableReplica replica = new AssignableReplica(testClusterConfig, testResourceConfigResource, partitionNamePrefix + 1, masterState, masterPriority); Assert.assertEquals(replica.getCapacity().size(), defaultWeightDataMapResource.size()); Assert.assertEquals(replica.getCapacity(), defaultWeightDataMapResource); }
@Test public void testIncompletePartitionWeightConfig() throws IOException { Map<String, Integer> capacityDataMapResource = new HashMap<>(); capacityDataMapResource.put("item1", 3); capacityDataMapResource.put("item2", 6); ResourceConfig testResourceConfigResource = new ResourceConfig(resourceName); testResourceConfigResource.setPartitionCapacityMap( Collections.singletonMap(ResourceConfig.DEFAULT_PARTITION_KEY, capacityDataMapResource)); ClusterConfig testClusterConfig = new ClusterConfig("testCluster"); List<String> requiredCapacityKeys = new ArrayList<>(capacityDataMapResource.keySet()); String unnecessaryCapacityKey = requiredCapacityKeys.remove(0); String newCapacityKey = "newCapacityKey"; requiredCapacityKeys.add(newCapacityKey); testClusterConfig.setInstanceCapacityKeys(requiredCapacityKeys); try { new AssignableReplica(testClusterConfig, testResourceConfigResource, partitionNamePrefix + 1, masterState, masterPriority); Assert.fail("Creating new replica should fail because of incomplete partition weight."); } catch (HelixException ex) { } Map<String, Integer> defaultCapacityDataMap = new HashMap<>(); for (String key : requiredCapacityKeys) { defaultCapacityDataMap.put(key, 0); } testClusterConfig.setDefaultPartitionWeightMap(defaultCapacityDataMap); AssignableReplica replica = new AssignableReplica(testClusterConfig, testResourceConfigResource, partitionNamePrefix + 1, masterState, masterPriority); Assert.assertTrue(replica.getCapacity().keySet().containsAll(requiredCapacityKeys)); Assert.assertEquals(replica.getCapacity().get(newCapacityKey).intValue(), 0); Assert.assertFalse(replica.getCapacity().containsKey(unnecessaryCapacityKey)); }