X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftest%2FTestUtil.java;h=745733f5b76f7051eea8676d09348e2b48b5c1ed;hp=22c2057ebd69763732843489d9c468a75a5f0123;hb=5201720801a4053f8f324b71fb3e9c36f6cd911e;hpb=a463041b2e85ed6202681dcd19955a24e9528174 diff --git a/src/test/java/net/pterodactylus/sone/test/TestUtil.java b/src/test/java/net/pterodactylus/sone/test/TestUtil.java index 22c2057..745733f 100644 --- a/src/test/java/net/pterodactylus/sone/test/TestUtil.java +++ b/src/test/java/net/pterodactylus/sone/test/TestUtil.java @@ -1,15 +1,20 @@ package net.pterodactylus.sone.test; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import kotlin.Deprecated; +import kotlin.ReplaceWith; + /** * Utilities for testing. */ public class TestUtil { + @Deprecated(message = "It only checks the given class, not its superclasses.", replaceWith = @ReplaceWith(imports = { "net.pterodactylus.sone.test" }, expression = "setField(`object`, fieldName, value)")) public static void setFinalField(Object object, String fieldName, Object value) { try { Field clientCoreField = object.getClass().getField(fieldName); @@ -43,4 +48,14 @@ public class TestUtil { } } + public static T createObject(Class clazz, Class[] parameterTypes, Object... arguments) { + try { + Constructor constructor = clazz.getDeclaredConstructor(parameterTypes); + constructor.setAccessible(true); + return constructor.newInstance(arguments); + } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } + }