@SuppressWarnings("unused") @RuntimeType @BindingPriority(BindingPriority.DEFAULT * 2) public static Object interceptSuperCallable(@This Object mock, @FieldValue("mockitoInterceptor") MockMethodInterceptor interceptor, @Origin Method invokedMethod, @AllArguments Object[] arguments, @SuperCall(serializableProxy = true) Callable<?> superCall) throws Throwable { if (interceptor == null) { return superCall.call(); } return interceptor.doIntercept( mock, invokedMethod, arguments, new RealMethod.FromCallable(superCall) ); }
/** * Resolves the explicitly stated binding priority of a method or returns the default value if no such * explicit information can be found. * * @param bindingPriority The annotation of the method or {@code null} if no such annotation was found. * @return The factual priority of the method under investigation. */ private static int resolve(AnnotationDescription.Loadable<BindingPriority> bindingPriority) { return bindingPriority == null ? BindingPriority.DEFAULT : bindingPriority.loadSilent().value(); }
@RuntimeType @BindingPriority(BindingPriority.DEFAULT * 2) public static Object intercept(@ProxyAdviceId long id, @This Object self, @Origin Method method, @AllArguments Object[] args, @SuperCall final Callable<Object> originalMethod) throws Throwable { JvmMockKDispatcher dispatcher = get(id, self); if (dispatcher == null) { return originalMethod.call(); } return dispatcher.handle(self, method, args, originalMethod); }
@RuntimeType @BindingPriority( BindingPriority.DEFAULT * 3 ) public Object interceptSuper( @SuperCall final Callable<?> zuper, @This final Object receiver, @Origin Method method, @AllArguments final Object[] parameters, @FieldProxy( INTERCEPTOR_FIELD_NAME ) StepInterceptorGetterSetter stepInterceptorGetter ) throws Throwable { StepInterceptor interceptor = (StepInterceptor) stepInterceptorGetter.getValue(); if( interceptor == null ) { return zuper.call(); } Invoker invoker = new Invoker() { @Override public Object proceed() throws Throwable { return zuper.call(); } }; return interceptor.intercept( receiver, method, parameters, invoker ); }
@RuntimeType @BindingPriority( BindingPriority.DEFAULT * 2 ) public Object interceptDefault( @DefaultCall final Callable<?> zuper, @This final Object receiver, @Origin Method method, @AllArguments final Object[] parameters, @FieldProxy( INTERCEPTOR_FIELD_NAME ) StepInterceptorGetterSetter stepInterceptorGetter ) throws Throwable { StepInterceptor interceptor = (StepInterceptor) stepInterceptorGetter.getValue(); if( interceptor == null ) { return zuper.call(); } Invoker invoker = new Invoker() { @Override public Object proceed() throws Throwable { return zuper.call(); } }; return interceptor.intercept( receiver, method, parameters, invoker ); }
@RuntimeType @BindingPriority(BindingPriority.DEFAULT * 2) public static Object intercept(@This Object self, @Origin Method method, @AllArguments Object[] args, @SuperCall final Callable<Object> originalMethod) throws Throwable { MockKInvocationHandler handler = MockKInstrumentation.INSTANCE.getHook(self); if (handler == null || MockKSelfCall.isSelf(self, method)) { return originalMethod.call(); } return handler.invocation( self, method, new MockKSkipInterceptingSelf(originalMethod, self, method), args); }