### Question:
InstanceValidationUtil { public static boolean isEnabled(HelixDataAccessor dataAccessor, String instanceName) { PropertyKey.Builder propertyKeyBuilder = dataAccessor.keyBuilder(); InstanceConfig instanceConfig = dataAccessor.getProperty(propertyKeyBuilder.instanceConfig(instanceName)); ClusterConfig clusterConfig = dataAccessor.getProperty(propertyKeyBuilder.clusterConfig()); if (instanceConfig == null || clusterConfig == null) { throw new HelixException("InstanceConfig or ClusterConfig is NULL"); } boolean enabledInInstanceConfig = instanceConfig.getInstanceEnabled(); Map<String, String> disabledInstances = clusterConfig.getDisabledInstances(); boolean enabledInClusterConfig = disabledInstances == null || !disabledInstances.keySet().contains(instanceName); return enabledInClusterConfig && enabledInInstanceConfig; } 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(dataProvider = "isEnabledTestSuite") public void TestIsInstanceEnabled(boolean instanceConfigEnabled, boolean clusterConfigEnabled, boolean expected) { Mock mock = new Mock(); InstanceConfig instanceConfig = new InstanceConfig(TEST_INSTANCE); instanceConfig.setInstanceEnabled(instanceConfigEnabled); doReturn(instanceConfig).when(mock.dataAccessor) .getProperty(BUILDER.instanceConfig(TEST_INSTANCE)); ClusterConfig clusterConfig = new ClusterConfig(TEST_CLUSTER); if (!clusterConfigEnabled) { clusterConfig.setDisabledInstances(ImmutableMap.of(TEST_INSTANCE, "12345")); } doReturn(clusterConfig).when(mock.dataAccessor) .getProperty(BUILDER.clusterConfig()); boolean isEnabled = InstanceValidationUtil.isEnabled(mock.dataAccessor, TEST_INSTANCE); Assert.assertEquals(isEnabled, expected); }
@Test(expectedExceptions = HelixException.class) public void TestIsInstanceEnabled_whenInstanceConfigNull() { Mock mock = new Mock(); doReturn(null).when(mock.dataAccessor) .getProperty(argThat(new PropertyKeyArgument(PropertyType.CONFIGS))); InstanceValidationUtil.isEnabled(mock.dataAccessor, TEST_INSTANCE); }
@Test(expectedExceptions = HelixException.class) public void TestIsInstanceEnabled_whenClusterConfigNull() { Mock mock = new Mock(); doReturn(new InstanceConfig(TEST_INSTANCE)).when(mock.dataAccessor) .getProperty(argThat(new PropertyKeyArgument(PropertyType.CONFIGS))); doReturn(null).when(mock.dataAccessor) .getProperty(BUILDER.clusterConfig()); InstanceValidationUtil.isEnabled(mock.dataAccessor, TEST_INSTANCE); }