ReflectionHelper { static public <T> Object invokeParameterlessMethod(T theObject, String methodName) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Method method = theObject.getClass().getDeclaredMethod(methodName, null); method.setAccessible(true); return method.invoke(theObject, null); }  static Object invokeParameterlessMethod(T theObject, String methodName);  }
@Test(timeOut = 1_000) public void testReflectionWorksForAPrivateMethodReturningAnInt() throws Exception { final int expectedInt = 10; TestClass testClass = new TestClass(expectedInt); int result = (int) ReflectionHelper.invokeParameterlessMethod(testClass, "getTheNumber"); assertEquals(result, expectedInt); }