### Question:
InstanceValidationUtil { public static boolean hasDisabledPartitions(HelixDataAccessor dataAccessor, String clusterId, String instanceName) { PropertyKey propertyKey = dataAccessor.keyBuilder().instanceConfig(instanceName); InstanceConfig instanceConfig = dataAccessor.getProperty(propertyKey); if (instanceConfig != null) { for (List<String> disabledPartitions : instanceConfig.getDisabledPartitionsMap().values()) { if (disabledPartitions != null && disabledPartitions.size() > 0) { return true; } } return false; } throw new HelixException("Fail to get instance config for " + instanceName); } private  InstanceValidationUtil(); static boolean isEnabled(HelixDataAccessor dataAccessor, String instanceName); static boolean isAlive(HelixDataAccessor dataAccessor, String instanceName); static boolean hasResourceAssigned(HelixDataAccessor dataAccessor, String clusterId,
      String instanceName); static boolean hasDisabledPartitions(HelixDataAccessor dataAccessor, String clusterId,
      String instanceName); static boolean hasValidConfig(HelixDataAccessor dataAccessor, String clusterId,
      String instanceName); static boolean hasErrorPartitions(HelixDataAccessor dataAccessor, String clusterId,
      String instanceName); static List<String> perPartitionHealthCheck(List<ExternalView> externalViews,
      Map<String, Map<String, Boolean>> globalPartitionHealthStatus, String instanceToBeStop,
      HelixDataAccessor dataAccessor); static boolean isInstanceStable(HelixDataAccessor dataAccessor, String instanceName); static boolean siblingNodesActiveReplicaCheck(HelixDataAccessor dataAccessor, String instanceName); static Set<String> UNHEALTHY_STATES; }### Answer:
@Test public void TestHasDisabledPartitions_false() { Mock mock = new Mock(); InstanceConfig instanceConfig = mock(InstanceConfig.class); when(instanceConfig.getDisabledPartitionsMap()) .thenReturn(Collections.<String, List<String>> emptyMap()); when(mock.dataAccessor.getProperty(any(PropertyKey.class))).thenReturn(instanceConfig); Assert.assertFalse(InstanceValidationUtil.hasDisabledPartitions(mock.dataAccessor, TEST_CLUSTER, TEST_INSTANCE)); }
@Test public void TestHasDisabledPartitions_with_only_names() { Mock mock = new Mock(); InstanceConfig instanceConfig = mock(InstanceConfig.class); when(instanceConfig.getDisabledPartitionsMap()) .thenReturn(ImmutableMap.of("db0", Collections.emptyList())); when(mock.dataAccessor.getProperty(any(PropertyKey.class))).thenReturn(instanceConfig); Assert.assertFalse(InstanceValidationUtil.hasDisabledPartitions(mock.dataAccessor, TEST_CLUSTER, TEST_INSTANCE)); }
@Test public void TestHasDisabledPartitions_true() { Mock mock = new Mock(); InstanceConfig instanceConfig = mock(InstanceConfig.class); when(instanceConfig.getDisabledPartitionsMap()) .thenReturn(ImmutableMap.of("db0", Arrays.asList("p1"))); when(mock.dataAccessor.getProperty(any(PropertyKey.class))).thenReturn(instanceConfig); Assert.assertTrue(InstanceValidationUtil.hasDisabledPartitions(mock.dataAccessor, TEST_CLUSTER, TEST_INSTANCE)); }
@Test(expectedExceptions = HelixException.class) public void TestHasDisabledPartitions_exception() { Mock mock = new Mock(); when(mock.dataAccessor.getProperty(any(PropertyKey.class))).thenReturn(null); Assert.assertTrue(InstanceValidationUtil.hasDisabledPartitions(mock.dataAccessor, TEST_CLUSTER, TEST_INSTANCE)); }