geforkt von Mirrors/Paper
867ce6cc0a
Currently includes generated key holder classes for types used in the Registry Modification API
120 Zeilen
4.5 KiB
Diff
120 Zeilen
4.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Mon, 13 Feb 2023 14:14:56 -0800
|
|
Subject: [PATCH] Test changes
|
|
|
|
|
|
diff --git a/build.gradle.kts b/build.gradle.kts
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/build.gradle.kts
|
|
+++ b/build.gradle.kts
|
|
@@ -0,0 +0,0 @@ tasks.compileJava {
|
|
options.setIncremental(false)
|
|
}
|
|
|
|
+// Paper start - compile tests with -parameters for better junit parameterized test names
|
|
+tasks.compileTestJava {
|
|
+ options.compilerArgs.add("-parameters")
|
|
+}
|
|
+// Paper end
|
|
+
|
|
publishing {
|
|
publications.create<MavenPublication>("maven") {
|
|
artifact(tasks.shadowJar)
|
|
diff --git a/src/test/java/io/papermc/paper/registry/RegistryKeyTest.java b/src/test/java/io/papermc/paper/registry/RegistryKeyTest.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/test/java/io/papermc/paper/registry/RegistryKeyTest.java
|
|
@@ -0,0 +0,0 @@
|
|
+package io.papermc.paper.registry;
|
|
+
|
|
+import java.util.Optional;
|
|
+import java.util.stream.Stream;
|
|
+import net.minecraft.core.Registry;
|
|
+import net.minecraft.resources.ResourceKey;
|
|
+import net.minecraft.resources.ResourceLocation;
|
|
+import org.bukkit.support.AbstractTestingBase;
|
|
+import org.junit.jupiter.api.BeforeAll;
|
|
+import org.junit.jupiter.params.ParameterizedTest;
|
|
+import org.junit.jupiter.params.provider.MethodSource;
|
|
+
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
+
|
|
+class RegistryKeyTest extends AbstractTestingBase {
|
|
+
|
|
+ @BeforeAll
|
|
+ static void before() throws ClassNotFoundException {
|
|
+ Class.forName(RegistryKey.class.getName()); // load all keys so they are found for the test
|
|
+ }
|
|
+
|
|
+ static Stream<RegistryKey<?>> data() {
|
|
+ return RegistryKeyImpl.REGISTRY_KEYS.stream();
|
|
+ }
|
|
+
|
|
+ @ParameterizedTest
|
|
+ @MethodSource("data")
|
|
+ void testApiRegistryKeysExist(final RegistryKey<?> key) {
|
|
+ final Optional<Registry<Object>> registry = AbstractTestingBase.REGISTRY_CUSTOM.registry(ResourceKey.createRegistryKey(new ResourceLocation(key.key().asString())));
|
|
+ assertTrue(registry.isPresent(), "Missing vanilla registry for " + key.key().asString());
|
|
+
|
|
+ }
|
|
+}
|
|
diff --git a/src/test/java/io/papermc/paper/util/EmptyTag.java b/src/test/java/io/papermc/paper/util/EmptyTag.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/test/java/io/papermc/paper/util/EmptyTag.java
|
|
@@ -0,0 +0,0 @@
|
|
+package io.papermc.paper.util;
|
|
+
|
|
+import java.util.Collections;
|
|
+import java.util.Set;
|
|
+import org.bukkit.Keyed;
|
|
+import org.bukkit.NamespacedKey;
|
|
+import org.bukkit.Tag;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+
|
|
+public record EmptyTag(NamespacedKey key) implements Tag<Keyed> {
|
|
+
|
|
+ @SuppressWarnings("deprecation")
|
|
+ public EmptyTag() {
|
|
+ this(NamespacedKey.randomKey());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @NotNull NamespacedKey getKey() {
|
|
+ return this.key;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isTagged(@NotNull final Keyed item) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @NotNull Set<Keyed> getValues() {
|
|
+ return Collections.emptySet();
|
|
+ }
|
|
+}
|
|
diff --git a/src/test/java/org/bukkit/support/DummyServer.java b/src/test/java/org/bukkit/support/DummyServer.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/test/java/org/bukkit/support/DummyServer.java
|
|
+++ b/src/test/java/org/bukkit/support/DummyServer.java
|
|
@@ -0,0 +0,0 @@ public final class DummyServer {
|
|
|
|
when(instance.getRegistry(any())).then(mock -> CraftRegistry.createRegistry(mock.getArgument(0), AbstractTestingBase.REGISTRY_CUSTOM));
|
|
|
|
+ // Paper start - testing additions
|
|
+ final Thread currentThread = Thread.currentThread();
|
|
+ when(instance.isPrimaryThread()).thenAnswer(ignored -> Thread.currentThread().equals(currentThread));
|
|
+
|
|
+ final org.bukkit.plugin.PluginManager pluginManager = new org.bukkit.plugin.SimplePluginManager(instance, new org.bukkit.command.SimpleCommandMap(instance));
|
|
+ when(instance.getPluginManager()).thenReturn(pluginManager);
|
|
+ when(instance.getTag(anyString(), any(org.bukkit.NamespacedKey.class), any())).thenAnswer(ignored -> new io.papermc.paper.util.EmptyTag());
|
|
+ // paper end - testing additions
|
|
+
|
|
Bukkit.setServer(instance);
|
|
} catch (Throwable t) {
|
|
throw new Error(t);
|