### Question:
InstanceConfig extends HelixProperty { public void setInstanceCapacityMap(Map<String, Integer> capacityDataMap) throws IllegalArgumentException { if (capacityDataMap == null) { _record.getMapFields().remove(InstanceConfigProperty.INSTANCE_CAPACITY_MAP.name()); } else { Map<String, String> capacityData = new HashMap<>(); capacityDataMap.entrySet().stream().forEach(entry -> { if (entry.getValue() < 0) { throw new IllegalArgumentException(String .format("Capacity Data contains a negative value: %s = %d", entry.getKey(), entry.getValue())); } capacityData.put(entry.getKey(), Integer.toString(entry.getValue())); }); _record.setMapField(InstanceConfigProperty.INSTANCE_CAPACITY_MAP.name(), capacityData); } } InstanceConfig(String instanceId);  InstanceConfig(ZNRecord record); String getHostName(); void setHostName(String hostName); String getPort(); void setPort(String port); @Deprecated String getZoneId(); void setZoneId(String zoneId); @Deprecated String getDomain(); String getDomainAsString(); Map<String, String> getDomainAsMap(); void setDomain(String domain); int getWeight(); void setWeight(int weight); List<String> getTags(); void addTag(String tag); void removeTag(String tag); boolean containsTag(String tag); boolean getInstanceEnabled(); void setInstanceEnabled(boolean enabled); long getInstanceEnabledTime(); @Deprecated boolean getInstanceEnabledForPartition(String partition); boolean getInstanceEnabledForPartition(String resource, String partition); @Deprecated List<String> getDisabledPartitions(); List<String> getDisabledPartitions(String resourceName); Map<String, List<String>> getDisabledPartitionsMap(); @Deprecated void setInstanceEnabledForPartition(String partitionName, boolean enabled); void setInstanceEnabledForPartition(String resourceName, String partitionName,
      boolean enabled); boolean isInstanceInDomain(String domain); boolean isDelayRebalanceEnabled(); void setDelayRebalanceEnabled(boolean enabled); int getMaxConcurrentTask(); void setMaxConcurrentTask(int maxConcurrentTask); int getTargetTaskThreadPoolSize(); void setTargetTaskThreadPoolSize(int targetTaskThreadPoolSize); Map<String, Integer> getInstanceCapacityMap(); void setInstanceCapacityMap(Map<String, Integer> capacityDataMap); @Override boolean equals(Object obj); @Override int hashCode(); String getInstanceName(); @Override boolean isValid(); static InstanceConfig toInstanceConfig(String instanceId); boolean validateTopologySettingInInstanceConfig(ClusterConfig clusterConfig,
      String instanceName); static final int WEIGHT_NOT_SET; static final int MAX_CONCURRENT_TASK_NOT_SET; }### Answer:
@Test public void testSetInstanceCapacityMap() { Map<String, Integer> capacityDataMap = ImmutableMap.of("item1", 1, "item2", 2, "item3", 3); Map<String, String> capacityDataMapString = ImmutableMap.of("item1", "1", "item2", "2", "item3", "3"); InstanceConfig testConfig = new InstanceConfig("testConfig"); testConfig.setInstanceCapacityMap(capacityDataMap); Assert.assertEquals(testConfig.getRecord().getMapField(InstanceConfig.InstanceConfigProperty. INSTANCE_CAPACITY_MAP.name()), capacityDataMapString); testConfig.setInstanceCapacityMap(Collections.emptyMap()); Assert.assertEquals(testConfig.getRecord().getMapField(InstanceConfig.InstanceConfigProperty. INSTANCE_CAPACITY_MAP.name()), Collections.emptyMap()); testConfig.setInstanceCapacityMap(null); Assert.assertTrue(testConfig.getRecord().getMapField(InstanceConfig.InstanceConfigProperty. INSTANCE_CAPACITY_MAP.name()) == null); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Capacity Data contains a negative value: item3 = -3") public void testSetInstanceCapacityMapInvalid() { Map<String, Integer> capacityDataMap = ImmutableMap.of("item1", 1, "item2", 2, "item3", -3); InstanceConfig testConfig = new InstanceConfig("testConfig"); testConfig.setInstanceCapacityMap(capacityDataMap); }