File size: 3,893 Bytes
d46f4a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package net.minecraft.gametest.framework;

import com.google.common.collect.Lists;
import java.util.Collection;
import java.util.function.Consumer;
import java.util.stream.Collectors;

public class MultipleTestTracker {
    private static final char NOT_STARTED_TEST_CHAR = ' ';
    private static final char ONGOING_TEST_CHAR = '_';
    private static final char SUCCESSFUL_TEST_CHAR = '+';
    private static final char FAILED_OPTIONAL_TEST_CHAR = 'x';
    private static final char FAILED_REQUIRED_TEST_CHAR = 'X';
    private final Collection<GameTestInfo> tests = Lists.newArrayList();
    private final Collection<GameTestListener> listeners = Lists.newArrayList();

    public MultipleTestTracker() {
    }

    public MultipleTestTracker(Collection<GameTestInfo> p_127802_) {
        this.tests.addAll(p_127802_);
    }

    public void addTestToTrack(GameTestInfo p_127810_) {
        this.tests.add(p_127810_);
        this.listeners.forEach(p_127810_::addListener);
    }

    public void addListener(GameTestListener p_127812_) {
        this.listeners.add(p_127812_);
        this.tests.forEach(p_127815_ -> p_127815_.addListener(p_127812_));
    }

    public void addFailureListener(final Consumer<GameTestInfo> p_127808_) {
        this.addListener(new GameTestListener() {
            @Override
            public void testStructureLoaded(GameTestInfo p_127830_) {
            }

            @Override
            public void testPassed(GameTestInfo p_331591_, GameTestRunner p_333054_) {
            }

            @Override
            public void testFailed(GameTestInfo p_127832_, GameTestRunner p_329601_) {
                p_127808_.accept(p_127832_);
            }

            @Override
            public void testAddedForRerun(GameTestInfo p_177685_, GameTestInfo p_331155_, GameTestRunner p_328103_) {
            }
        });
    }

    public int getFailedRequiredCount() {
        return (int)this.tests.stream().filter(GameTestInfo::hasFailed).filter(GameTestInfo::isRequired).count();
    }

    public int getFailedOptionalCount() {
        return (int)this.tests.stream().filter(GameTestInfo::hasFailed).filter(GameTestInfo::isOptional).count();
    }

    public int getDoneCount() {
        return (int)this.tests.stream().filter(GameTestInfo::isDone).count();
    }

    public boolean hasFailedRequired() {
        return this.getFailedRequiredCount() > 0;
    }

    public boolean hasFailedOptional() {
        return this.getFailedOptionalCount() > 0;
    }

    public Collection<GameTestInfo> getFailedRequired() {
        return this.tests.stream().filter(GameTestInfo::hasFailed).filter(GameTestInfo::isRequired).collect(Collectors.toList());
    }

    public Collection<GameTestInfo> getFailedOptional() {
        return this.tests.stream().filter(GameTestInfo::hasFailed).filter(GameTestInfo::isOptional).collect(Collectors.toList());
    }

    public int getTotalCount() {
        return this.tests.size();
    }

    public boolean isDone() {
        return this.getDoneCount() == this.getTotalCount();
    }

    public String getProgressBar() {
        StringBuffer stringbuffer = new StringBuffer();
        stringbuffer.append('[');
        this.tests.forEach(p_127806_ -> {
            if (!p_127806_.hasStarted()) {
                stringbuffer.append(' ');
            } else if (p_127806_.hasSucceeded()) {
                stringbuffer.append('+');
            } else if (p_127806_.hasFailed()) {
                stringbuffer.append((char)(p_127806_.isRequired() ? 'X' : 'x'));
            } else {
                stringbuffer.append('_');
            }
        });
        stringbuffer.append(']');
        return stringbuffer.toString();
    }

    @Override
    public String toString() {
        return this.getProgressBar();
    }

    public void remove(GameTestInfo p_333633_) {
        this.tests.remove(p_333633_);
    }
}