From 2cacd71d0561c205127d0621f91895a5ca3e0a74 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 2 Nov 2014 10:32:41 +0100 Subject: [PATCH] Add method to call private or otherwise non-accessible getters. --- src/test/java/net/pterodactylus/sone/TestUtil.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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); + } + } + } -- 2.7.4