/** * Find method or throw exception. * * @param type the type * @param methodName the method name * @param parameterTypes the parameter types * @return the method */ @SuppressWarnings("all") public static Method findMethodOrThrowException(Class<?> type, String methodName, Class<?>... parameterTypes) { Method methodToMock = findMethod(type, methodName, parameterTypes); throwExceptionIfMethodWasNotFound(type, methodName, methodToMock, (Object[]) parameterTypes); return methodToMock; }
/** * Find method or throw exception. * * @param type * the type * @param methodName * the method name * @param parameterTypes * the parameter types * @return the method */ @SuppressWarnings("all") public static Method findMethodOrThrowException(Class<?> type, String methodName, Class<?>... parameterTypes) { Method methodToMock = findMethod(type, methodName, parameterTypes); throwExceptionIfMethodWasNotFound(type, methodName, methodToMock, parameterTypes); return methodToMock; }
/** * Get a method when it cannot be determined by methodName or parameter * types only. * <p> * The method will first try to look for a declared method in the same * class. If the method is not declared in this class it will look for the * method in the super class. This will continue throughout the whole class * hierarchy. If the method is not found an {@link IllegalArgumentException} * is thrown. * * @param declaringClass * The declaringClass of the class where the method is located. * @param methodName * The method names. * @param parameterTypes * All parameter types of the method (may be <code>null</code>). * @return A <code>java.lang.reflect.Method</code>. * @throws MethodNotFoundException * If a method cannot be found in the hierarchy. */ public static Method method(Class<?> declaringClass, String methodName, Class<?>... parameterTypes) { final Method method = WhiteboxImpl.findMethod(declaringClass, methodName, parameterTypes); WhiteboxImpl.throwExceptionIfMethodWasNotFound(declaringClass, methodName, method, (Object[]) parameterTypes); return method; }
/** * Get a method when it cannot be determined by methodName or parameter * types only. * <p> * The method will first try to look for a declared method in the same * class. If the method is not declared in this class it will look for the * method in the super class. This will continue throughout the whole class * hierarchy. If the method is not found an {@link IllegalArgumentException} * is thrown. * * @param declaringClass * The declaringClass of the class where the method is located. * @param methodName * The method names. * @param parameterTypes * All parameter types of the method (may be {@code null}). * @return A {@code java.lang.reflect.Method}. * @throws MethodNotFoundException * If a method cannot be found in the hierarchy. */ public static Method method(Class<?> declaringClass, String methodName, Class<?>... parameterTypes) { final Method method = WhiteboxImpl.findMethod(declaringClass, methodName, parameterTypes); WhiteboxImpl.throwExceptionIfMethodWasNotFound(declaringClass, methodName, method, (Object[]) parameterTypes); return method; }