MultipleTestTracker .java

net.minecraft.gametest.framework.MultipleTestTracker (class): members: FAILED_OPTIONAL_TEST_CHAR, FAILED_REQUIRED_TEST_CHAR, getFailedOptionalCount, tests.

net.minecraft.gametest.frameworkclass118 linescommon3.3 KB

API Surface (19)

void addTestToTrack(final GameTestInfo testInfo)
void addListener(final GameTestListener listener)
void addFailureListener(final Consumer<GameTestInfo> listener)
void testStructureLoaded(final GameTestInfo testInfo)
void testPassed(final GameTestInfo testInfo, final GameTestRunner runner)
void testFailed(final GameTestInfo testInfo, final GameTestRunner runner)
void testAddedForRerun(final GameTestInfo original, final GameTestInfo copy, final GameTestRunner runner)
int getFailedRequiredCount()
int getFailedOptionalCount()
int getDoneCount()
boolean hasFailedRequired()
boolean hasFailedOptional()
Collection<GameTestInfo> getFailedRequired()
Collection<GameTestInfo> getFailedOptional()
int getTotalCount()
boolean isDone()
String getProgressBar()
String toString()
void remove(final GameTestInfo testInfo)

Fields & Constants (7)

NOT_STARTED_TEST_CHAR
ONGOING_TEST_CHAR
SUCCESSFUL_TEST_CHAR
FAILED_OPTIONAL_TEST_CHAR
FAILED_REQUIRED_TEST_CHAR
tests
listeners

Code Graph: Dependencies (2)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

MultipleTestTracker.java118 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.gametest.framework;
2
3
import com.google.common.collect.Lists;
4
import java.util.Collection;
5
import java.util.function.Consumer;
6
import java.util.stream.Collectors;
7
8
public class MultipleTestTracker {
9
	private static final char NOT_STARTED_TEST_CHAR = ' ';
10
	private static final char ONGOING_TEST_CHAR = '_';
11
	private static final char SUCCESSFUL_TEST_CHAR = '+';
12
	private static final char FAILED_OPTIONAL_TEST_CHAR = 'x';
13
	private static final char FAILED_REQUIRED_TEST_CHAR = 'X';
14
	private final Collection<GameTestInfo> tests = Lists.newArrayList();
15
	private final Collection<GameTestListener> listeners = Lists.newArrayList();
16
17
	public MultipleTestTracker() {
18
	}
19
20
	public MultipleTestTracker(final Collection<GameTestInfo> tests) {
21
		this.tests.addAll(tests);
22
	}
23
24
	public void addTestToTrack(final GameTestInfo testInfo) {
25
		this.tests.add(testInfo);
26
		this.listeners.forEach(testInfo::addListener);
27
	}
28
29
	public void addListener(final GameTestListener listener) {
30
		this.listeners.add(listener);
31
		this.tests.forEach(testInfo -> testInfo.addListener(listener));
32
	}
33
34
	public void addFailureListener(final Consumer<GameTestInfo> listener) {
35
		this.addListener(new GameTestListener() {
36
			@Override
37
			public void testStructureLoaded(final GameTestInfo testInfo) {
38
			}
39
40
			@Override
41
			public void testPassed(final GameTestInfo testInfo, final GameTestRunner runner) {
42
			}
43
44
			@Override
45
			public void testFailed(final GameTestInfo testInfo, final GameTestRunner runner) {
46
				listener.accept(testInfo);
47
			}
48
49
			@Override
50
			public void testAddedForRerun(final GameTestInfo original, final GameTestInfo copy, final GameTestRunner runner) {
51
			}
52
		});
53
	}
54
55
	public int getFailedRequiredCount() {
56
		return (int)this.tests.stream().filter(GameTestInfo::hasFailed).filter(GameTestInfo::isRequired).count();
57
	}
58
59
	public int getFailedOptionalCount() {
60
		return (int)this.tests.stream().filter(GameTestInfo::hasFailed).filter(GameTestInfo::isOptional).count();
61
	}
62
63
	public int getDoneCount() {
64
		return (int)this.tests.stream().filter(GameTestInfo::isDone).count();
65
	}
66
67
	public boolean hasFailedRequired() {
68
		return this.getFailedRequiredCount() > 0;
69
	}
70
71
	public boolean hasFailedOptional() {
72
		return this.getFailedOptionalCount() > 0;
73
	}
74
75
	public Collection<GameTestInfo> getFailedRequired() {
76
		return this.tests.stream().filter(GameTestInfo::hasFailed).filter(GameTestInfo::isRequired).collect(Collectors.toList());
77
	}
78
79
	public Collection<GameTestInfo> getFailedOptional() {
80
		return this.tests.stream().filter(GameTestInfo::hasFailed).filter(GameTestInfo::isOptional).collect(Collectors.toList());
81
	}
82
83
	public int getTotalCount() {
84
		return this.tests.size();
85
	}
86
87
	public boolean isDone() {
88
		return this.getDoneCount() == this.getTotalCount();
89
	}
90
91
	public String getProgressBar() {
92
		StringBuffer buf = new StringBuffer();
93
		buf.append('[');
94
		this.tests.forEach(test -> {
95
			if (!test.hasStarted()) {
96
				buf.append(' ');
97
			} else if (test.hasSucceeded()) {
98
				buf.append('+');
99
			} else if (test.hasFailed()) {
100
				buf.append((char)(test.isRequired() ? 'X' : 'x'));
101
			} else {
102
				buf.append('_');
103
			}
104
		});
105
		buf.append(']');
106
		return buf.toString();
107
	}
108
109
	@Override
110
	public String toString() {
111
		return this.getProgressBar();
112
	}
113
114
	public void remove(final GameTestInfo testInfo) {
115
		this.tests.remove(testInfo);
116
	}
117
}
118

Decompiled Minecraft 26.3 source of MultipleTestTracker (net/minecraft/gametest/framework/MultipleTestTracker.java) with Mojang official mappings, stored verbatim on the site.