X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2FTestUtil.java;fp=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2FTestUtil.java;h=0000000000000000000000000000000000000000;hp=fa7879dd9a03c2911dcf56402a15d0e62acf2c44;hb=eb32457356fac09e16ec98394c1b5d48f9dfba84;hpb=ec655d61682a70063c1cf540fe3e41613aaf71a5 diff --git a/src/test/java/net/pterodactylus/sone/TestUtil.java b/src/test/java/net/pterodactylus/sone/TestUtil.java deleted file mode 100644 index fa7879d..0000000 --- a/src/test/java/net/pterodactylus/sone/TestUtil.java +++ /dev/null @@ -1,56 +0,0 @@ -package net.pterodactylus.sone; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -/** - * Utilities for testing. - * - * @author David ‘Bombe’ Roden - */ -public class TestUtil { - - public static void setFinalField(Object object, String fieldName, Object value) { - try { - Field clientCoreField = object.getClass().getField(fieldName); - clientCoreField.setAccessible(true); - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(clientCoreField, clientCoreField.getModifiers() & ~Modifier.FINAL); - clientCoreField.set(object, value); - } catch (NoSuchFieldException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - - public static T getPrivateField(Object object, String fieldName) { - try { - Field field = object.getClass().getDeclaredField(fieldName); - field.setAccessible(true); - return (T) field.get(object); - } catch (NoSuchFieldException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - - public static T callPrivateMethod(Object object, String methodName) { - try { - Method method = object.getClass().getDeclaredMethod(methodName, new Class[0]); - method.setAccessible(true); - return (T) method.invoke(object); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - -}