/** * Add a proxy for this method. Each call to the method will be routed to * the invocationHandler instead. */ public static void proxy(Method method, InvocationHandler invocationHandler) { assertInvocationHandlerNotNull(invocationHandler); MockRepository.putMethodProxy(method, invocationHandler); }
/** * Add a proxy for this method. Each call to the method will be routed to * the invocationHandler instead. */ public static void proxy(Method method, InvocationHandler invocationHandler) { assertInvocationHandlerNotNull(invocationHandler); MockRepository.putMethodProxy(method, invocationHandler); }
/** * Add a proxy for a method declared in class {@code declaringClass}. * Each call to the method will be routed to the invocationHandler instead. */ public static void proxy(Class<?> declaringClass, String methodName, InvocationHandler invocationHandler) { assertInvocationHandlerNotNull(invocationHandler); if (declaringClass == null) { throw new IllegalArgumentException("declaringClass cannot be null"); } if (methodName == null || methodName.length() == 0) { throw new IllegalArgumentException("methodName cannot be empty"); } Method[] methods = Whitebox.getMethods(declaringClass, methodName); if (methods.length == 0) { throw new MethodNotFoundException(String.format("Couldn't find a method with name %s in the class hierarchy of %s", methodName, declaringClass.getName())); } else if (methods.length > 1) { throw new TooManyMethodsFoundException(String.format("Found %d methods with name %s in the class hierarchy of %s.", methods.length, methodName, declaringClass.getName())); } MockRepository.putMethodProxy(methods[0], invocationHandler); }
/** * Add a proxy for a method declared in class <code>declaringClass</code>. * Each call to the method will be routed to the invocationHandler instead. */ public static void proxy(Class<?> declaringClass, String methodName, InvocationHandler invocationHandler) { assertInvocationHandlerNotNull(invocationHandler); if (declaringClass == null) { throw new IllegalArgumentException("declaringClass cannot be null"); } if (methodName == null || methodName.length() == 0) { throw new IllegalArgumentException("methodName cannot be empty"); } Method[] methods = Whitebox.getMethods(declaringClass, methodName); if (methods.length == 0) { throw new MethodNotFoundException(String.format("Couldn't find a method with name %s in the class hierarchy of %s", methodName, declaringClass.getName())); } else if (methods.length > 1) { throw new TooManyMethodsFoundException(String.format("Found %d methods with name %s in the class hierarchy of %s.", methods.length, methodName, declaringClass.getName())); } MockRepository.putMethodProxy(methods[0], invocationHandler); }
@SuppressWarnings("unused") private void initializeInterceptionSettings() { MockPolicyInterceptionSettings interceptionSettings = getInterceptionSettings(); for (Method method : interceptionSettings.getMethodsToSuppress()) { MockRepository.addMethodToSuppress(method); } for (Entry<Method, InvocationHandler> entry : interceptionSettings.getProxiedMethods().entrySet()) { MockRepository.putMethodProxy(entry.getKey(), entry.getValue()); } for (Entry<Method, Object> entry : interceptionSettings.getStubbedMethods().entrySet()) { final Method method = entry.getKey(); final Object className = entry.getValue(); MockRepository.putMethodToStub(method, className); } for (Field field : interceptionSettings.getFieldsToSuppress()) { MockRepository.addFieldToSuppress(field); } for (String type : interceptionSettings.getFieldTypesToSuppress()) { MockRepository.addFieldTypeToSuppress(type); } }
/** * {@link #noMockito} is wrapped into it's own static class to make sure it is initialized not earlier than * {@link #calledFromMockito()} is called for the first time. */ private static final class NoMockito { static final boolean noMockito = Package.getPackage("org.mockito") == null; private NoMockito() {} } public static final Object PROCEED = new Object();