@SuppressWarnings("unchecked") private static <T> IExpectationSetters<T> doExpectPrivate(Object instance, Method methodToExpect, Object... arguments) throws Exception { WhiteboxImpl.performMethodInvocation(instance, methodToExpect, arguments); return (IExpectationSetters<T>) org.easymock.classextension.EasyMock.expectLastCall(); }
/** * Do invoke method. * * @param <T> the generic type * @param tested the tested * @param declaringClass the declaring class * @param methodToExecute the method to execute * @param arguments the arguments * @return the t * @throws Exception the exception */ @SuppressWarnings("unchecked") private static <T> T doInvokeMethod(Object tested, Class<?> declaringClass, String methodToExecute, Object... arguments) throws Exception { Method methodToInvoke = findMethodOrThrowException(tested, declaringClass, methodToExecute, arguments); // Invoke test return (T) performMethodInvocation(tested, methodToInvoke, arguments); }
/** * Invoke a private method in that is located in a subclass of an instance. * This might be useful to test overloaded private methods. * * Use this for overloaded methods only, if possible use * * @param <T> the generic type * @param object the object * @param declaringClass the declaring class * @param methodToExecute the method to execute * @param parameterTypes the parameter types * @param arguments the arguments * @return the t * @throws Exception Exception that may occur when invoking this method. * {@link #invokeMethod(Object, Object...)} or * {@link #invokeMethod(Object, String, Object...)} instead. */ @SuppressWarnings("unchecked") public static synchronized <T> T invokeMethod(Object object, Class<?> declaringClass, String methodToExecute, Class<?>[] parameterTypes, Object... arguments) throws Exception { if (object == null) { throw new IllegalArgumentException("object cannot be null"); } final Method methodToInvoke = getMethod(declaringClass, methodToExecute, parameterTypes); // Invoke method return (T) performMethodInvocation(object, methodToInvoke, arguments); }
/** * Do invoke method. * * @param <T> * the generic type * @param tested * the tested * @param declaringClass * the declaring class * @param methodToExecute * the method to execute * @param arguments * the arguments * @return the t * @throws Exception * the exception */ @SuppressWarnings("unchecked") private static <T> T doInvokeMethod(Object tested, Class<?> declaringClass, String methodToExecute, Object... arguments) throws Exception { Method methodToInvoke = findMethodOrThrowException(tested, declaringClass, methodToExecute, arguments); // Invoke test return (T) performMethodInvocation(tested, methodToInvoke, arguments); }
return (T) performMethodInvocation(object, methodToInvoke, arguments);
/** * Invoke a private or inner class method in a subclass (defined by * {@code definedIn}) in cases where power mock cannot automatically * determine the type of the parameters, for example when mixing primitive * types and wrapper types in the same method. For most situations use * * @param <T> the generic type * @param tested the tested * @param methodToExecute the method to execute * @param definedIn the defined in * @param argumentTypes the argument types * @param arguments the arguments * @return the t * @throws Exception Exception that may occur when invoking this method. * {@link #invokeMethod(Class, String, Object...)} instead. */ @SuppressWarnings("unchecked") public static synchronized <T> T invokeMethod(Object tested, String methodToExecute, Class<?> definedIn, Class<?>[] argumentTypes, Object... arguments) throws Exception { Method method = getMethod(definedIn, methodToExecute, argumentTypes); if (method == null) { throwExceptionIfMethodWasNotFound(definedIn, methodToExecute, null, arguments); } return (T) performMethodInvocation(tested, method, arguments); }
throwExceptionIfMethodWasNotFound(definedIn, methodToExecute, null, arguments); return (T) performMethodInvocation(tested, method, arguments);
/** * Invoke a private or inner class method in cases where power mock cannot * automatically determine the type of the parameters, for example when * mixing primitive types and wrapper types in the same method. For most * situations use {@link #invokeMethod(Class, String, Object...)} instead. * * @param <T> the generic type * @param tested the tested * @param methodToExecute the method to execute * @param argumentTypes the argument types * @param arguments the arguments * @return the t * @throws Exception Exception that may occur when invoking this method. */ @SuppressWarnings("unchecked") public static synchronized <T> T invokeMethod(Object tested, String methodToExecute, Class<?>[] argumentTypes, Object... arguments) throws Exception { final Class<?> unmockedType = getType(tested); Method method = getMethod(unmockedType, methodToExecute, argumentTypes); if (method == null) { throwExceptionIfMethodWasNotFound(unmockedType, methodToExecute, null, arguments); } return (T) performMethodInvocation(tested, method, arguments); }
/** * Invoke a private or inner class method in cases where power mock cannot * automatically determine the type of the parameters, for example when * mixing primitive types and wrapper types in the same method. For most * situations use {@link #invokeMethod(Class, String, Object...)} instead. * * @param <T> * the generic type * @param tested * the tested * @param methodToExecute * the method to execute * @param argumentTypes * the argument types * @param arguments * the arguments * @return the t * @throws Exception * Exception that may occur when invoking this method. */ @SuppressWarnings("unchecked") public static synchronized <T> T invokeMethod(Object tested, String methodToExecute, Class<?>[] argumentTypes, Object... arguments) throws Exception { final Class<?> unmockedType = getType(tested); Method method = getMethod(unmockedType, methodToExecute, argumentTypes); if (method == null) { throwExceptionIfMethodWasNotFound(unmockedType, methodToExecute, null, arguments); } return (T) performMethodInvocation(tested, method, arguments); }