### Question:
InstanceValidationUtil { public static boolean isInstanceStable(HelixDataAccessor dataAccessor, String instanceName) { PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder(); ClusterConfig clusterConfig = dataAccessor.getProperty(keyBuilder.clusterConfig()); if (clusterConfig == null) { throw new HelixException("Missing cluster config!"); } List<String> idealStateNames = dataAccessor.getChildNames(keyBuilder.idealStates()); for (String idealStateName : idealStateNames) { IdealState idealState = dataAccessor.getProperty(keyBuilder.idealStates(idealStateName)); if (idealState == null || !idealState.isEnabled() || !idealState.isValid() || TaskConstants.STATE_MODEL_NAME.equals(idealState.getStateModelDefRef())) { continue; } ExternalView externalView = dataAccessor.getProperty(keyBuilder.externalView(idealStateName)); if (externalView == null) { throw new HelixException( String.format("Resource %s does not have external view!", idealStateName)); } for (String partition : idealState.getPartitionSet()) { Map<String, String> isPartitionMap = idealState.getInstanceStateMap(partition); if (isPartitionMap == null) { throw new HelixException(String .format("Partition %s of resource %s does not have an ideal state partition map", partition, idealStateName)); } if (isPartitionMap.containsKey(instanceName)) { Map<String, String> evPartitionMap = externalView.getStateMap(partition); if (evPartitionMap == null) { throw new HelixException(String .format("Partition %s of resource %s does not have an external view partition map", partition, idealStateName)); } if (!evPartitionMap.containsKey(instanceName) || !evPartitionMap.get(instanceName).equals(isPartitionMap.get(instanceName))) { return false; } } } } return true; } 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 TestIsInstanceStable_NoException_whenPersistAssignmentOff() { Mock mock = new Mock(); ClusterConfig clusterConfig = new ClusterConfig(TEST_CLUSTER); clusterConfig.setPersistIntermediateAssignment(false); when(mock.dataAccessor.getProperty(any(PropertyKey.class))).thenReturn(clusterConfig); InstanceValidationUtil.isInstanceStable(mock.dataAccessor, TEST_INSTANCE); }