public MethodProxy getMethodProxy() { if (methodProxy == null) methodProxy = MethodProxy.create(c1, c2, desc, name, superName); return methodProxy; } }
public SerializableMockitoMethodProxy(MethodProxy methodProxy) { Object info = Whitebox.getInternalState(methodProxy, "createInfo"); c1 = (Class<?>) Whitebox.getInternalState(info, "c1"); c2 = (Class<?>) Whitebox.getInternalState(info, "c2"); desc = methodProxy.getSignature().getDescriptor(); name = methodProxy.getSignature().getName(); superName = methodProxy.getSuperName(); this.methodProxy = methodProxy; }
@Override public Object invokeSuper(Object target, Object[] arguments) throws Throwable { return methodProxy.invokeSuper(target, arguments); } }
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { return proxy.invoke(target, args); } }
/** * Return the {@link org.mockito.cglib.reflect.FastClass} method index * for the method used by {@link #invokeSuper}. This index uniquely * identifies the method within the generated proxy, and therefore * can be useful to reference external metadata. * @see #getSuperName */ public int getSuperIndex() { init(); return fastClassInfo.i2; }
/** * For internal use by {@link Enhancer} only; see the {@link org.mockito.cglib.reflect.FastMethod} class * for similar functionality. */ public static MethodProxy create(Class c1, Class c2, String desc, String name1, String name2) { MethodProxy proxy = new MethodProxy(); proxy.sig1 = new Signature(name1, desc); proxy.sig2 = new Signature(name2, desc); proxy.createInfo = new CreateInfo(c1, c2); return proxy; }
private void init() { /* * Using a volatile invariant allows us to initialize the FastClass and * method index pairs atomically. * * Double-checked locking is safe with volatile in Java 5. Before 1.5 this * code could allow fastClassInfo to be instantiated more than once, which * appears to be benign. */ if (fastClassInfo == null) { synchronized (initLock) { if (fastClassInfo == null) { CreateInfo ci = createInfo; FastClassInfo fci = new FastClassInfo(); fci.f1 = helper(ci, ci.c1); fci.f2 = helper(ci, ci.c2); fci.i1 = fci.f1.getIndex(sig1); fci.i2 = fci.f2.getIndex(sig2); fastClassInfo = fci; } } } }
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { return proxy.invoke(target, args); } }
/** * Invoke the original (super) method on the specified object. * @param obj the enhanced object, must be the object passed as the first * argument to the MethodInterceptor * @param args the arguments passed to the intercepted method; you may substitute a different * argument array as long as the types are compatible * @see MethodInterceptor#intercept * @throws Throwable the bare exceptions thrown by the called method are passed through * without wrapping in an <code>InvocationTargetException</code> */ public Object invokeSuper(Object obj, Object[] args) throws Throwable { try { init(); FastClassInfo fci = fastClassInfo; return fci.f2.invoke(fci.i2, obj, args); } catch (InvocationTargetException e) { throw e.getTargetException(); } } }
/** * For internal use by {@link Enhancer} only; see the {@link org.mockito.cglib.reflect.FastMethod} class * for similar functionality. */ public static MethodProxy create(Class c1, Class c2, String desc, String name1, String name2) { MethodProxy proxy = new MethodProxy(); proxy.sig1 = new Signature(name1, desc); proxy.sig2 = new Signature(name2, desc); proxy.createInfo = new CreateInfo(c1, c2); return proxy; }
private void init() { /* * Using a volatile invariant allows us to initialize the FastClass and * method index pairs atomically. * * Double-checked locking is safe with volatile in Java 5. Before 1.5 this * code could allow fastClassInfo to be instantiated more than once, which * appears to be benign. */ if (fastClassInfo == null) { synchronized (initLock) { if (fastClassInfo == null) { CreateInfo ci = createInfo; FastClassInfo fci = new FastClassInfo(); fci.f1 = helper(ci, ci.c1); fci.f2 = helper(ci, ci.c2); fci.i1 = fci.f1.getIndex(sig1); fci.i2 = fci.f2.getIndex(sig2); fastClassInfo = fci; } } } }
public SerializableMockitoMethodProxy(MethodProxy methodProxy) { assert methodProxy != null; Object info = Whitebox.getInternalState(methodProxy, "createInfo"); c1 = (Class<?>) Whitebox.getInternalState(info, "c1"); c2 = (Class<?>) Whitebox.getInternalState(info, "c2"); desc = methodProxy.getSignature().getDescriptor(); name = methodProxy.getSignature().getName(); superName = methodProxy.getSuperName(); this.methodProxy = methodProxy; }
@Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { beforeInvocation(); cglibHacker.setMockitoNamingPolicy(new DelegatingMockitoMethodProxy( proxy)); try { Object retval = proxy.invoke(target, args); return afterInvocation(retval); } catch (Exception e) { return afterInvocationThrowsException(e, method); } } }
public Object invokeSuper(Object target, Object[] arguments) throws Throwable { return getMethodProxy().invokeSuper(target, arguments); } }
private MethodProxy getMethodProxy() { if (methodProxy == null) { methodProxy = MethodProxy.create(c1, c2, desc, name, superName); } return methodProxy; }
/** * Invoke the original method, on a different object of the same type. * @param obj the compatible object; recursion will result if you use the object passed as the first * argument to the MethodInterceptor (usually not what you want) * @param args the arguments passed to the intercepted method; you may substitute a different * argument array as long as the types are compatible * @see MethodInterceptor#intercept * @throws Throwable the bare exceptions thrown by the called method are passed through * without wrapping in an <code>InvocationTargetException</code> */ public Object invoke(Object obj, Object[] args) throws Throwable { try { init(); FastClassInfo fci = fastClassInfo; return fci.f1.invoke(fci.i1, obj, args); } catch (InvocationTargetException e) { throw e.getTargetException(); } catch (IllegalArgumentException e) { if (fastClassInfo.i1 < 0) throw new IllegalArgumentException("Protected method: " + sig1); throw e; } }
public SerializableMockitoMethodProxy(MethodProxy methodProxy) { Object info = Whitebox.getInternalState(methodProxy, "createInfo"); c1 = (Class<?>) Whitebox.getInternalState(info, "c1"); c2 = (Class<?>) Whitebox.getInternalState(info, "c2"); desc = methodProxy.getSignature().getDescriptor(); name = methodProxy.getSignature().getName(); superName = methodProxy.getSuperName(); this.methodProxy = methodProxy; }
@Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { beforeInvocation(); cglibHacker.setMockitoNamingPolicy(new DelegatingMockitoMethodProxy( proxy)); try { Object retval = proxy.invoke(target, args); return afterInvocation(retval); } catch (Throwable e) { return afterInvocationThrowsThrowable(e, method); } } }
@Override public Object invokeSuper(Object target, Object[] arguments) throws Throwable { return getMethodProxy().invokeSuper(target, arguments); } }
public MethodProxy getMethodProxy() { if (methodProxy == null) methodProxy = MethodProxy.create(c1, c2, desc, name, superName); return methodProxy; } }