2023-02-15 22:27:40 +01:00
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
2024-01-14 10:46:04 +01:00
index e7fa464573909d4c3d649ebb5f40ef54055e09a8..2df1cae62cff433a7f3f55f561f70719bb6a745b 100644
2023-02-15 22:27:40 +01:00
--- a/build.gradle.kts
+++ b/build.gradle.kts
2024-01-14 10:46:04 +01:00
@@ -57,6 +57,12 @@ tasks.compileJava {
2023-09-25 01:05:05 +02:00
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)
2023-11-23 05:56:28 +01:00
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());
+
+ }
+}
2023-11-05 00:37:51 +01:00
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();
+ }
+}
2023-02-15 22:27:40 +01:00
diff --git a/src/test/java/org/bukkit/support/DummyServer.java b/src/test/java/org/bukkit/support/DummyServer.java
2024-01-26 20:17:06 +01:00
index b19d4f7d1fcb604b448a5084f6bfe56d47ab12b3..f3017525b0c2397fdc7ce0778add2e7b38e9e2ba 100644
2023-02-15 22:27:40 +01:00
--- a/src/test/java/org/bukkit/support/DummyServer.java
2023-10-22 21:12:00 +02:00
+++ b/src/test/java/org/bukkit/support/DummyServer.java
2024-01-26 20:17:06 +01:00
@@ -48,6 +48,15 @@ public final class DummyServer {
return registers.computeIfAbsent(aClass, key -> CraftRegistry.createRegistry(aClass, AbstractTestingBase.REGISTRY_CUSTOM));
});
2023-10-22 21:12:00 +02:00
+ // 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);
2023-11-05 00:37:51 +01:00
+ when(instance.getTag(anyString(), any(org.bukkit.NamespacedKey.class), any())).thenAnswer(ignored -> new io.papermc.paper.util.EmptyTag());
2023-10-22 21:12:00 +02:00
+ // paper end - testing additions
+
Bukkit.setServer(instance);
} catch (Throwable t) {
throw new Error(t);