### Question:
InstanceValidationUtil { public static boolean hasErrorPartitions(HelixDataAccessor dataAccessor, String clusterId, String instanceName) { PropertyKey.Builder propertyKeyBuilder = new PropertyKey.Builder(clusterId); PropertyKey liveInstanceKey = propertyKeyBuilder.liveInstance(instanceName); LiveInstance liveInstance = dataAccessor.getProperty(liveInstanceKey); if (liveInstance != null) { String sessionId = liveInstance.getEphemeralOwner(); PropertyKey currentStatesKey = propertyKeyBuilder.currentStates(instanceName, sessionId); List<String> resourceNames = dataAccessor.getChildNames(currentStatesKey); for (String resourceName : resourceNames) { PropertyKey key = propertyKeyBuilder.currentState(instanceName, sessionId, resourceName); CurrentState currentState = dataAccessor.getProperty(key); if (currentState != null && currentState.getPartitionStateMap().containsValue(HelixDefinedState.ERROR.name())) { return true; } } } _logger.warn(String.format("The instance %s is not active", instanceName)); return false; } 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 TestHasErrorPartitions_true() { String sessionId = "sessionId"; String resource = "db"; Mock mock = new Mock(); LiveInstance liveInstance = new LiveInstance(TEST_INSTANCE); liveInstance.setSessionId(sessionId); doReturn(liveInstance).when(mock.dataAccessor) .getProperty(argThat(new PropertyKeyArgument(PropertyType.LIVEINSTANCES))); doReturn(ImmutableList.of(resource)).when(mock.dataAccessor) .getChildNames(argThat(new PropertyKeyArgument(PropertyType.CURRENTSTATES))); CurrentState currentState = mock(CurrentState.class); when(currentState.getPartitionStateMap()).thenReturn(ImmutableMap.of("db0", "ERROR")); doReturn(currentState).when(mock.dataAccessor) .getProperty(argThat(new PropertyKeyArgument(PropertyType.CURRENTSTATES))); Assert.assertTrue( InstanceValidationUtil.hasErrorPartitions(mock.dataAccessor, TEST_CLUSTER, TEST_INSTANCE)); }
@Test public void TestHasErrorPartitions_false() { String sessionId = "sessionId"; String resource = "db"; Mock mock = new Mock(); LiveInstance liveInstance = new LiveInstance(TEST_INSTANCE); liveInstance.setSessionId(sessionId); doReturn(liveInstance).when(mock.dataAccessor) .getProperty(argThat(new PropertyKeyArgument(PropertyType.LIVEINSTANCES))); doReturn(ImmutableList.of(resource)).when(mock.dataAccessor) .getChildNames(argThat(new PropertyKeyArgument(PropertyType.CURRENTSTATES))); CurrentState currentState = mock(CurrentState.class); when(currentState.getPartitionStateMap()).thenReturn(ImmutableMap.of("db0", "Master")); doReturn(currentState).when(mock.dataAccessor) .getProperty(argThat(new PropertyKeyArgument(PropertyType.CURRENTSTATES))); Assert.assertFalse( InstanceValidationUtil.hasErrorPartitions(mock.dataAccessor, TEST_CLUSTER, TEST_INSTANCE)); }