@SuppressWarnings("unused") public static int doIdentityHashCode(@This Object thiz) { return System.identityHashCode(thiz); } }
@SuppressWarnings("unused") public static boolean doIdentityEquals(@This Object thiz, @Argument(0) Object other) { return thiz == other; } }
@RuntimeType public static Object intercept( @Origin Method method, @AllArguments Object[] args, @This Object me, @FieldValue("liveObjectLiveMap") RMap<?, ?> map ) throws Exception { if (args.length >= 1 && String.class.isAssignableFrom(args[0].getClass())) { String name = ((String) args[0]).substring(0, 1).toUpperCase() + ((String) args[0]).substring(1); if ("get".equals(method.getName()) && args.length == 1) { try { return me.getClass().getMethod("get" + name).invoke(me); } catch (NoSuchMethodException noSuchMethodException) { throw new NoSuchFieldException((String) args[0]); } } else if ("set".equals(method.getName()) && args.length == 2) { Method m = ClassUtils.searchForMethod(me.getClass(), "set" + name, new Class[]{args[1].getClass()}); if (m != null) { return m.invoke(me, args[1]); } else { throw new NoSuchFieldException((String) args[0]); } } } throw new NoSuchMethodException(method.getName() + " has wrong signature"); } }
@RuntimeType public static Object intercept( @Origin Method method, @AllArguments Object[] args, @This Object me, @FieldValue("liveObjectLiveMap") RMap<?, ?> map ) throws Exception { if (args.length >= 1 && String.class.isAssignableFrom(args[0].getClass())) { String name = ((String) args[0]).substring(0, 1).toUpperCase() + ((String) args[0]).substring(1); if ("get".equals(method.getName()) && args.length == 1) { try { return me.getClass().getMethod("get" + name).invoke(me); } catch (NoSuchMethodException noSuchMethodException) { throw new NoSuchFieldException((String) args[0]); } } else if ("set".equals(method.getName()) && args.length == 2) { Method m = ClassUtils.searchForMethod(me.getClass(), "set" + name, new Class[]{args[1].getClass()}); if (m != null) { return m.invoke(me, args[1]); } else { throw new NoSuchFieldException((String) args[0]); } } } throw new NoSuchMethodException(method.getName() + " has wrong signature"); } }
@RuntimeType public static Object intercept(@This AbstractAssert<?, ?> assertion, @SuperCall Callable<Object> proxy) throws Exception { try { Object result = proxy.call(); if (result != assertion && result instanceof AbstractAssert) { return asAssumption((AbstractAssert<?, ?>) result).withAssertionState(assertion); } return result; } catch (AssertionError e) { throw assumptionNotMet(e); } } }
public static Object doWriteReplace(@This MockAccess thiz) throws ObjectStreamException { return thiz.getMockitoInterceptor().getSerializationSupport().writeReplace(thiz); } }
@SuppressWarnings("unused") public static void doReadObject(@Identifier String identifier, @This MockAccess thiz, @Argument(0) ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { objectInputStream.defaultReadObject(); MockMethodAdvice mockMethodAdvice = (MockMethodAdvice) MockMethodDispatcher.get(identifier, thiz); if (mockMethodAdvice != null) { mockMethodAdvice.interceptors.put(thiz, thiz.getMockitoInterceptor()); } } }
@RuntimeType public static Object intercept(@This AbstractAssert<?, ?> assertion, @SuperCall Callable<Object> proxy) throws Exception { try { Object result = proxy.call(); if (result != assertion && result instanceof AbstractAssert) { return asAssumption((AbstractAssert<?, ?>) result).withAssertionState(assertion); } return result; } catch (AssertionError e) { throw assumptionNotMet(e); } } }
/** * Intercepts a method call to a proxy. * * @param instance The proxied instance. * @param method The invoked method. * @param arguments The intercepted method arguments. * * @return The method's return value. * * @throws Throwable If the intercepted method raises an exception. */ @RuntimeType Object intercept(@This Object instance, @Origin Method method, @AllArguments Object[] arguments) throws Throwable; }
@RuntimeType public static AbstractAssert<?, ?> intercept(@FieldValue(FIELD_NAME) ProxifyMethodChangingTheObjectUnderTest dispatcher, @SuperCall Callable<AbstractAssert<?, ?>> assertionMethod, @This AbstractAssert<?, ?> currentAssertInstance) throws Exception { Object result = assertionMethod.call(); return dispatcher.createAssertProxy(result).withAssertionState(currentAssertInstance); }
@RuntimeType public static AbstractAssert<?, ?> intercept(@FieldValue(FIELD_NAME) ProxifyMethodChangingTheObjectUnderTest dispatcher, @SuperCall Callable<AbstractAssert<?, ?>> assertionMethod, @This AbstractAssert<?, ?> currentAssertInstance) throws Exception { Object result = assertionMethod.call(); return dispatcher.createAssertProxy(result).withAssertionState(currentAssertInstance); }
@This Object assertion, @SuperCall Callable<?> proxy, @SuperMethod(nullIfImpossible = true) Method method,
@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) ); }
@SuppressWarnings("unused") @RuntimeType public static Object interceptAbstract(@This Object mock, @FieldValue("mockitoInterceptor") MockMethodInterceptor interceptor, @StubValue Object stubValue, @Origin Method invokedMethod, @AllArguments Object[] arguments) throws Throwable { if (interceptor == null) { return stubValue; } return interceptor.doIntercept( mock, invokedMethod, arguments, RealMethod.IsIllegal.INSTANCE ); } }
@This final Object instance, @Origin final Method method, @AllArguments final Object[] arguments,
@Origin Method method, @AllArguments Object[] args, @This Object me, @FieldValue("liveObjectId") Object id, @FieldProxy("liveObjectId") Setter idSetter,
@Origin Method method, @AllArguments Object[] args, @This Object me, @FieldValue("liveObjectId") Object id, @FieldProxy("liveObjectId") Setter idSetter,
@RuntimeType public Object intercept(@Origin Method method, @SuperCall Callable<?> superMethod, @AllArguments Object[] args, @This Object me, @FieldValue("liveObjectLiveMap") RMap<String, Object> liveMap) throws Exception { if (isGetter(method, getREntityIdFieldName(me))) {
@RuntimeType public static Object interceptAbstract(@FieldValue("$spock_interceptor") IProxyBasedMockInterceptor proxyBasedMockInterceptor, @This Object self, @AllArguments Object[] arguments, @Origin Method method, @StubValue Object stubValue) throws Exception { Object returnValue; if (proxyBasedMockInterceptor == null) { returnValue = null; // Call before interceptor was set (constructor). } else { returnValue = proxyBasedMockInterceptor.intercept(self, method, arguments, new ByteBuddyMethodInvoker(null)); } return returnValue == null ? stubValue : returnValue; }
@RuntimeType public static Object interceptNonAbstract(@FieldValue("$spock_interceptor") IProxyBasedMockInterceptor proxyBasedMockInterceptor, @Morph ByteBuddyInvoker invoker, @This Object self, @AllArguments Object[] arguments, @Origin Method method, @StubValue Object stubValue) throws Exception { Object returnValue; if (proxyBasedMockInterceptor == null) { returnValue = invoker.call(arguments); // Call before interceptor was set (constructor). } else { returnValue = proxyBasedMockInterceptor.intercept(self, method, arguments, new ByteBuddyMethodInvoker(invoker)); } return returnValue == null ? stubValue : returnValue; }