During the development and review process of the disk health indicator we noticed that it was hard to understand. Since we learnt a lot from the first round of development we want to go through the code one more time and restructure it.
server/src/test/java/org/elasticsearch/health/node/DiskHealthIndicatorServiceTests.java
Set<DiscoveryNode> nodes2,
        HealthStatus expectedStatus3,
        int numberOfNodesWithExpectedStatus3,
        Set<DiscoveryNode> nodes3
    ) {
        assert numberOfNodesWithExpectedStatus1 <= nodes1.size();
        assert numberOfNodesWithExpectedStatus2 <= nodes2.size();
        assert numberOfNodesWithExpectedStatus3 <= nodes3.size();
        Map<String, DiskHealthInfo> diskInfoByNode = new HashMap<>();
        createHealthInfoForNodes(diskInfoByNode, expectedStatus1, numberOfNodesWithExpectedStatus1, nodes1);
        createHealthInfoForNodes(diskInfoByNode, expectedStatus2, numberOfNodesWithExpectedStatus2, nodes2);
        createHealthInfoForNodes(diskInfoByNode, expectedStatus3, numberOfNodesWithExpectedStatus3, nodes3);
        return new HealthInfo(diskInfoByNode);
    }
    private void createHealthInfoForNodes(
        Map<String, DiskHealthInfo> diskInfoByNode,
        HealthStatus expectedStatus,
        int numberOfNodesWithExpectedStatus,
        Set<DiscoveryNode> nodes
    ) {
        int numberWithNonGreenStatus3 = 0;
        for (DiscoveryNode node : nodes) {
            final DiskHealthInfo diskHealthInfo;
            if (numberWithNonGreenStatus3 < numberOfNodesWithExpectedStatus) {
                diskHealthInfo = randomBoolean()
                    ? new DiskHealthInfo(expectedStatus)
                    : new DiskHealthInfo(expectedStatus, randomFrom(DiskHealthInfo.Cause.values()));
                numberWithNonGreenStatus3++;
            } else {
                diskHealthInfo = randomBoolean()