mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-30 04:02:50 +01:00
119 lines
4.6 KiB
Diff
119 lines
4.6 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 ff4d0f970990187e9b46324b5cf051fcc546119f..844eff88c9ad95871900c2d8aa3136b3f2928bf9 100644
|
|
--- a/build.gradle.kts
|
|
+++ b/build.gradle.kts
|
|
@@ -58,6 +58,12 @@ 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..e070aa1bb69859224493d958621389ee757f8752
|
|
--- /dev/null
|
|
+++ b/src/test/java/io/papermc/paper/registry/RegistryKeyTest.java
|
|
@@ -0,0 +1,33 @@
|
|
+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..6eb95a5e2534974c0e52e2b78b04e7c2b2f28525
|
|
--- /dev/null
|
|
+++ b/src/test/java/io/papermc/paper/util/EmptyTag.java
|
|
@@ -0,0 +1,31 @@
|
|
+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 d96efc9aa90debcca5f237c949ba11b10070223a..d1253a07a90aa4cc29d0140795203a71118c827a 100644
|
|
--- a/src/test/java/org/bukkit/support/DummyServer.java
|
|
+++ b/src/test/java/org/bukkit/support/DummyServer.java
|
|
@@ -38,6 +38,15 @@ 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);
|