@SuppressWarnings("unused") public static boolean doIdentityEquals(@This Object thiz, @Argument(0) Object other) { return thiz == other; } }
@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()); } } }
/** * @param method * @param id * @return * @throws Throwable */ public static Model findById(@Origin Method method, @Argument(0) Serializable id) throws Throwable { return invoke(method, new Class[] {Class.class, Serializable.class}, new Object[]{method.getDeclaringClass(), id}); }
/** * @param method * @param id * @return * @throws Throwable */ public static boolean exists(@Origin Method method, @Argument(0) Serializable id) throws Throwable { return invoke(method, new Class[] {Class.class, Serializable.class}, new Object[]{method.getDeclaringClass(), id}); }
/** * @param method * @param filter * @return * @throws Throwable */ public static long count(@Origin Method method, @Argument(0) Filter filter) throws Throwable { return invoke(method, new Class[] {Class.class, Filter.class}, new Object[]{method.getDeclaringClass(), filter}); }
/** * @param method * @param paramValues * @return * @throws Throwable */ public static Model one(@Origin Method method, @Argument(0) Object[] paramValues) throws Throwable { return invoke(method, new Class[] {Class.class, Object[].class}, new Object[]{method.getDeclaringClass(), paramValues}); }
/** * @param method * @param paramValues * @return * @throws Throwable */ public static Model first(@Origin Method method, @Argument(0) Object[] paramValues) throws Throwable { return invoke(method, new Class[] {Class.class, Object[].class}, new Object[]{method.getDeclaringClass(), paramValues}); }
/** * @param method * @param filter * @return * @throws Throwable */ public static List<Model> where(@Origin Method method, @Argument(0) Filter filter) throws Throwable { return invoke(method, new Class[] {Class.class, Filter.class}, new Object[]{method.getDeclaringClass(), filter}); }
/** * @param method * @param filter * @throws Throwable */ public static void deleteAll(@Origin Method method, @Argument(0) Filter filter) throws Throwable { invoke(method, new Class[] {Class.class, Filter.class}, new Object[]{method.getDeclaringClass(), filter}); }
/** * @param method * @param paramValues * @return * @throws Throwable */ public static List<Model> where(@Origin Method method, @Argument(0) Object[] paramValues) throws Throwable { return invoke(method, new Class[] {Class.class, Object[].class}, new Object[]{method.getDeclaringClass(), paramValues}); }
@RuntimeType public static Object intercept(@This Object thiz, @Argument(0) Object other, @FieldValue("bean") Object bean) throws IllegalAccessException, NoSuchFieldException { if (thiz == other) { return true; } else if (other instanceof EnhancedProxy) { return bean.equals(ReflectionUtils.getValue(other, "bean")); } else { return bean.equals(other); } } }
@RuntimeType public static void setProperty(@This final ElementFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final Object obj) { assert thiz instanceof CachesReflection; final Property annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Property.class); final String value = annotation.value(); if ((obj != null) && (obj.getClass().isEnum())) thiz.setProperty(value, ((Enum<?>) obj).name()); else thiz.setProperty(value, obj); } }
@RuntimeType public static void setProperty(@This final ElementFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final Object obj) { assert thiz instanceof CachesReflection; final Property annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Property.class); final String value = annotation.value(); if ((obj != null) && (obj.getClass().isEnum())) thiz.setProperty(value, ((Enum<?>) obj).name()); else thiz.setProperty(value, obj); } }
@RuntimeType public static Object addVertex(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final VertexFrame newVertex, @RuntimeType @Argument(1) final ClassInitializer edgeType) { assert thiz instanceof CachesReflection; final Incidence annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Incidence.class); final Direction direction = annotation.direction(); final String label = annotation.label(); switch (direction) { case BOTH: throw new IllegalStateException(method.getName() + " is annotated with direction BOTH, this is not allowed for add methods annotated with @Incidence."); case IN: return thiz.getGraph().addFramedEdge(newVertex, thiz, label, edgeType); case OUT: return thiz.getGraph().addFramedEdge(thiz, newVertex, label, edgeType); default: throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT."); } } }
@RuntimeType public static Object addVertex(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final VertexFrame newVertex, @RuntimeType @Argument(1) final ClassInitializer edgeType) { assert thiz instanceof CachesReflection; final Incidence annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Incidence.class); final Direction direction = annotation.direction(); final String label = annotation.label(); switch (direction) { case BOTH: throw new IllegalStateException(method.getName() + " is annotated with direction BOTH, this is not allowed for add methods annotated with @Incidence."); case IN: return thiz.getGraph().addFramedEdge(newVertex, thiz, label, edgeType); case OUT: return thiz.getGraph().addFramedEdge(thiz, newVertex, label, edgeType); default: throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT."); } } }
@RuntimeType public static void removeEdge(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final EdgeFrame edge) { edge.remove(); } }
@RuntimeType public static void removeEdge(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final EdgeFrame edge) { edge.remove(); } }
@RuntimeType public static Object addVertex(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final VertexFrame newVertex) { assert thiz instanceof CachesReflection; final Incidence annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Incidence.class); final Direction direction = annotation.direction(); final String label = annotation.label(); switch (direction) { case BOTH: throw new IllegalStateException(method.getName() + " is annotated with direction BOTH, this is not allowed for add methods annotated with @Incidence."); case IN: return thiz.getGraph().addFramedEdge(newVertex, thiz, label); case OUT: return thiz.getGraph().addFramedEdge(thiz, newVertex, label); default: throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT."); } } }
@RuntimeType public static List getEdges(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final Class type) { assert thiz instanceof CachesReflection; final Incidence annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Incidence.class); final Direction direction = annotation.direction(); final String label = annotation.label(); final TypeResolver resolver = thiz.getGraph().getTypeResolver(); switch (direction) { case BOTH: return thiz.traverse(input -> resolver.hasType(input.bothE(label), type)).toList(type); case IN: return thiz.traverse(input -> resolver.hasType(input.inE(label), type)).toList(type); case OUT: return thiz.traverse(input -> resolver.hasType(input.outE(label), type)).toList(type); default: throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT."); } } }
@RuntimeType public static List getEdges(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final Class type) { assert thiz instanceof CachesReflection; final Incidence annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Incidence.class); final Direction direction = annotation.direction(); final String label = annotation.label(); final TypeResolver resolver = thiz.getGraph().getTypeResolver(); switch (direction) { case BOTH: return thiz.traverse(input -> resolver.hasType(input.bothE(label), type)).toList(type); case IN: return thiz.traverse(input -> resolver.hasType(input.inE(label), type)).toList(type); case OUT: return thiz.traverse(input -> resolver.hasType(input.outE(label), type)).toList(type); default: throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT."); } } }