### Question:
InstanceValidationUtil { public static boolean hasValidConfig(HelixDataAccessor dataAccessor, String clusterId, String instanceName) { PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder(); ClusterConfig clusterConfig = dataAccessor.getProperty(keyBuilder.clusterConfig()); if (clusterConfig == null) { _logger.error("Cluster config is missing in cluster " + clusterId); return false; } if (!clusterConfig.isPersistIntermediateAssignment()) { _logger.error( "Cluster config %s is not turned on, which is required for instance stability check.", ClusterConfig.ClusterConfigProperty.PERSIST_INTERMEDIATE_ASSIGNMENT.toString()); return false; } PropertyKey propertyKey = keyBuilder.instanceConfig(instanceName); InstanceConfig instanceConfig = dataAccessor.getProperty(propertyKey); return instanceConfig != null && instanceConfig.isValid(); } 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 TestHasValidConfig_true() { Mock mock = new Mock(); PropertyKey.Builder keyBuilder = mock.dataAccessor.keyBuilder(); PropertyKey clusterProperty = keyBuilder.clusterConfig(); ClusterConfig clusterConfig = new ClusterConfig(TEST_CLUSTER); clusterConfig.setPersistIntermediateAssignment(true); when(mock.dataAccessor.getProperty(eq(clusterProperty))) .thenReturn(clusterConfig); PropertyKey instanceProperty = keyBuilder.instanceConfig(TEST_INSTANCE); when(mock.dataAccessor.getProperty(eq(instanceProperty))) .thenReturn(new InstanceConfig(TEST_INSTANCE)); Assert.assertTrue( InstanceValidationUtil.hasValidConfig(mock.dataAccessor, TEST_CLUSTER, TEST_INSTANCE)); }
@Test public void TestHasValidConfig_false() { Mock mock = new Mock(); when(mock.dataAccessor.getProperty(any(PropertyKey.class))).thenReturn(null); Assert.assertFalse( InstanceValidationUtil.hasValidConfig(mock.dataAccessor, TEST_CLUSTER, TEST_INSTANCE)); }