64 lines
2.3 KiB
Java
64 lines
2.3 KiB
Java
package net.minecraft.gametest.framework;
|
|
|
|
import com.google.common.collect.Maps;
|
|
import com.google.common.collect.Sets;
|
|
import com.google.common.collect.Lists;
|
|
import java.util.Optional;
|
|
import javax.annotation.Nullable;
|
|
import java.util.stream.Collector;
|
|
import java.util.stream.Collectors;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import java.util.function.Consumer;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.Collection;
|
|
|
|
public class GameTestRegistry {
|
|
private static final Collection<TestFunction> testFunctions;
|
|
private static final Set<String> testClassNames;
|
|
private static final Map<String, Consumer<ServerLevel>> beforeBatchFunctions;
|
|
|
|
public static Collection<TestFunction> getTestFunctionsForClassName(final String string) {
|
|
return GameTestRegistry.testFunctions.stream().filter(jk -> isTestFunctionPartOfClass(jk, string)).collect(Collectors.toList());
|
|
}
|
|
|
|
public static Collection<TestFunction> getAllTestFunctions() {
|
|
return GameTestRegistry.testFunctions;
|
|
}
|
|
|
|
public static Collection<String> getAllTestClassNames() {
|
|
return GameTestRegistry.testClassNames;
|
|
}
|
|
|
|
public static boolean isTestClass(final String string) {
|
|
return GameTestRegistry.testClassNames.contains(string);
|
|
}
|
|
|
|
@Nullable
|
|
public static Consumer<ServerLevel> getBeforeBatchFunction(final String string) {
|
|
return GameTestRegistry.beforeBatchFunctions.get(string);
|
|
}
|
|
|
|
public static Optional<TestFunction> findTestFunction(final String string) {
|
|
return getAllTestFunctions().stream().filter(jk -> jk.getTestName().equalsIgnoreCase(string)).findFirst();
|
|
}
|
|
|
|
public static TestFunction getTestFunction(final String string) {
|
|
final Optional<TestFunction> optional2 = findTestFunction(string);
|
|
if (!optional2.isPresent()) {
|
|
throw new IllegalArgumentException("Can't find the test function for " + string);
|
|
}
|
|
return optional2.get();
|
|
}
|
|
|
|
private static boolean isTestFunctionPartOfClass(final TestFunction jk, final String string) {
|
|
return jk.getTestName().toLowerCase().startsWith(string.toLowerCase() + ".");
|
|
}
|
|
|
|
static {
|
|
testFunctions = Lists.newArrayList();
|
|
testClassNames = Sets.newHashSet();
|
|
beforeBatchFunctions = Maps.newHashMap();
|
|
}
|
|
}
|