@Override
    public Map<Errors, Integer> errorCounts() {
        if (data.errorCode() != Errors.NONE.code())
            // Minor optimization since the top-level error applies to all partitions
            return Collections.singletonMap(error(), data.partitionErrors().size() + 1);
        Map<Errors, Integer> errors = errorCounts(data.partitionErrors().stream().map(p -> Errors.forCode(p.errorCode())));
        updateErrorCounts(errors, Errors.forCode(data.errorCode())); // top level error
        return errors;
    }
@Test
    public void testErrorCountsFromGetErrorResponse() {
        List<StopReplicaTopicState> topicStates = new ArrayList<>();
        topicStates.add(new StopReplicaTopicState()
            .setTopicName("foo")
            .setPartitionStates(Arrays.asList(
                new StopReplicaPartitionState().setPartitionIndex(0),
                new StopReplicaPartitionState().setPartitionIndex(1))));

        for (short version : STOP_REPLICA.allVersions()) {
            StopReplicaRequest request = new StopReplicaRequest.Builder(version,
                15, 20, 0, false, topicStates).build(version);
            StopReplicaResponse response = request
                .getErrorResponse(0, Errors.CLUSTER_AUTHORIZATION_FAILED.exception());
            assertEquals(Collections.singletonMap(Errors.CLUSTER_AUTHORIZATION_FAILED, 3),
                response.errorCounts());
        }
    }