From: David ‘Bombe’ Roden Date: Sun, 2 Nov 2014 09:32:41 +0000 (+0100) Subject: Add method to call private or otherwise non-accessible getters. X-Git-Tag: 0.9-rc1^2~3^2~62 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=2cacd71d0561c205127d0621f91895a5ca3e0a74;p=Sone.git Add method to call private or otherwise non-accessible getters. --- diff --git a/src/test/java/net/pterodactylus/sone/TestUtil.java b/src/test/java/net/pterodactylus/sone/TestUtil.java index d1a4d04..fa7879d 100644 --- a/src/test/java/net/pterodactylus/sone/TestUtil.java +++ b/src/test/java/net/pterodactylus/sone/TestUtil.java @@ -1,6 +1,8 @@ package net.pterodactylus.sone; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.lang.reflect.Modifier; /** @@ -37,4 +39,18 @@ public class TestUtil { } } + 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); + } + } + }