convert API/server tests to mockito (#8848)
* convert API tests to mockito * convert server tests to mockito * add co-author
This commit is contained in:
parent
f2f9e8cc4d
commit
afe633df08
964 changed files with 819 additions and 230 deletions
|
@ -1,114 +0,0 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Shane Freeder <theboyetronic@gmail.com>
|
||||
Date: Sun, 17 Mar 2019 23:04:30 +0000
|
||||
Subject: [PATCH] Annotation Test changes
|
||||
|
||||
- Allow use of TYPE_USE annotations
|
||||
- Ignore package-private methods for nullability annotations
|
||||
- Add excludes for classes which don't pass
|
||||
|
||||
diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java
|
||||
index 4ac3dd977e75cd8464163351d306e037ee32cb48..1a71bb8861150c1add6446aa2fad0f7035dd6873 100644
|
||||
--- a/src/test/java/org/bukkit/AnnotationTest.java
|
||||
+++ b/src/test/java/org/bukkit/AnnotationTest.java
|
||||
@@ -40,7 +40,17 @@ public class AnnotationTest {
|
||||
"org/bukkit/util/io/Wrapper",
|
||||
"org/bukkit/plugin/java/PluginClassLoader",
|
||||
// Generic functional interface
|
||||
- "org/bukkit/util/Consumer"
|
||||
+ "org/bukkit/util/Consumer",
|
||||
+ // Paper start
|
||||
+ // Timings history is broken in terms of nullability due to guavas Function defining that the param is NonNull
|
||||
+ "co/aikar/timings/TimingHistory$2",
|
||||
+ "co/aikar/timings/TimingHistory$2$1",
|
||||
+ "co/aikar/timings/TimingHistory$2$1$1",
|
||||
+ "co/aikar/timings/TimingHistory$2$1$2",
|
||||
+ "co/aikar/timings/TimingHistory$3",
|
||||
+ "co/aikar/timings/TimingHistory$4",
|
||||
+ "co/aikar/timings/TimingHistoryEntry$1"
|
||||
+ // Paper end
|
||||
};
|
||||
|
||||
@Test
|
||||
@@ -67,14 +77,40 @@ public class AnnotationTest {
|
||||
}
|
||||
|
||||
if (mustBeAnnotated(Type.getReturnType(method.desc)) && !isWellAnnotated(method.invisibleAnnotations)) {
|
||||
+ // Paper start - Allow use of TYPE_USE annotations
|
||||
+ boolean warn = true;
|
||||
+ if (isWellAnnotated(method.visibleTypeAnnotations)) {
|
||||
+ warn = false;
|
||||
+ } else if (method.invisibleTypeAnnotations != null) {
|
||||
+ dance: for (final org.objectweb.asm.tree.TypeAnnotationNode invisibleTypeAnnotation : method.invisibleTypeAnnotations) {
|
||||
+ final org.objectweb.asm.TypeReference ref = new org.objectweb.asm.TypeReference(invisibleTypeAnnotation.typeRef);
|
||||
+ if (ref.getSort() == org.objectweb.asm.TypeReference.METHOD_RETURN && java.util.Arrays.binarySearch(ACCEPTED_ANNOTATIONS, invisibleTypeAnnotation.desc) >= 0) {
|
||||
+ warn = false;
|
||||
+ break dance; // cha cha real smooth
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ if (warn)
|
||||
+ // Paper end
|
||||
warn(errors, clazz, method, "return value");
|
||||
}
|
||||
|
||||
Type[] paramTypes = Type.getArgumentTypes(method.desc);
|
||||
List<ParameterNode> parameters = method.parameters;
|
||||
|
||||
+ dancing: // Paper
|
||||
for (int i = 0; i < paramTypes.length; i++) {
|
||||
if (mustBeAnnotated(paramTypes[i]) ^ isWellAnnotated(method.invisibleParameterAnnotations == null ? null : method.invisibleParameterAnnotations[i])) {
|
||||
+ // Paper start
|
||||
+ if (method.invisibleTypeAnnotations != null) {
|
||||
+ for (final org.objectweb.asm.tree.TypeAnnotationNode invisibleTypeAnnotation : method.invisibleTypeAnnotations) {
|
||||
+ final org.objectweb.asm.TypeReference ref = new org.objectweb.asm.TypeReference(invisibleTypeAnnotation.typeRef);
|
||||
+ if (ref.getSort() == org.objectweb.asm.TypeReference.METHOD_FORMAL_PARAMETER && ref.getTypeParameterIndex() == i && java.util.Arrays.binarySearch(ACCEPTED_ANNOTATIONS, invisibleTypeAnnotation.desc) >= 0) {
|
||||
+ continue dancing;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ // Paper end - Allow use of TYPE_USE annotations
|
||||
ParameterNode paramNode = parameters == null ? null : parameters.get(i);
|
||||
String paramName = paramNode == null ? null : paramNode.name;
|
||||
|
||||
@@ -91,13 +127,18 @@ public class AnnotationTest {
|
||||
|
||||
Collections.sort(errors);
|
||||
|
||||
- System.out.println(errors.size() + " missing annotation(s):");
|
||||
+ StringBuilder builder = new StringBuilder()
|
||||
+ .append("There ")
|
||||
+ .append(errors.size() != 1 ? "are " : "is ")
|
||||
+ .append(errors.size())
|
||||
+ .append(" missing annotation")
|
||||
+ .append(errors.size() != 1 ? "s:\n" : ":\n");
|
||||
+
|
||||
for (String message : errors) {
|
||||
- System.out.print("\t");
|
||||
- System.out.println(message);
|
||||
+ builder.append("\t").append(message).append("\n");
|
||||
}
|
||||
|
||||
- Assert.fail("There " + errors.size() + " are missing annotation(s)");
|
||||
+ Assert.fail(builder.toString());
|
||||
}
|
||||
|
||||
private static void collectClasses(@NotNull File from, @NotNull Map<String, ClassNode> to) throws IOException {
|
||||
@@ -152,7 +193,7 @@ public class AnnotationTest {
|
||||
|
||||
private static boolean isMethodIncluded(@NotNull ClassNode clazz, @NotNull MethodNode method, @NotNull Map<String, ClassNode> allClasses) {
|
||||
// Exclude private, synthetic and deprecated methods
|
||||
- if ((method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_DEPRECATED)) != 0) {
|
||||
+ if ((method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_DEPRECATED)) != 0 || (method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC)) == 0) { // Paper - ignore package-private
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -174,7 +215,7 @@ public class AnnotationTest {
|
||||
return true;
|
||||
}
|
||||
|
||||
- private static boolean isWellAnnotated(@Nullable List<AnnotationNode> annotations) {
|
||||
+ private static boolean isWellAnnotated(@Nullable List<? extends AnnotationNode> annotations) { // Paper
|
||||
if (annotations == null) {
|
||||
return false;
|
||||
}
|
478
patches/api/0003-Test-changes.patch
Normal file
478
patches/api/0003-Test-changes.patch
Normal file
|
@ -0,0 +1,478 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Shane Freeder <theboyetronic@gmail.com>
|
||||
Date: Sun, 17 Mar 2019 23:04:30 +0000
|
||||
Subject: [PATCH] Test changes
|
||||
|
||||
- convert to mockito for mocking of types
|
||||
- Allow use of TYPE_USE annotations
|
||||
- Ignore package-private methods for nullability annotations
|
||||
- Add excludes for classes which don't pass
|
||||
|
||||
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
|
||||
diff --git a/build.gradle.kts b/build.gradle.kts
|
||||
index 2b3288057d67e5add4e22e6b7072527057bcd808..4b3453f8dab6008b6fad6245fb7205da33b4bfb8 100644
|
||||
--- a/build.gradle.kts
|
||||
+++ b/build.gradle.kts
|
||||
@@ -34,6 +34,7 @@ dependencies {
|
||||
compileOnlyApi(checkerQual)
|
||||
testCompileOnly(checkerQual)
|
||||
// Paper end
|
||||
+ testImplementation("org.mockito:mockito-core:4.9.0") // Paper - add mockito
|
||||
|
||||
testImplementation("org.apache.commons:commons-lang3:3.12.0")
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
diff --git a/src/test/java/io/papermc/paper/testing/EmptyRegistry.java b/src/test/java/io/papermc/paper/testing/EmptyRegistry.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..ba9ddce87a9f385e729a5c2cf7c5eec120e388a7
|
||||
--- /dev/null
|
||||
+++ b/src/test/java/io/papermc/paper/testing/EmptyRegistry.java
|
||||
@@ -0,0 +1,23 @@
|
||||
+package io.papermc.paper.testing;
|
||||
+
|
||||
+import java.util.Collections;
|
||||
+import java.util.Iterator;
|
||||
+import org.bukkit.Keyed;
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.Registry;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+
|
||||
+public record EmptyRegistry() implements Registry<Keyed> {
|
||||
+
|
||||
+ @NotNull
|
||||
+ @Override
|
||||
+ public Iterator<Keyed> iterator() {
|
||||
+ return Collections.emptyIterator();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @Nullable Keyed get(@NotNull final NamespacedKey key) {
|
||||
+ return null;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/test/java/io/papermc/paper/testing/EmptyTag.java b/src/test/java/io/papermc/paper/testing/EmptyTag.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..77154095cfb8b259bdb318e8ff40cb6f559ebc18
|
||||
--- /dev/null
|
||||
+++ b/src/test/java/io/papermc/paper/testing/EmptyTag.java
|
||||
@@ -0,0 +1,31 @@
|
||||
+package io.papermc.paper.testing;
|
||||
+
|
||||
+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/io/papermc/paper/testing/TestServer.java b/src/test/java/io/papermc/paper/testing/TestServer.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..756acf231b1b076b08046d86992ba7ce7f62a94f
|
||||
--- /dev/null
|
||||
+++ b/src/test/java/io/papermc/paper/testing/TestServer.java
|
||||
@@ -0,0 +1,48 @@
|
||||
+package io.papermc.paper.testing;
|
||||
+
|
||||
+import java.util.logging.Logger;
|
||||
+import org.bukkit.Bukkit;
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.Server;
|
||||
+import org.bukkit.command.SimpleCommandMap;
|
||||
+import org.bukkit.plugin.PluginManager;
|
||||
+import org.bukkit.plugin.SimplePluginManager;
|
||||
+
|
||||
+import static org.mockito.ArgumentMatchers.anyString;
|
||||
+import static org.mockito.Mockito.any;
|
||||
+import static org.mockito.Mockito.mock;
|
||||
+import static org.mockito.Mockito.when;
|
||||
+
|
||||
+public final class TestServer {
|
||||
+
|
||||
+ @SuppressWarnings("removal")
|
||||
+ public static void setup() {
|
||||
+ //noinspection ConstantValue
|
||||
+ if (Bukkit.getServer() != null) {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ final Server dummyServer = mock(Server.class);
|
||||
+
|
||||
+ final Logger logger = Logger.getLogger(TestServer.class.getCanonicalName());
|
||||
+ when(dummyServer.getLogger()).thenReturn(logger);
|
||||
+ when(dummyServer.getName()).thenReturn(TestServer.class.getSimpleName());
|
||||
+ when(dummyServer.getVersion()).thenReturn("Version_" + TestServer.class.getPackage().getImplementationVersion());
|
||||
+ when(dummyServer.getBukkitVersion()).thenReturn("BukkitVersion_" + TestServer.class.getPackage().getImplementationVersion());
|
||||
+
|
||||
+
|
||||
+ final Thread currentThread = Thread.currentThread();
|
||||
+ when(dummyServer.isPrimaryThread()).thenAnswer(ignored -> Thread.currentThread().equals(currentThread));
|
||||
+
|
||||
+ when(dummyServer.getTag(anyString(), any(NamespacedKey.class), any())).thenAnswer(ignored -> new EmptyTag());
|
||||
+
|
||||
+ final PluginManager pluginManager = new SimplePluginManager(dummyServer, new SimpleCommandMap(dummyServer));
|
||||
+ when(dummyServer.getPluginManager()).thenReturn(pluginManager);
|
||||
+
|
||||
+ when(dummyServer.getRegistry(any())).thenAnswer(ignored -> new EmptyRegistry());
|
||||
+ when(dummyServer.getScoreboardCriteria(anyString())).thenReturn(null);
|
||||
+
|
||||
+ Bukkit.setServer(dummyServer);
|
||||
+ }
|
||||
+
|
||||
+}
|
||||
diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java
|
||||
index 4ac3dd977e75cd8464163351d306e037ee32cb48..1a71bb8861150c1add6446aa2fad0f7035dd6873 100644
|
||||
--- a/src/test/java/org/bukkit/AnnotationTest.java
|
||||
+++ b/src/test/java/org/bukkit/AnnotationTest.java
|
||||
@@ -40,7 +40,17 @@ public class AnnotationTest {
|
||||
"org/bukkit/util/io/Wrapper",
|
||||
"org/bukkit/plugin/java/PluginClassLoader",
|
||||
// Generic functional interface
|
||||
- "org/bukkit/util/Consumer"
|
||||
+ "org/bukkit/util/Consumer",
|
||||
+ // Paper start
|
||||
+ // Timings history is broken in terms of nullability due to guavas Function defining that the param is NonNull
|
||||
+ "co/aikar/timings/TimingHistory$2",
|
||||
+ "co/aikar/timings/TimingHistory$2$1",
|
||||
+ "co/aikar/timings/TimingHistory$2$1$1",
|
||||
+ "co/aikar/timings/TimingHistory$2$1$2",
|
||||
+ "co/aikar/timings/TimingHistory$3",
|
||||
+ "co/aikar/timings/TimingHistory$4",
|
||||
+ "co/aikar/timings/TimingHistoryEntry$1"
|
||||
+ // Paper end
|
||||
};
|
||||
|
||||
@Test
|
||||
@@ -67,14 +77,40 @@ public class AnnotationTest {
|
||||
}
|
||||
|
||||
if (mustBeAnnotated(Type.getReturnType(method.desc)) && !isWellAnnotated(method.invisibleAnnotations)) {
|
||||
+ // Paper start - Allow use of TYPE_USE annotations
|
||||
+ boolean warn = true;
|
||||
+ if (isWellAnnotated(method.visibleTypeAnnotations)) {
|
||||
+ warn = false;
|
||||
+ } else if (method.invisibleTypeAnnotations != null) {
|
||||
+ dance: for (final org.objectweb.asm.tree.TypeAnnotationNode invisibleTypeAnnotation : method.invisibleTypeAnnotations) {
|
||||
+ final org.objectweb.asm.TypeReference ref = new org.objectweb.asm.TypeReference(invisibleTypeAnnotation.typeRef);
|
||||
+ if (ref.getSort() == org.objectweb.asm.TypeReference.METHOD_RETURN && java.util.Arrays.binarySearch(ACCEPTED_ANNOTATIONS, invisibleTypeAnnotation.desc) >= 0) {
|
||||
+ warn = false;
|
||||
+ break dance; // cha cha real smooth
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ if (warn)
|
||||
+ // Paper end
|
||||
warn(errors, clazz, method, "return value");
|
||||
}
|
||||
|
||||
Type[] paramTypes = Type.getArgumentTypes(method.desc);
|
||||
List<ParameterNode> parameters = method.parameters;
|
||||
|
||||
+ dancing: // Paper
|
||||
for (int i = 0; i < paramTypes.length; i++) {
|
||||
if (mustBeAnnotated(paramTypes[i]) ^ isWellAnnotated(method.invisibleParameterAnnotations == null ? null : method.invisibleParameterAnnotations[i])) {
|
||||
+ // Paper start
|
||||
+ if (method.invisibleTypeAnnotations != null) {
|
||||
+ for (final org.objectweb.asm.tree.TypeAnnotationNode invisibleTypeAnnotation : method.invisibleTypeAnnotations) {
|
||||
+ final org.objectweb.asm.TypeReference ref = new org.objectweb.asm.TypeReference(invisibleTypeAnnotation.typeRef);
|
||||
+ if (ref.getSort() == org.objectweb.asm.TypeReference.METHOD_FORMAL_PARAMETER && ref.getTypeParameterIndex() == i && java.util.Arrays.binarySearch(ACCEPTED_ANNOTATIONS, invisibleTypeAnnotation.desc) >= 0) {
|
||||
+ continue dancing;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ // Paper end - Allow use of TYPE_USE annotations
|
||||
ParameterNode paramNode = parameters == null ? null : parameters.get(i);
|
||||
String paramName = paramNode == null ? null : paramNode.name;
|
||||
|
||||
@@ -91,13 +127,18 @@ public class AnnotationTest {
|
||||
|
||||
Collections.sort(errors);
|
||||
|
||||
- System.out.println(errors.size() + " missing annotation(s):");
|
||||
+ StringBuilder builder = new StringBuilder()
|
||||
+ .append("There ")
|
||||
+ .append(errors.size() != 1 ? "are " : "is ")
|
||||
+ .append(errors.size())
|
||||
+ .append(" missing annotation")
|
||||
+ .append(errors.size() != 1 ? "s:\n" : ":\n");
|
||||
+
|
||||
for (String message : errors) {
|
||||
- System.out.print("\t");
|
||||
- System.out.println(message);
|
||||
+ builder.append("\t").append(message).append("\n");
|
||||
}
|
||||
|
||||
- Assert.fail("There " + errors.size() + " are missing annotation(s)");
|
||||
+ Assert.fail(builder.toString());
|
||||
}
|
||||
|
||||
private static void collectClasses(@NotNull File from, @NotNull Map<String, ClassNode> to) throws IOException {
|
||||
@@ -152,7 +193,7 @@ public class AnnotationTest {
|
||||
|
||||
private static boolean isMethodIncluded(@NotNull ClassNode clazz, @NotNull MethodNode method, @NotNull Map<String, ClassNode> allClasses) {
|
||||
// Exclude private, synthetic and deprecated methods
|
||||
- if ((method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_DEPRECATED)) != 0) {
|
||||
+ if ((method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_DEPRECATED)) != 0 || (method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC)) == 0) { // Paper - ignore package-private
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -174,7 +215,7 @@ public class AnnotationTest {
|
||||
return true;
|
||||
}
|
||||
|
||||
- private static boolean isWellAnnotated(@Nullable List<AnnotationNode> annotations) {
|
||||
+ private static boolean isWellAnnotated(@Nullable List<? extends AnnotationNode> annotations) { // Paper
|
||||
if (annotations == null) {
|
||||
return false;
|
||||
}
|
||||
diff --git a/src/test/java/org/bukkit/TestServer.java b/src/test/java/org/bukkit/TestServer.java
|
||||
deleted file mode 100644
|
||||
index 701a17c10f31cd345238a3c568264178ce372faa..0000000000000000000000000000000000000000
|
||||
--- a/src/test/java/org/bukkit/TestServer.java
|
||||
+++ /dev/null
|
||||
@@ -1,139 +0,0 @@
|
||||
-package org.bukkit;
|
||||
-
|
||||
-import com.google.common.collect.ImmutableMap;
|
||||
-import java.lang.reflect.InvocationHandler;
|
||||
-import java.lang.reflect.Method;
|
||||
-import java.lang.reflect.Proxy;
|
||||
-import java.util.Iterator;
|
||||
-import java.util.Map;
|
||||
-import java.util.logging.Logger;
|
||||
-import org.bukkit.command.SimpleCommandMap;
|
||||
-import org.bukkit.plugin.PluginManager;
|
||||
-import org.bukkit.plugin.SimplePluginManager;
|
||||
-import org.jetbrains.annotations.NotNull;
|
||||
-import org.jetbrains.annotations.Nullable;
|
||||
-
|
||||
-public final class TestServer implements InvocationHandler {
|
||||
- private static interface MethodHandler {
|
||||
- Object handle(TestServer server, Object[] args);
|
||||
- }
|
||||
-
|
||||
- private static final Map<Method, MethodHandler> methods;
|
||||
-
|
||||
- static {
|
||||
- try {
|
||||
- ImmutableMap.Builder<Method, MethodHandler> methodMap = ImmutableMap.builder();
|
||||
- methodMap.put(
|
||||
- Server.class.getMethod("isPrimaryThread"),
|
||||
- new MethodHandler() {
|
||||
- @Override
|
||||
- public Object handle(TestServer server, Object[] args) {
|
||||
- return Thread.currentThread().equals(server.creatingThread);
|
||||
- }
|
||||
- }
|
||||
- );
|
||||
- methodMap.put(
|
||||
- Server.class.getMethod("getPluginManager"),
|
||||
- new MethodHandler() {
|
||||
- @Override
|
||||
- public Object handle(TestServer server, Object[] args) {
|
||||
- return server.pluginManager;
|
||||
- }
|
||||
- }
|
||||
- );
|
||||
- methodMap.put(
|
||||
- Server.class.getMethod("getLogger"),
|
||||
- new MethodHandler() {
|
||||
- final Logger logger = Logger.getLogger(TestServer.class.getCanonicalName());
|
||||
- @Override
|
||||
- public Object handle(TestServer server, Object[] args) {
|
||||
- return logger;
|
||||
- }
|
||||
- }
|
||||
- );
|
||||
- methodMap.put(
|
||||
- Server.class.getMethod("getName"),
|
||||
- new MethodHandler() {
|
||||
- @Override
|
||||
- public Object handle(TestServer server, Object[] args) {
|
||||
- return TestServer.class.getSimpleName();
|
||||
- }
|
||||
- }
|
||||
- );
|
||||
- methodMap.put(
|
||||
- Server.class.getMethod("getVersion"),
|
||||
- new MethodHandler() {
|
||||
- @Override
|
||||
- public Object handle(TestServer server, Object[] args) {
|
||||
- return "Version_" + TestServer.class.getPackage().getImplementationVersion();
|
||||
- }
|
||||
- }
|
||||
- );
|
||||
- methodMap.put(
|
||||
- Server.class.getMethod("getBukkitVersion"),
|
||||
- new MethodHandler() {
|
||||
- @Override
|
||||
- public Object handle(TestServer server, Object[] args) {
|
||||
- return "BukkitVersion_" + TestServer.class.getPackage().getImplementationVersion();
|
||||
- }
|
||||
- }
|
||||
- );
|
||||
- methodMap.put(
|
||||
- Server.class.getMethod("getRegistry", Class.class),
|
||||
- new MethodHandler() {
|
||||
- @Override
|
||||
- public Object handle(TestServer server, Object[] args) {
|
||||
- return new Registry() {
|
||||
- @NotNull
|
||||
- @Override
|
||||
- public Iterator iterator() {
|
||||
- return null;
|
||||
- }
|
||||
-
|
||||
- @Nullable
|
||||
- @Override
|
||||
- public Keyed get(@NotNull NamespacedKey key) {
|
||||
- return null;
|
||||
- }
|
||||
- };
|
||||
- }
|
||||
- }
|
||||
- );
|
||||
- methodMap.put(
|
||||
- Server.class.getMethod("getScoreboardCriteria", String.class),
|
||||
- new MethodHandler() {
|
||||
- @Override
|
||||
- public Object handle(TestServer server, Object[] args) {
|
||||
- // Does not need to return anything. Exists solely to test CriteriaTest which has static init fields
|
||||
- return null;
|
||||
- }
|
||||
- }
|
||||
- );
|
||||
- methods = methodMap.build();
|
||||
-
|
||||
- TestServer server = new TestServer();
|
||||
- Server instance = Proxy.getProxyClass(Server.class.getClassLoader(), Server.class).asSubclass(Server.class).getConstructor(InvocationHandler.class).newInstance(server);
|
||||
- Bukkit.setServer(instance);
|
||||
- server.pluginManager = new SimplePluginManager(instance, new SimpleCommandMap(instance));
|
||||
- } catch (Throwable t) {
|
||||
- throw new Error(t);
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- private Thread creatingThread = Thread.currentThread();
|
||||
- private PluginManager pluginManager;
|
||||
- private TestServer() {};
|
||||
-
|
||||
- public static Server getInstance() {
|
||||
- return Bukkit.getServer();
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public Object invoke(Object proxy, Method method, Object[] args) {
|
||||
- MethodHandler handler = methods.get(method);
|
||||
- if (handler != null) {
|
||||
- return handler.handle(this, args);
|
||||
- }
|
||||
- throw new UnsupportedOperationException(String.valueOf(method));
|
||||
- }
|
||||
-}
|
||||
diff --git a/src/test/java/org/bukkit/TestWorld.java b/src/test/java/org/bukkit/TestWorld.java
|
||||
index ab34f1199921d415fa2ca6e281a8125c9e6d7173..f64d024f5bbf9482aaddb56597b23b04c66f21bf 100644
|
||||
--- a/src/test/java/org/bukkit/TestWorld.java
|
||||
+++ b/src/test/java/org/bukkit/TestWorld.java
|
||||
@@ -18,7 +18,7 @@ public final class TestWorld implements InvocationHandler {
|
||||
|
||||
static {
|
||||
try {
|
||||
- TestServer.getInstance();
|
||||
+ io.papermc.paper.testing.TestServer.setup(); // Paper
|
||||
|
||||
ImmutableMap.Builder<Method, MethodHandler> methodMap = ImmutableMap.builder();
|
||||
methodMap.put(
|
||||
diff --git a/src/test/java/org/bukkit/event/SyntheticEventTest.java b/src/test/java/org/bukkit/event/SyntheticEventTest.java
|
||||
index d402cb59f508205ebe9ee450594826b04cecb90b..09886568ae6167141b463b6262565fa212af3385 100644
|
||||
--- a/src/test/java/org/bukkit/event/SyntheticEventTest.java
|
||||
+++ b/src/test/java/org/bukkit/event/SyntheticEventTest.java
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.bukkit.event;
|
||||
|
||||
-import org.bukkit.TestServer;
|
||||
import org.bukkit.plugin.PluginLoader;
|
||||
import org.bukkit.plugin.SimplePluginManager;
|
||||
import org.bukkit.plugin.TestPlugin;
|
||||
@@ -12,14 +11,15 @@ public class SyntheticEventTest {
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void test() {
|
||||
- final JavaPluginLoader loader = new JavaPluginLoader(TestServer.getInstance());
|
||||
+ io.papermc.paper.testing.TestServer.setup(); // Paper
|
||||
+ final JavaPluginLoader loader = new JavaPluginLoader(org.bukkit.Bukkit.getServer()); // Paper
|
||||
TestPlugin plugin = new TestPlugin(getClass().getName()) {
|
||||
@Override
|
||||
public PluginLoader getPluginLoader() {
|
||||
return loader;
|
||||
}
|
||||
};
|
||||
- SimplePluginManager pluginManager = new SimplePluginManager(TestServer.getInstance(), null);
|
||||
+ SimplePluginManager pluginManager = new SimplePluginManager(org.bukkit.Bukkit.getServer(), null); // Paper
|
||||
|
||||
TestEvent event = new TestEvent(false);
|
||||
Impl impl = new Impl();
|
||||
diff --git a/src/test/java/org/bukkit/plugin/PluginManagerTest.java b/src/test/java/org/bukkit/plugin/PluginManagerTest.java
|
||||
index f188cd4f3b07027c30d41f1162db77a506b7b6bb..c46ed2acb82db814d660459b705dd49e6d44240f 100644
|
||||
--- a/src/test/java/org/bukkit/plugin/PluginManagerTest.java
|
||||
+++ b/src/test/java/org/bukkit/plugin/PluginManagerTest.java
|
||||
@@ -2,7 +2,6 @@ package org.bukkit.plugin;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
-import org.bukkit.TestServer;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.TestEvent;
|
||||
import org.bukkit.permissions.Permission;
|
||||
@@ -14,7 +13,7 @@ public class PluginManagerTest {
|
||||
volatile Object value = null;
|
||||
}
|
||||
|
||||
- private static final PluginManager pm = TestServer.getInstance().getPluginManager();
|
||||
+ private static final PluginManager pm = org.bukkit.Bukkit.getServer().getPluginManager(); // Paper
|
||||
|
||||
private final MutableObject store = new MutableObject();
|
||||
|
||||
diff --git a/src/test/java/org/bukkit/scoreboard/CriteriaTest.java b/src/test/java/org/bukkit/scoreboard/CriteriaTest.java
|
||||
index eb94b6f4d58cd9f66b07791c57af7e359992e28c..a93f28e2f987a36e2c7e4f7d31506b750bdb222b 100644
|
||||
--- a/src/test/java/org/bukkit/scoreboard/CriteriaTest.java
|
||||
+++ b/src/test/java/org/bukkit/scoreboard/CriteriaTest.java
|
||||
@@ -2,7 +2,6 @@ package org.bukkit.scoreboard;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
-import org.bukkit.TestServer;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -11,7 +10,7 @@ public class CriteriaTest {
|
||||
|
||||
@Test
|
||||
public void testStatistic() {
|
||||
- TestServer.getInstance();
|
||||
+ io.papermc.paper.testing.TestServer.setup(); // Paper
|
||||
|
||||
Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, Material.STONE)); // Generic statistic with block
|
||||
Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, EntityType.CREEPER)); // Generic statistic with entity type
|
|
@ -7,7 +7,7 @@ Co-authored-by: zml <zml@stellardrift.ca>
|
|||
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
|
||||
diff --git a/build.gradle.kts b/build.gradle.kts
|
||||
index c2928c6f2d54de0ffde164fd9407085cf9fa18a6..c9f9174a085174b96897c013e0ecb79738c2e9e3 100644
|
||||
index d217f708b5bc57e402f4c2179ae3aea555b40f92..558fa62d87af1103efa703ef9114481cb928cf8d 100644
|
||||
--- a/build.gradle.kts
|
||||
+++ b/build.gradle.kts
|
||||
@@ -8,17 +8,37 @@ java {
|
||||
|
@ -49,7 +49,7 @@ index c2928c6f2d54de0ffde164fd9407085cf9fa18a6..c9f9174a085174b96897c013e0ecb797
|
|||
// Paper end
|
||||
|
||||
compileOnly("org.apache.maven:maven-resolver-provider:3.8.5")
|
||||
@@ -78,9 +98,24 @@ tasks.withType<Javadoc> {
|
||||
@@ -79,9 +99,24 @@ tasks.withType<Javadoc> {
|
||||
"https://guava.dev/releases/31.0.1-jre/api/docs/",
|
||||
"https://javadoc.io/doc/org.yaml/snakeyaml/1.33/",
|
||||
"https://javadoc.io/doc/org.jetbrains/annotations/23.0.0/", // Paper - we don't want Java 5 annotations
|
||||
|
|
|
@ -84,11 +84,11 @@ index 9f32b57464352c08617f6adec144111b8fcad50c..5af99aa87e6d4fbff81bd9de40484f4e
|
|||
RegisteredListener[] listeners = handlers.getRegisteredListeners();
|
||||
|
||||
diff --git a/src/test/java/org/bukkit/plugin/PluginManagerTest.java b/src/test/java/org/bukkit/plugin/PluginManagerTest.java
|
||||
index f188cd4f3b07027c30d41f1162db77a506b7b6bb..1941c9f49e9514c1236c5f4ea9f7af47f7be85c5 100644
|
||||
index c46ed2acb82db814d660459b705dd49e6d44240f..24dc87898e0fc40dfaf52f17a1bd26eccfbc7abc 100644
|
||||
--- a/src/test/java/org/bukkit/plugin/PluginManagerTest.java
|
||||
+++ b/src/test/java/org/bukkit/plugin/PluginManagerTest.java
|
||||
@@ -17,7 +17,7 @@ public class PluginManagerTest {
|
||||
private static final PluginManager pm = TestServer.getInstance().getPluginManager();
|
||||
@@ -16,7 +16,7 @@ public class PluginManagerTest {
|
||||
private static final PluginManager pm = org.bukkit.Bukkit.getServer().getPluginManager(); // Paper
|
||||
|
||||
private final MutableObject store = new MutableObject();
|
||||
-
|
||||
|
@ -96,7 +96,7 @@ index f188cd4f3b07027c30d41f1162db77a506b7b6bb..1941c9f49e9514c1236c5f4ea9f7af47
|
|||
@Test
|
||||
public void testAsyncSameThread() {
|
||||
final Event event = new TestEvent(true);
|
||||
@@ -28,14 +28,14 @@ public class PluginManagerTest {
|
||||
@@ -27,14 +27,14 @@ public class PluginManagerTest {
|
||||
return;
|
||||
}
|
||||
throw new IllegalStateException("No exception thrown");
|
||||
|
@ -113,7 +113,7 @@ index f188cd4f3b07027c30d41f1162db77a506b7b6bb..1941c9f49e9514c1236c5f4ea9f7af47
|
|||
@Test
|
||||
public void testAsyncLocked() throws InterruptedException {
|
||||
final Event event = new TestEvent(true);
|
||||
@@ -129,7 +129,7 @@ public class PluginManagerTest {
|
||||
@@ -128,7 +128,7 @@ public class PluginManagerTest {
|
||||
if (store.value == null) {
|
||||
throw new IllegalStateException("No exception thrown");
|
||||
}
|
||||
|
|
|
@ -1134,7 +1134,7 @@ index bceaa1a97b2c5cc15c8f54ae8f6f18029708627a..15699ee58e06880a508689f761ecfdb7
|
|||
public interface Tag<T extends Keyed> extends Keyed {
|
||||
diff --git a/src/test/java/com/destroystokyo/paper/MaterialTagsTest.java b/src/test/java/com/destroystokyo/paper/MaterialTagsTest.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..f849d8b12a7e3d1606698408ab4bb140a3b370e4
|
||||
index 0000000000000000000000000000000000000000..e541f29e983d8dcaca91de9ee1459d587226b4c3
|
||||
--- /dev/null
|
||||
+++ b/src/test/java/com/destroystokyo/paper/MaterialTagsTest.java
|
||||
@@ -0,0 +1,65 @@
|
||||
|
@ -1146,8 +1146,8 @@ index 0000000000000000000000000000000000000000..f849d8b12a7e3d1606698408ab4bb140
|
|||
+
|
||||
+import io.papermc.paper.tag.BaseTag;
|
||||
+import io.papermc.paper.tag.EntityTags;
|
||||
+import io.papermc.paper.testing.TestServer;
|
||||
+import org.bukkit.Bukkit;
|
||||
+import org.bukkit.TestServer;
|
||||
+import org.junit.Before;
|
||||
+import org.junit.Test;
|
||||
+
|
||||
|
@ -1163,7 +1163,7 @@ index 0000000000000000000000000000000000000000..f849d8b12a7e3d1606698408ab4bb140
|
|||
+
|
||||
+ @Before
|
||||
+ public void before() {
|
||||
+ TestServer.getInstance();
|
||||
+ TestServer.setup();
|
||||
+ }
|
||||
+
|
||||
+ @Test
|
||||
|
@ -1205,26 +1205,24 @@ index 0000000000000000000000000000000000000000..f849d8b12a7e3d1606698408ab4bb140
|
|||
+}
|
||||
diff --git a/src/test/java/io/papermc/paper/EntityTagsTest.java b/src/test/java/io/papermc/paper/EntityTagsTest.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..06bb9d1180361d3d00c699796bbacbce5bef2177
|
||||
index 0000000000000000000000000000000000000000..3caf03d8e50cd2180e9aac2dddeaa3afd0bf7438
|
||||
--- /dev/null
|
||||
+++ b/src/test/java/io/papermc/paper/EntityTagsTest.java
|
||||
@@ -0,0 +1,24 @@
|
||||
@@ -0,0 +1,22 @@
|
||||
+package io.papermc.paper;
|
||||
+
|
||||
+import com.destroystokyo.paper.MaterialTags;
|
||||
+import io.papermc.paper.tag.EntityTags;
|
||||
+import org.bukkit.Bukkit;
|
||||
+import org.bukkit.TestServer;
|
||||
+import org.junit.Test;
|
||||
+
|
||||
+import io.papermc.paper.testing.TestServer;
|
||||
+import java.util.logging.Level;
|
||||
+import org.bukkit.Bukkit;
|
||||
+import org.junit.Test;
|
||||
+
|
||||
+public class EntityTagsTest {
|
||||
+
|
||||
+ @Test
|
||||
+ public void testInitialize() {
|
||||
+ try {
|
||||
+ TestServer.getInstance();
|
||||
+ TestServer.setup();
|
||||
+ EntityTags.HORSES.getValues();
|
||||
+ assert true;
|
||||
+ } catch (Throwable e) {
|
||||
|
@ -1233,24 +1231,3 @@ index 0000000000000000000000000000000000000000..06bb9d1180361d3d00c699796bbacbce
|
|||
+ }
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/test/java/org/bukkit/TestServer.java b/src/test/java/org/bukkit/TestServer.java
|
||||
index 701a17c10f31cd345238a3c568264178ce372faa..bfb39f48bea14ad616c53e2a8a6901e93f728768 100644
|
||||
--- a/src/test/java/org/bukkit/TestServer.java
|
||||
+++ b/src/test/java/org/bukkit/TestServer.java
|
||||
@@ -32,6 +32,16 @@ public final class TestServer implements InvocationHandler {
|
||||
}
|
||||
}
|
||||
);
|
||||
+ // Paper start
|
||||
+ methodMap.put(
|
||||
+ Server.class.getMethod("getTag", String.class, NamespacedKey.class, Class.class),
|
||||
+ new MethodHandler() {
|
||||
+ public Object handle(TestServer server, Object[] args) {
|
||||
+ return new com.destroystokyo.paper.MaterialSetTag();
|
||||
+ }
|
||||
+ }
|
||||
+ );
|
||||
+ // Paper end
|
||||
methodMap.put(
|
||||
Server.class.getMethod("getPluginManager"),
|
||||
new MethodHandler() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue