001
014
015 package com.liferay.portal.test.aspects;
016
017 import com.liferay.portal.kernel.util.ReflectionUtil;
018
019 import org.aspectj.lang.ProceedingJoinPoint;
020 import org.aspectj.lang.annotation.Around;
021 import org.aspectj.lang.annotation.Aspect;
022
023
026 @Aspect
027 public class ReflectionUtilAdvice {
028
029 public static void setDeclaredFieldThrowable(
030 Throwable declaredFieldThrowable) {
031
032 _declaredFieldThrowable = declaredFieldThrowable;
033 }
034
035 public static void setDeclaredMethodThrowable(
036 Throwable declaredMethodThrowable)
037 throws ClassNotFoundException {
038
039 Class.forName(
040 ReflectionUtil.class.getName(), true,
041 ReflectionUtil.class.getClassLoader());
042
043 _declaredMethodThrowable = declaredMethodThrowable;
044 }
045
046 @Around(
047 "execution(public static java.lang.reflect.Field " +
048 "com.liferay.portal.kernel.util.ReflectionUtil." +
049 "getDeclaredField(Class, String))"
050 )
051 public Object getDeclaredField(ProceedingJoinPoint proceedingJoinPoint)
052 throws Throwable {
053
054 if (_declaredFieldThrowable != null) {
055 throw _declaredFieldThrowable;
056 }
057
058 return proceedingJoinPoint.proceed();
059 }
060
061 @Around(
062 "execution(public static java.lang.reflect.Method " +
063 "com.liferay.portal.kernel.util.ReflectionUtil." +
064 "getDeclaredMethod(Class, String, Class...))"
065 )
066 public Object getDeclaredMethod(ProceedingJoinPoint proceedingJoinPoint)
067 throws Throwable {
068
069 if (_declaredMethodThrowable != null) {
070 throw _declaredMethodThrowable;
071 }
072
073 return proceedingJoinPoint.proceed();
074 }
075
076 private static Throwable _declaredFieldThrowable;
077 private static Throwable _declaredMethodThrowable;
078
079 }