diff --git a/spring-aop/src/main/java/org/springframework/aop/MethodMatcher.java b/spring-aop/src/main/java/org/springframework/aop/MethodMatcher.java index 15526c1fc8..7cba7648cf 100644 --- a/spring-aop/src/main/java/org/springframework/aop/MethodMatcher.java +++ b/spring-aop/src/main/java/org/springframework/aop/MethodMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -86,7 +86,7 @@ public interface MethodMatcher { * @return whether there's a runtime match * @see MethodMatcher#matches(Method, Class) */ - boolean matches(Method method, Class targetClass, Object[] args); + boolean matches(Method method, Class targetClass, Object... args); /** diff --git a/spring-aop/src/main/java/org/springframework/aop/TrueMethodMatcher.java b/spring-aop/src/main/java/org/springframework/aop/TrueMethodMatcher.java index 0b82427e8b..cf21e97c91 100644 --- a/spring-aop/src/main/java/org/springframework/aop/TrueMethodMatcher.java +++ b/spring-aop/src/main/java/org/springframework/aop/TrueMethodMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,12 +29,14 @@ class TrueMethodMatcher implements MethodMatcher, Serializable { public static final TrueMethodMatcher INSTANCE = new TrueMethodMatcher(); + /** * Enforce Singleton pattern. */ private TrueMethodMatcher() { } + @Override public boolean isRuntime() { return false; @@ -46,11 +48,17 @@ class TrueMethodMatcher implements MethodMatcher, Serializable { } @Override - public boolean matches(Method method, Class targetClass, Object[] args) { + public boolean matches(Method method, Class targetClass, Object... args) { // Should never be invoked as isRuntime returns false. throw new UnsupportedOperationException(); } + + @Override + public String toString() { + return "MethodMatcher.TRUE"; + } + /** * Required to support serialization. Replaces with canonical * instance on deserialization, protecting Singleton pattern. @@ -60,9 +68,4 @@ class TrueMethodMatcher implements MethodMatcher, Serializable { return INSTANCE; } - @Override - public String toString() { - return "MethodMatcher.TRUE"; - } - } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java index 60427610a6..3cb2613689 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java @@ -305,7 +305,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut } @Override - public boolean matches(Method method, Class targetClass, Object[] args) { + public boolean matches(Method method, Class targetClass, Object... args) { checkReadyToMatch(); ShadowMatch shadowMatch = getShadowMatch(AopUtils.getMostSpecificMethod(method, targetClass), method); ShadowMatch originalShadowMatch = getShadowMatch(method, method); diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java index 3fad461004..98c74f7ad0 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,34 +61,6 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac private static final String AJC_MAGIC = "ajc$"; - /** - * Find and return the first AspectJ annotation on the given method - * (there should only be one anyway...) - */ - @SuppressWarnings("unchecked") - protected static AspectJAnnotation findAspectJAnnotationOnMethod(Method method) { - Class[] classesToLookFor = new Class[] { - Before.class, Around.class, After.class, AfterReturning.class, AfterThrowing.class, Pointcut.class}; - for (Class c : classesToLookFor) { - AspectJAnnotation foundAnnotation = findAnnotation(method, (Class) c); - if (foundAnnotation != null) { - return foundAnnotation; - } - } - return null; - } - - private static AspectJAnnotation findAnnotation(Method method, Class toLookFor) { - A result = AnnotationUtils.findAnnotation(method, toLookFor); - if (result != null) { - return new AspectJAnnotation(result); - } - else { - return null; - } - } - - /** Logger available to subclasses */ protected final Log logger = LogFactory.getLog(getClass()); @@ -181,6 +153,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac throw new IllegalStateException("Expecting at least " + argNames.length + " arguments in the advice declaration, but only found " + paramTypes.length); } + // Make the simplifying assumption for now that all of the JoinPoint based arguments // come first in the advice declaration. int typeOffset = paramTypes.length - argNames.length; @@ -191,7 +164,36 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac } + /** + * Find and return the first AspectJ annotation on the given method + * (there should only be one anyway...) + */ + @SuppressWarnings("unchecked") + protected static AspectJAnnotation findAspectJAnnotationOnMethod(Method method) { + Class[] classesToLookFor = new Class[] { + Before.class, Around.class, After.class, AfterReturning.class, AfterThrowing.class, Pointcut.class}; + for (Class c : classesToLookFor) { + AspectJAnnotation foundAnnotation = findAnnotation(method, (Class) c); + if (foundAnnotation != null) { + return foundAnnotation; + } + } + return null; + } + + private static AspectJAnnotation findAnnotation(Method method, Class toLookFor) { + A result = AnnotationUtils.findAnnotation(method, toLookFor); + if (result != null) { + return new AspectJAnnotation(result); + } + else { + return null; + } + } + + protected enum AspectJAnnotationType { + AtPointcut, AtBefore, AtAfter, diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorFactory.java index 36bf115105..7eba0606d5 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,31 +63,31 @@ public interface AspectJAdvisorFactory { /** * Build Spring AOP Advisors for all annotated At-AspectJ methods * on the specified aspect instance. - * @param aif the aspect instance factory (not the aspect instance itself - * in order to avoid eager instantiation) + * @param aspectInstanceFactory the aspect instance factory + * (not the aspect instance itself in order to avoid eager instantiation) * @return a list of advisors for this class */ - List getAdvisors(MetadataAwareAspectInstanceFactory aif); + List getAdvisors(MetadataAwareAspectInstanceFactory aspectInstanceFactory); /** * Build a Spring AOP Advisor for the given AspectJ advice method. * @param candidateAdviceMethod the candidate advice method - * @param aif the aspect instance factory - * @param declarationOrderInAspect the declaration order within the aspect + * @param aspectInstanceFactory the aspect instance factory + * @param declarationOrder the declaration order within the aspect * @param aspectName the name of the aspect * @return {@code null} if the method is not an AspectJ advice method * or if it is a pointcut that will be used by other advice but will not * create a Spring advice in its own right */ - Advisor getAdvisor(Method candidateAdviceMethod, - MetadataAwareAspectInstanceFactory aif, int declarationOrderInAspect, String aspectName); + Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFactory aspectInstanceFactory, + int declarationOrder, String aspectName); /** * Build a Spring AOP Advice for the given AspectJ advice method. * @param candidateAdviceMethod the candidate advice method - * @param pointcut the corresponding AspectJ expression pointcut - * @param aif the aspect instance factory - * @param declarationOrderInAspect the declaration order within the aspect + * @param expressionPointcut the AspectJ expression pointcut + * @param aspectInstanceFactory the aspect instance factory + * @param declarationOrder the declaration order within the aspect * @param aspectName the name of the aspect * @return {@code null} if the method is not an AspectJ advice method * or if it is a pointcut that will be used by other advice but will not @@ -98,7 +98,7 @@ public interface AspectJAdvisorFactory { * @see org.springframework.aop.aspectj.AspectJAfterReturningAdvice * @see org.springframework.aop.aspectj.AspectJAfterThrowingAdvice */ - Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut pointcut, - MetadataAwareAspectInstanceFactory aif, int declarationOrderInAspect, String aspectName); + Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut expressionPointcut, + MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrder, String aspectName); } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java index b58d4ffc1f..27d3a9ba43 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java @@ -54,7 +54,7 @@ class InstantiationModelAwarePointcutAdvisorImpl private transient Method aspectJAdviceMethod; - private final AspectJAdvisorFactory atAspectJAdvisorFactory; + private final AspectJAdvisorFactory aspectJAdvisorFactory; private final MetadataAwareAspectInstanceFactory aspectInstanceFactory; @@ -73,28 +73,30 @@ class InstantiationModelAwarePointcutAdvisorImpl private Boolean isAfterAdvice; - public InstantiationModelAwarePointcutAdvisorImpl(AspectJAdvisorFactory af, AspectJExpressionPointcut ajexp, - MetadataAwareAspectInstanceFactory aif, Method method, int declarationOrderInAspect, String aspectName) { + public InstantiationModelAwarePointcutAdvisorImpl(AspectJExpressionPointcut declaredPointcut, + Method aspectJAdviceMethod, AspectJAdvisorFactory aspectJAdvisorFactory, + MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrder, String aspectName) { - this.declaredPointcut = ajexp; - this.declaringClass = method.getDeclaringClass(); - this.methodName = method.getName(); - this.parameterTypes = method.getParameterTypes(); - this.aspectJAdviceMethod = method; - this.atAspectJAdvisorFactory = af; - this.aspectInstanceFactory = aif; - this.declarationOrder = declarationOrderInAspect; + this.declaredPointcut = declaredPointcut; + this.declaringClass = aspectJAdviceMethod.getDeclaringClass(); + this.methodName = aspectJAdviceMethod.getName(); + this.parameterTypes = aspectJAdviceMethod.getParameterTypes(); + this.aspectJAdviceMethod = aspectJAdviceMethod; + this.aspectJAdvisorFactory = aspectJAdvisorFactory; + this.aspectInstanceFactory = aspectInstanceFactory; + this.declarationOrder = declarationOrder; this.aspectName = aspectName; - if (aif.getAspectMetadata().isLazilyInstantiated()) { + if (aspectInstanceFactory.getAspectMetadata().isLazilyInstantiated()) { // Static part of the pointcut is a lazy type. - Pointcut preInstantiationPointcut = - Pointcuts.union(aif.getAspectMetadata().getPerClausePointcut(), this.declaredPointcut); + Pointcut preInstantiationPointcut = Pointcuts.union( + aspectInstanceFactory.getAspectMetadata().getPerClausePointcut(), this.declaredPointcut); // Make it dynamic: must mutate from pre-instantiation to post-instantiation state. // If it's not a dynamic pointcut, it may be optimized out // by the Spring AOP infrastructure after the first evaluation. - this.pointcut = new PerTargetInstantiationModelPointcut(this.declaredPointcut, preInstantiationPointcut, aif); + this.pointcut = new PerTargetInstantiationModelPointcut( + this.declaredPointcut, preInstantiationPointcut, aspectInstanceFactory); this.lazy = true; } else { @@ -155,7 +157,7 @@ class InstantiationModelAwarePointcutAdvisorImpl private Advice instantiateAdvice(AspectJExpressionPointcut pcut) { - return this.atAspectJAdvisorFactory.getAdvice(this.aspectJAdviceMethod, pcut, + return this.aspectJAdvisorFactory.getAdvice(this.aspectJAdviceMethod, pcut, this.aspectInstanceFactory, this.declarationOrder, this.aspectName); } @@ -279,7 +281,7 @@ class InstantiationModelAwarePointcutAdvisorImpl } @Override - public boolean matches(Method method, Class targetClass, Object[] args) { + public boolean matches(Method method, Class targetClass, Object... args) { // This can match only on declared pointcut. return (isAspectMaterialized() && this.declaredPointcut.matches(method, targetClass)); } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java index 825cb0ceab..ce139f710d 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java @@ -79,8 +79,9 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto new Converter() { @Override public Annotation convert(Method method) { - AspectJAnnotation annotation = AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(method); - return annotation == null ? null : annotation.getAnnotation(); + AspectJAnnotation annotation = + AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(method); + return (annotation != null ? annotation.getAnnotation() : null); } })); comparator.addComparator(new ConvertingComparator( @@ -95,17 +96,17 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto @Override - public List getAdvisors(MetadataAwareAspectInstanceFactory maaif) { - final Class aspectClass = maaif.getAspectMetadata().getAspectClass(); - final String aspectName = maaif.getAspectMetadata().getAspectName(); + public List getAdvisors(MetadataAwareAspectInstanceFactory aspectInstanceFactory) { + Class aspectClass = aspectInstanceFactory.getAspectMetadata().getAspectClass(); + String aspectName = aspectInstanceFactory.getAspectMetadata().getAspectName(); validate(aspectClass); // We need to wrap the MetadataAwareAspectInstanceFactory with a decorator // so that it will only instantiate once. - final MetadataAwareAspectInstanceFactory lazySingletonAspectInstanceFactory = - new LazySingletonAspectInstanceFactoryDecorator(maaif); + MetadataAwareAspectInstanceFactory lazySingletonAspectInstanceFactory = + new LazySingletonAspectInstanceFactoryDecorator(aspectInstanceFactory); - final List advisors = new LinkedList(); + List advisors = new LinkedList(); for (Method method : getAdvisorMethods(aspectClass)) { Advisor advisor = getAdvisor(method, lazySingletonAspectInstanceFactory, advisors.size(), aspectName); if (advisor != null) { @@ -171,18 +172,19 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto @Override - public Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFactory aif, + public Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrderInAspect, String aspectName) { - validate(aif.getAspectMetadata().getAspectClass()); + validate(aspectInstanceFactory.getAspectMetadata().getAspectClass()); - AspectJExpressionPointcut ajexp = - getPointcut(candidateAdviceMethod, aif.getAspectMetadata().getAspectClass()); - if (ajexp == null) { + AspectJExpressionPointcut expressionPointcut = getPointcut( + candidateAdviceMethod, aspectInstanceFactory.getAspectMetadata().getAspectClass()); + if (expressionPointcut == null) { return null; } - return new InstantiationModelAwarePointcutAdvisorImpl( - this, ajexp, aif, candidateAdviceMethod, declarationOrderInAspect, aspectName); + + return new InstantiationModelAwarePointcutAdvisorImpl(expressionPointcut, candidateAdviceMethod, + this, aspectInstanceFactory, declarationOrderInAspect, aspectName); } private AspectJExpressionPointcut getPointcut(Method candidateAdviceMethod, Class candidateAspectClass) { @@ -191,6 +193,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto if (aspectJAnnotation == null) { return null; } + AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(candidateAspectClass, new String[0], new Class[0]); ajexp.setExpression(aspectJAnnotation.getPointcutExpression()); @@ -199,10 +202,10 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto @Override - public Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut ajexp, - MetadataAwareAspectInstanceFactory aif, int declarationOrderInAspect, String aspectName) { + public Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut expressionPointcut, + MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrder, String aspectName) { - Class candidateAspectClass = aif.getAspectMetadata().getAspectClass(); + Class candidateAspectClass = aspectInstanceFactory.getAspectMetadata().getAspectClass(); validate(candidateAspectClass); AspectJAnnotation aspectJAnnotation = @@ -227,27 +230,32 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto switch (aspectJAnnotation.getAnnotationType()) { case AtBefore: - springAdvice = new AspectJMethodBeforeAdvice(candidateAdviceMethod, ajexp, aif); + springAdvice = new AspectJMethodBeforeAdvice( + candidateAdviceMethod, expressionPointcut, aspectInstanceFactory); break; case AtAfter: - springAdvice = new AspectJAfterAdvice(candidateAdviceMethod, ajexp, aif); + springAdvice = new AspectJAfterAdvice( + candidateAdviceMethod, expressionPointcut, aspectInstanceFactory); break; case AtAfterReturning: - springAdvice = new AspectJAfterReturningAdvice(candidateAdviceMethod, ajexp, aif); + springAdvice = new AspectJAfterReturningAdvice( + candidateAdviceMethod, expressionPointcut, aspectInstanceFactory); AfterReturning afterReturningAnnotation = (AfterReturning) aspectJAnnotation.getAnnotation(); if (StringUtils.hasText(afterReturningAnnotation.returning())) { springAdvice.setReturningName(afterReturningAnnotation.returning()); } break; case AtAfterThrowing: - springAdvice = new AspectJAfterThrowingAdvice(candidateAdviceMethod, ajexp, aif); + springAdvice = new AspectJAfterThrowingAdvice( + candidateAdviceMethod, expressionPointcut, aspectInstanceFactory); AfterThrowing afterThrowingAnnotation = (AfterThrowing) aspectJAnnotation.getAnnotation(); if (StringUtils.hasText(afterThrowingAnnotation.throwing())) { springAdvice.setThrowingName(afterThrowingAnnotation.throwing()); } break; case AtAround: - springAdvice = new AspectJAroundAdvice(candidateAdviceMethod, ajexp, aif); + springAdvice = new AspectJAroundAdvice( + candidateAdviceMethod, expressionPointcut, aspectInstanceFactory); break; case AtPointcut: if (logger.isDebugEnabled()) { @@ -256,12 +264,12 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto return null; default: throw new UnsupportedOperationException( - "Unsupported advice type on method " + candidateAdviceMethod); + "Unsupported advice type on method: " + candidateAdviceMethod); } // Now to configure the advice... springAdvice.setAspectName(aspectName); - springAdvice.setDeclarationOrder(declarationOrderInAspect); + springAdvice.setDeclarationOrder(declarationOrder); String[] argNames = this.parameterNameDiscoverer.getParameterNames(candidateAdviceMethod); if (argNames != null) { springAdvice.setArgumentNamesFromStringArray(argNames); @@ -270,6 +278,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto return springAdvice; } + /** * Synthetic advisor that instantiates the aspect. * Triggered by per-clause pointcut on non-singleton aspect. diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java index ed95bd96de..9b3b307467 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -113,7 +113,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised { * Create a AdvisedSupport instance with the given parameters. * @param interfaces the proxied interfaces */ - public AdvisedSupport(Class[] interfaces) { + public AdvisedSupport(Class... interfaces) { this(); setInterfaces(interfaces); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java index d41a36c250..1989a6dae4 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -91,17 +91,17 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher } @Override - public boolean matches(Method method, Class targetClass, Object[] args) { - ++this.evaluations; + public boolean matches(Method method, Class targetClass, Object... args) { + this.evaluations++; ControlFlow cflow = ControlFlowFactory.createControlFlow(); - return (this.methodName != null) ? cflow.under(this.clazz, this.methodName) : cflow.under(this.clazz); + return (this.methodName != null ? cflow.under(this.clazz, this.methodName) : cflow.under(this.clazz)); } /** * It's useful to know how many times we've fired, for optimization. */ public int getEvaluations() { - return evaluations; + return this.evaluations; } @@ -115,6 +115,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher return this; } + @Override public boolean equals(Object other) { if (this == other) { diff --git a/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java b/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java index b71e2c2399..9a64d07431 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -138,7 +138,7 @@ public abstract class MethodMatchers { } @Override - public boolean matches(Method method, Class targetClass, Object[] args) { + public boolean matches(Method method, Class targetClass, Object... args) { return this.mm1.matches(method, targetClass, args) || this.mm2.matches(method, targetClass, args); } @@ -245,7 +245,7 @@ public abstract class MethodMatchers { } @Override - public boolean matches(Method method, Class targetClass, Object[] args) { + public boolean matches(Method method, Class targetClass, Object... args) { // Because a dynamic intersection may be composed of a static and dynamic part, // we must avoid calling the 3-arg matches method on a dynamic matcher, as // it will probably be an unsupported operation. diff --git a/spring-aop/src/main/java/org/springframework/aop/support/Pointcuts.java b/spring-aop/src/main/java/org/springframework/aop/support/Pointcuts.java index df6e57bfa4..b17977ba48 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/Pointcuts.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/Pointcuts.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,7 +71,7 @@ public abstract class Pointcuts { * @param args arguments to the method * @return whether there's a runtime match */ - public static boolean matches(Pointcut pointcut, Method method, Class targetClass, Object[] args) { + public static boolean matches(Pointcut pointcut, Method method, Class targetClass, Object... args) { Assert.notNull(pointcut, "Pointcut must not be null"); if (pointcut == Pointcut.TRUE) { return true; @@ -98,9 +98,9 @@ public abstract class Pointcuts { @Override public boolean matches(Method method, Class targetClass) { - return method.getName().startsWith("set") && - method.getParameterTypes().length == 1 && - method.getReturnType() == Void.TYPE; + return (method.getName().startsWith("set") && + method.getParameterTypes().length == 1 && + method.getReturnType() == Void.TYPE); } private Object readResolve() { @@ -119,8 +119,8 @@ public abstract class Pointcuts { @Override public boolean matches(Method method, Class targetClass) { - return method.getName().startsWith("get") && - method.getParameterTypes().length == 0; + return (method.getName().startsWith("get") && + method.getParameterTypes().length == 0); } private Object readResolve() { diff --git a/spring-aop/src/main/java/org/springframework/aop/support/StaticMethodMatcher.java b/spring-aop/src/main/java/org/springframework/aop/support/StaticMethodMatcher.java index 8bb1d74d73..0627248ee9 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/StaticMethodMatcher.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/StaticMethodMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,7 @@ public abstract class StaticMethodMatcher implements MethodMatcher { } @Override - public final boolean matches(Method method, Class targetClass, Object[] args) { + public final boolean matches(Method method, Class targetClass, Object... args) { // should never be invoked because isRuntime() returns false throw new UnsupportedOperationException("Illegal MethodMatcher usage"); } diff --git a/spring-aop/src/test/java/org/springframework/aop/aspectj/AspectJExpressionPointcutTests.java b/spring-aop/src/test/java/org/springframework/aop/aspectj/AspectJExpressionPointcutTests.java index 6419fbe774..28622ba8d2 100644 --- a/spring-aop/src/test/java/org/springframework/aop/aspectj/AspectJExpressionPointcutTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/aspectj/AspectJExpressionPointcutTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,17 +53,15 @@ public final class AspectJExpressionPointcutTests { private Method setSomeNumber; - private Method isPostProcessed; - @Before public void setUp() throws NoSuchMethodException { - getAge = TestBean.class.getMethod("getAge", (Class[])null); - setAge = TestBean.class.getMethod("setAge", new Class[]{int.class}); - setSomeNumber = TestBean.class.getMethod("setSomeNumber", new Class[]{Number.class}); - isPostProcessed = TestBean.class.getMethod("isPostProcessed", (Class[]) null); + getAge = TestBean.class.getMethod("getAge"); + setAge = TestBean.class.getMethod("setAge", int.class); + setSomeNumber = TestBean.class.getMethod("setSomeNumber", Number.class); } + @Test public void testMatchExplicit() { String expression = "execution(int org.springframework.tests.sample.beans.TestBean.getAge())"; @@ -111,21 +109,9 @@ public final class AspectJExpressionPointcutTests { testThisOrTarget("target"); } - public static class OtherIOther implements IOther { - - @Override - public void absquatulate() { - // Empty - } - - } - /** * This and target are equivalent. Really instanceof pointcuts. * @param which this or target - * @throws Exception - * @throws NoSuchMethodException - * @throws SecurityException */ private void testThisOrTarget(String which) throws SecurityException, NoSuchMethodException { String matchesTestBean = which + "(org.springframework.tests.sample.beans.TestBean)"; @@ -138,11 +124,8 @@ public final class AspectJExpressionPointcutTests { assertTrue(testBeanPc.matches(TestBean.class)); assertTrue(testBeanPc.matches(getAge, TestBean.class)); - assertTrue(iOtherPc.matches(OtherIOther.class.getMethod("absquatulate", (Class[])null), - OtherIOther.class)); - - assertFalse(testBeanPc.matches(OtherIOther.class.getMethod("absquatulate", (Class[])null), - OtherIOther.class)); + assertTrue(iOtherPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class)); + assertFalse(testBeanPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class)); } @Test @@ -171,8 +154,7 @@ public final class AspectJExpressionPointcutTests { assertEquals(matchSubpackages, withinBeansPc.matches( DeepBean.class.getMethod("aMethod", String.class), DeepBean.class)); assertFalse(withinBeansPc.matches(String.class)); - assertFalse(withinBeansPc.matches(OtherIOther.class.getMethod("absquatulate", (Class[])null), - OtherIOther.class)); + assertFalse(withinBeansPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class)); } @Test @@ -183,7 +165,7 @@ public final class AspectJExpressionPointcutTests { fail(); } catch (IllegalStateException ex) { - assertTrue(ex.getMessage().indexOf("expression") != -1); + assertTrue(ex.getMessage().contains("expression")); } } @@ -195,7 +177,7 @@ public final class AspectJExpressionPointcutTests { fail(); } catch (IllegalStateException ex) { - assertTrue(ex.getMessage().indexOf("expression") != -1); + assertTrue(ex.getMessage().contains("expression")); } } @@ -207,7 +189,7 @@ public final class AspectJExpressionPointcutTests { fail(); } catch (IllegalStateException ex) { - assertTrue(ex.getMessage().indexOf("expression") != -1); + assertTrue(ex.getMessage().contains("expression")); } } @@ -226,10 +208,10 @@ public final class AspectJExpressionPointcutTests { //assertDoesNotMatchStringClass(classFilter); assertTrue("Should match with setSomeNumber with Double input", - methodMatcher.matches(setSomeNumber, TestBean.class, new Object[]{new Double(12)})); + methodMatcher.matches(setSomeNumber, TestBean.class, new Double(12))); assertFalse("Should not match setSomeNumber with Integer input", - methodMatcher.matches(setSomeNumber, TestBean.class, new Object[]{new Integer(11)})); - assertFalse("Should not match getAge", methodMatcher.matches(getAge, TestBean.class, null)); + methodMatcher.matches(setSomeNumber, TestBean.class, new Integer(11))); + assertFalse("Should not match getAge", methodMatcher.matches(getAge, TestBean.class)); assertTrue("Should be a runtime match", methodMatcher.isRuntime()); } @@ -281,7 +263,6 @@ public final class AspectJExpressionPointcutTests { } catch (IllegalArgumentException ex) { assertTrue(true); - System.out.println(ex.getMessage()); } } @@ -326,16 +307,14 @@ public final class AspectJExpressionPointcutTests { @Test public void testAndSubstitution() { Pointcut pc = getPointcut("execution(* *(..)) and args(String)"); - PointcutExpression expr = - ((AspectJExpressionPointcut) pc).getPointcutExpression(); + PointcutExpression expr = ((AspectJExpressionPointcut) pc).getPointcutExpression(); assertEquals("execution(* *(..)) && args(String)",expr.getPointcutExpression()); } @Test public void testMultipleAndSubstitutions() { Pointcut pc = getPointcut("execution(* *(..)) and args(String) and this(Object)"); - PointcutExpression expr = - ((AspectJExpressionPointcut) pc).getPointcutExpression(); + PointcutExpression expr = ((AspectJExpressionPointcut) pc).getPointcutExpression(); assertEquals("execution(* *(..)) && args(String) && this(Object)",expr.getPointcutExpression()); } @@ -344,6 +323,15 @@ public final class AspectJExpressionPointcutTests { pointcut.setExpression(expression); return pointcut; } + + + public static class OtherIOther implements IOther { + + @Override + public void absquatulate() { + // Empty + } + } } diff --git a/spring-aop/src/test/java/org/springframework/aop/aspectj/TigerAspectJExpressionPointcutTests.java b/spring-aop/src/test/java/org/springframework/aop/aspectj/TigerAspectJExpressionPointcutTests.java index f14bee5dfc..ddb7c1afe2 100644 --- a/spring-aop/src/test/java/org/springframework/aop/aspectj/TigerAspectJExpressionPointcutTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/aspectj/TigerAspectJExpressionPointcutTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ import static org.junit.Assert.*; * @author Rod Johnson * @author Chris Beams */ -public final class TigerAspectJExpressionPointcutTests { +public class TigerAspectJExpressionPointcutTests { // TODO factor into static in AspectJExpressionPointcut private Method getAge; @@ -46,7 +46,7 @@ public final class TigerAspectJExpressionPointcutTests { @Before public void setUp() throws NoSuchMethodException { - getAge = TestBean.class.getMethod("getAge", (Class[]) null); + getAge = TestBean.class.getMethod("getAge"); // Assumes no overloading for (Method m : HasGeneric.class.getMethods()) { methodsOnHasGeneric.put(m.getName(), m); @@ -54,18 +54,6 @@ public final class TigerAspectJExpressionPointcutTests { } - public static class HasGeneric { - - public void setFriends(List friends) { - } - public void setEnemies(List enemies) { - } - public void setPartners(List partners) { - } - public void setPhoneNumbers(List numbers) { - } - } - @Test public void testMatchGenericArgument() { String expression = "execution(* set*(java.util.List) )"; @@ -132,15 +120,12 @@ public final class TigerAspectJExpressionPointcutTests { public void testMatchAnnotationOnClassWithSubpackageWildcard() throws SecurityException, NoSuchMethodException { String expression = "within(@(test.annotation..*) *)"; AspectJExpressionPointcut springAnnotatedPc = testMatchAnnotationOnClass(expression); - assertFalse(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class), - TestBean.class)); - assertTrue(springAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo", (Class[]) null), - SpringAnnotated.class)); + assertFalse(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class), TestBean.class)); + assertTrue(springAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo"), SpringAnnotated.class)); expression = "within(@(test.annotation.transaction..*) *)"; AspectJExpressionPointcut springTxAnnotatedPc = testMatchAnnotationOnClass(expression); - assertFalse(springTxAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo", (Class[]) null), - SpringAnnotated.class)); + assertFalse(springTxAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo"), SpringAnnotated.class)); } @Test @@ -154,7 +139,7 @@ public final class TigerAspectJExpressionPointcutTests { ajexp.setExpression(expression); assertFalse(ajexp.matches(getAge, TestBean.class)); - assertTrue(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo", (Class[]) null), HasTransactionalAnnotation.class)); + assertTrue(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)); assertTrue(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)); assertTrue(ajexp.matches(BeanB.class.getMethod("setName", String.class), BeanB.class)); assertFalse(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)); @@ -168,10 +153,10 @@ public final class TigerAspectJExpressionPointcutTests { ajexp.setExpression(expression); assertFalse(ajexp.matches(getAge, TestBean.class)); - assertFalse(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo", (Class[]) null), HasTransactionalAnnotation.class)); + assertFalse(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)); assertFalse(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)); assertFalse(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)); - assertTrue(ajexp.matches(BeanA.class.getMethod("getAge", (Class[]) null), BeanA.class)); + assertTrue(ajexp.matches(BeanA.class.getMethod("getAge"), BeanA.class)); assertFalse(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)); } @@ -182,10 +167,10 @@ public final class TigerAspectJExpressionPointcutTests { anySpringMethodAnnotation.setExpression(expression); assertFalse(anySpringMethodAnnotation.matches(getAge, TestBean.class)); - assertFalse(anySpringMethodAnnotation.matches(HasTransactionalAnnotation.class.getMethod("foo", (Class[]) null), HasTransactionalAnnotation.class)); + assertFalse(anySpringMethodAnnotation.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)); assertFalse(anySpringMethodAnnotation.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)); assertFalse(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)); - assertTrue(anySpringMethodAnnotation.matches(BeanA.class.getMethod("getAge", (Class[]) null), BeanA.class)); + assertTrue(anySpringMethodAnnotation.matches(BeanA.class.getMethod("getAge"), BeanA.class)); assertFalse(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)); } @@ -196,10 +181,10 @@ public final class TigerAspectJExpressionPointcutTests { takesSpringAnnotatedArgument2.setExpression(expression); assertFalse(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class)); - assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("foo", (Class[]) null), HasTransactionalAnnotation.class)); + assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)); assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)); assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)); - assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge", (Class[]) null), BeanA.class)); + assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class)); assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)); assertTrue(takesSpringAnnotatedArgument2.matches( @@ -213,8 +198,7 @@ public final class TigerAspectJExpressionPointcutTests { assertFalse(takesSpringAnnotatedArgument2.matches( ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class), - ProcessesSpringAnnotatedParameters.class, - new Object[] { new TestBean(), new BeanA()}) + ProcessesSpringAnnotatedParameters.class, new TestBean(), new BeanA()) ); } @@ -225,10 +209,10 @@ public final class TigerAspectJExpressionPointcutTests { takesSpringAnnotatedArgument2.setExpression(expression); assertFalse(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class)); - assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("foo", (Class[]) null), HasTransactionalAnnotation.class)); + assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)); assertFalse(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)); assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)); - assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge", (Class[]) null), BeanA.class)); + assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class)); assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)); assertTrue(takesSpringAnnotatedArgument2.matches( @@ -240,6 +224,19 @@ public final class TigerAspectJExpressionPointcutTests { } + public static class HasGeneric { + + public void setFriends(List friends) { + } + public void setEnemies(List enemies) { + } + public void setPartners(List partners) { + } + public void setPhoneNumbers(List numbers) { + } + } + + public static class ProcessesSpringAnnotatedParameters { public void takesAnnotatedParameters(TestBean tb, SpringAnnotated sa) { diff --git a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactoryTests.java b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactoryTests.java index 6d925271ce..3f34ff592e 100644 --- a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactoryTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.aop.aspectj.annotation; import java.io.FileNotFoundException; @@ -961,7 +962,7 @@ abstract class AbstractMakeModifiable { private Method getGetterFromSetter(Method setter) { String getterName = setter.getName().replaceFirst("set", "get"); try { - return setter.getDeclaringClass().getMethod(getterName, (Class[]) null); + return setter.getDeclaringClass().getMethod(getterName); } catch (NoSuchMethodException ex) { // must be write only diff --git a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJPointcutAdvisorTests.java b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJPointcutAdvisorTests.java index 3cf475bee4..2f84af9c41 100644 --- a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJPointcutAdvisorTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJPointcutAdvisorTests.java @@ -41,9 +41,11 @@ public class AspectJPointcutAdvisorTests { AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS); - InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(af, ajexp, + InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl( + ajexp, TestBean.class.getMethod("getAge"), af, new SingletonMetadataAwareAspectInstanceFactory(new AbstractAspectJAdvisorFactoryTests.ExceptionAspect(null), "someBean"), - TestBean.class.getMethod("getAge", (Class[]) null), 1, "someBean"); + 1, "someBean"); + assertSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut()); assertFalse(ajpa.isPerInstance()); } @@ -53,19 +55,21 @@ public class AspectJPointcutAdvisorTests { AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS); - InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(af, ajexp, - new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(),"someBean"), - TestBean.class.getMethod("getAge", (Class[]) null), 1, "someBean"); + InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl( + ajexp, TestBean.class.getMethod("getAge"), af, + new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(), "someBean"), + 1, "someBean"); + assertNotSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut()); assertTrue(ajpa.getAspectMetadata().getPerClausePointcut() instanceof AspectJExpressionPointcut); assertTrue(ajpa.isPerInstance()); assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getClassFilter().matches(TestBean.class)); assertFalse(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches( - TestBean.class.getMethod("getAge", (Class[]) null), TestBean.class)); + TestBean.class.getMethod("getAge"), TestBean.class)); assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches( - TestBean.class.getMethod("getSpouse", (Class[]) null), TestBean.class)); + TestBean.class.getMethod("getSpouse"), TestBean.class)); } @Test(expected = AopConfigException.class) diff --git a/spring-aop/src/test/java/org/springframework/aop/framework/MethodInvocationTests.java b/spring-aop/src/test/java/org/springframework/aop/framework/MethodInvocationTests.java index 7083320483..2a7f726fb7 100644 --- a/spring-aop/src/test/java/org/springframework/aop/framework/MethodInvocationTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/framework/MethodInvocationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ public final class MethodInvocationTests { @Test public void testValidInvocation() throws Throwable { - Method m = Object.class.getMethod("hashCode", (Class[]) null); + Method m = Object.class.getMethod("hashCode"); Object proxy = new Object(); final Object returnValue = new Object(); List is = new LinkedList(); @@ -67,7 +67,7 @@ public final class MethodInvocationTests { }; List is = new LinkedList(); - Method m = Object.class.getMethod("hashCode", (Class[]) null); + Method m = Object.class.getMethod("hashCode"); Object proxy = new Object(); ReflectiveMethodInvocation invocation = new ReflectiveMethodInvocation(proxy, target, m, null, null, is); diff --git a/spring-aop/src/test/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptorTests.java b/spring-aop/src/test/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptorTests.java index 25e35f5783..6cb0c47cf5 100644 --- a/spring-aop/src/test/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptorTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -78,7 +78,7 @@ public final class ThrowsAdviceInterceptorTests { ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th); FileNotFoundException ex = new FileNotFoundException(); MethodInvocation mi = mock(MethodInvocation.class); - given(mi.getMethod()).willReturn(Object.class.getMethod("hashCode", (Class[]) null)); + given(mi.getMethod()).willReturn(Object.class.getMethod("hashCode")); given(mi.getThis()).willReturn(new Object()); given(mi.proceed()).willThrow(ex); try { @@ -140,12 +140,15 @@ public final class ThrowsAdviceInterceptorTests { assertEquals(1, th.getCalls("remoteException")); } + @SuppressWarnings("serial") static class MyThrowsHandler extends MethodCounter implements ThrowsAdvice { + // Full method signature public void afterThrowing(Method m, Object[] args, Object target, IOException ex) { count("ioException"); } + public void afterThrowing(RemoteException ex) throws Throwable { count("remoteException"); } diff --git a/spring-aop/src/test/java/org/springframework/aop/support/AbstractRegexpMethodPointcutTests.java b/spring-aop/src/test/java/org/springframework/aop/support/AbstractRegexpMethodPointcutTests.java index 64ab845a04..39cbed336e 100644 --- a/spring-aop/src/test/java/org/springframework/aop/support/AbstractRegexpMethodPointcutTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/support/AbstractRegexpMethodPointcutTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,8 +54,8 @@ public abstract class AbstractRegexpMethodPointcutTests { } protected void noPatternSuppliedTests(AbstractRegexpMethodPointcut rpc) throws Exception { - assertFalse(rpc.matches(Object.class.getMethod("hashCode", (Class[]) null), String.class)); - assertFalse(rpc.matches(Object.class.getMethod("wait", (Class[]) null), Object.class)); + assertFalse(rpc.matches(Object.class.getMethod("hashCode"), String.class)); + assertFalse(rpc.matches(Object.class.getMethod("wait"), Object.class)); assertEquals(0, rpc.getPatterns().length); } @@ -69,38 +69,38 @@ public abstract class AbstractRegexpMethodPointcutTests { protected void exactMatchTests(AbstractRegexpMethodPointcut rpc) throws Exception { // assumes rpc.setPattern("java.lang.Object.hashCode"); - assertTrue(rpc.matches(Object.class.getMethod("hashCode", (Class[]) null), String.class)); - assertTrue(rpc.matches(Object.class.getMethod("hashCode", (Class[]) null), Object.class)); - assertFalse(rpc.matches(Object.class.getMethod("wait", (Class[]) null), Object.class)); + assertTrue(rpc.matches(Object.class.getMethod("hashCode"), String.class)); + assertTrue(rpc.matches(Object.class.getMethod("hashCode"), Object.class)); + assertFalse(rpc.matches(Object.class.getMethod("wait"), Object.class)); } @Test public void testSpecificMatch() throws Exception { rpc.setPattern("java.lang.String.hashCode"); - assertTrue(rpc.matches(Object.class.getMethod("hashCode", (Class[]) null), String.class)); - assertFalse(rpc.matches(Object.class.getMethod("hashCode", (Class[]) null), Object.class)); + assertTrue(rpc.matches(Object.class.getMethod("hashCode"), String.class)); + assertFalse(rpc.matches(Object.class.getMethod("hashCode"), Object.class)); } @Test public void testWildcard() throws Exception { rpc.setPattern(".*Object.hashCode"); - assertTrue(rpc.matches(Object.class.getMethod("hashCode", (Class[]) null), Object.class)); - assertFalse(rpc.matches(Object.class.getMethod("wait", (Class[]) null), Object.class)); + assertTrue(rpc.matches(Object.class.getMethod("hashCode"), Object.class)); + assertFalse(rpc.matches(Object.class.getMethod("wait"), Object.class)); } @Test public void testWildcardForOneClass() throws Exception { rpc.setPattern("java.lang.Object.*"); - assertTrue(rpc.matches(Object.class.getMethod("hashCode", (Class[]) null), String.class)); - assertTrue(rpc.matches(Object.class.getMethod("wait", (Class[]) null), String.class)); + assertTrue(rpc.matches(Object.class.getMethod("hashCode"), String.class)); + assertTrue(rpc.matches(Object.class.getMethod("wait"), String.class)); } @Test public void testMatchesObjectClass() throws Exception { rpc.setPattern("java.lang.Object.*"); - assertTrue(rpc.matches(Exception.class.getMethod("hashCode", (Class[]) null), IOException.class)); + assertTrue(rpc.matches(Exception.class.getMethod("hashCode"), IOException.class)); // Doesn't match a method from Throwable - assertFalse(rpc.matches(Exception.class.getMethod("getMessage", (Class[]) null), Exception.class)); + assertFalse(rpc.matches(Exception.class.getMethod("getMessage"), Exception.class)); } @Test diff --git a/spring-aop/src/test/java/org/springframework/aop/support/ComposablePointcutTests.java b/spring-aop/src/test/java/org/springframework/aop/support/ComposablePointcutTests.java index b229c3ee59..b34438ee3d 100644 --- a/spring-aop/src/test/java/org/springframework/aop/support/ComposablePointcutTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/support/ComposablePointcutTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,7 @@ import static org.junit.Assert.*; * @author Rod Johnson * @author Chris Beams */ -public final class ComposablePointcutTests { +public class ComposablePointcutTests { public static MethodMatcher GETTER_METHOD_MATCHER = new StaticMethodMatcher() { @Override @@ -62,11 +62,12 @@ public final class ComposablePointcutTests { } }; + @Test public void testMatchAll() throws NoSuchMethodException { Pointcut pc = new ComposablePointcut(); assertTrue(pc.getClassFilter().matches(Object.class)); - assertTrue(pc.getMethodMatcher().matches(Object.class.getMethod("hashCode", (Class[]) null), Exception.class)); + assertTrue(pc.getMethodMatcher().matches(Object.class.getMethod("hashCode"), Exception.class)); } @Test @@ -93,23 +94,23 @@ public final class ComposablePointcutTests { public void testUnionMethodMatcher() { // Matches the getAge() method in any class ComposablePointcut pc = new ComposablePointcut(ClassFilter.TRUE, GET_AGE_METHOD_MATCHER); - assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class, null)); - assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class, null)); - assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class, null)); + assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)); + assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)); + assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)); pc.union(GETTER_METHOD_MATCHER); // Should now match all getter methods - assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class, null)); - assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class, null)); - assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class, null)); + assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)); + assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)); + assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)); pc.union(ABSQUATULATE_METHOD_MATCHER); // Should now match absquatulate() as well - assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class, null)); - assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class, null)); - assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class, null)); + assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)); + assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)); + assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)); // But it doesn't match everything - assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_SET_AGE, TestBean.class, null)); + assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_SET_AGE, TestBean.class)); } @Test @@ -124,9 +125,9 @@ public final class ComposablePointcutTests { assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)); pc.intersection(GET_AGE_METHOD_MATCHER); // Use the Pointcuts matches method - assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class, null)); - assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class, null)); - assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class, null)); + assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)); + assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)); + assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)); } @Test @@ -153,4 +154,5 @@ public final class ComposablePointcutTests { assertEquals(pc1, pc2); assertEquals(pc1.hashCode(), pc2.hashCode()); } + } diff --git a/spring-aop/src/test/java/org/springframework/aop/support/MethodMatchersTests.java b/spring-aop/src/test/java/org/springframework/aop/support/MethodMatchersTests.java index afa1726b01..5b12fa19e9 100644 --- a/spring-aop/src/test/java/org/springframework/aop/support/MethodMatchersTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/support/MethodMatchersTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,7 @@ import static org.junit.Assert.*; * @author Juergen Hoeller * @author Chris Beams */ -public final class MethodMatchersTests { +public class MethodMatchersTests { private final Method EXCEPTION_GETMESSAGE; @@ -44,10 +44,10 @@ public final class MethodMatchersTests { public MethodMatchersTests() throws Exception { - EXCEPTION_GETMESSAGE = Exception.class.getMethod("getMessage", (Class[]) null); - ITESTBEAN_GETAGE = ITestBean.class.getMethod("getAge", (Class[]) null); - ITESTBEAN_SETAGE = ITestBean.class.getMethod("setAge", new Class[] { int.class }); - IOTHER_ABSQUATULATE = IOther.class.getMethod("absquatulate", (Class[]) null); + EXCEPTION_GETMESSAGE = Exception.class.getMethod("getMessage"); + ITESTBEAN_GETAGE = ITestBean.class.getMethod("getAge"); + ITESTBEAN_SETAGE = ITestBean.class.getMethod("setAge", int.class); + IOTHER_ABSQUATULATE = IOther.class.getMethod("absquatulate"); } @@ -82,12 +82,12 @@ public final class MethodMatchersTests { MethodMatcher intersection = MethodMatchers.intersection(mm1, mm2); assertTrue("Intersection is a dynamic matcher", intersection.isRuntime()); assertTrue("2Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class)); - assertTrue("3Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Object[] { new Integer(5) })); + assertTrue("3Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Integer(5))); // Knock out dynamic part intersection = MethodMatchers.intersection(intersection, new TestDynamicMethodMatcherWhichDoesNotMatch()); assertTrue("Intersection is a dynamic matcher", intersection.isRuntime()); assertTrue("2Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class)); - assertFalse("3 - not Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Object[] { new Integer(5) })); + assertFalse("3 - not Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Integer(5))); } @Test @@ -125,18 +125,20 @@ public final class MethodMatchersTests { } } + private static class TestDynamicMethodMatcherWhichMatches extends DynamicMethodMatcher { @Override - public boolean matches(Method m, Class targetClass, Object[] args) { + public boolean matches(Method m, Class targetClass, Object... args) { return true; } } + private static class TestDynamicMethodMatcherWhichDoesNotMatch extends DynamicMethodMatcher { @Override - public boolean matches(Method m, Class targetClass, Object[] args) { + public boolean matches(Method m, Class targetClass, Object... args) { return false; } } diff --git a/spring-aop/src/test/java/org/springframework/aop/support/PointcutsTests.java b/spring-aop/src/test/java/org/springframework/aop/support/PointcutsTests.java index 6404c8d760..5e5569a949 100644 --- a/spring-aop/src/test/java/org/springframework/aop/support/PointcutsTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/support/PointcutsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ import static org.junit.Assert.*; * @author Rod Johnson * @author Chris Beams */ -public final class PointcutsTests { +public class PointcutsTests { public static Method TEST_BEAN_SET_AGE; public static Method TEST_BEAN_GET_AGE; @@ -39,10 +39,10 @@ public final class PointcutsTests { static { try { - TEST_BEAN_SET_AGE = TestBean.class.getMethod("setAge", new Class[] { int.class }); - TEST_BEAN_GET_AGE = TestBean.class.getMethod("getAge", (Class[]) null); - TEST_BEAN_GET_NAME = TestBean.class.getMethod("getName", (Class[]) null); - TEST_BEAN_ABSQUATULATE = TestBean.class.getMethod("absquatulate", (Class[]) null); + TEST_BEAN_SET_AGE = TestBean.class.getMethod("setAge", int.class); + TEST_BEAN_GET_AGE = TestBean.class.getMethod("getAge"); + TEST_BEAN_GET_NAME = TestBean.class.getMethod("getName"); + TEST_BEAN_ABSQUATULATE = TestBean.class.getMethod("absquatulate"); } catch (Exception ex) { throw new RuntimeException("Shouldn't happen: error in test suite"); @@ -125,22 +125,22 @@ public final class PointcutsTests { @Test public void testTrue() { - assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)})); - assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class, null)); - assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class, null)); - assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)})); - assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class, null)); - assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class, null)); + assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))); + assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class)); + assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class)); + assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))); + assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class)); + assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class)); } @Test public void testMatches() { - assertTrue(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)})); - assertFalse(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class, null)); - assertFalse(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class, null)); - assertFalse(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)})); - assertTrue(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class, null)); - assertFalse(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class, null)); + assertTrue(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))); + assertFalse(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class)); + assertFalse(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class)); + assertFalse(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))); + assertTrue(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class)); + assertFalse(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class)); } /** @@ -149,29 +149,29 @@ public final class PointcutsTests { @Test public void testUnionOfSettersAndGetters() { Pointcut union = Pointcuts.union(allClassGetterPointcut, allClassSetterPointcut); - assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)})); - assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class, null)); - assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class, null)); + assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))); + assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)); + assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class)); } @Test public void testUnionOfSpecificGetters() { Pointcut union = Pointcuts.union(allClassGetAgePointcut, allClassGetNamePointcut); - assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)})); - assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class, null)); - assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class, null)); - assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class, null)); - assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class, null)); + assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))); + assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)); + assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class)); + assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class)); + assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class)); // Union with all setters union = Pointcuts.union(union, allClassSetterPointcut); - assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)})); - assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class, null)); - assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class, null)); - assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class, null)); - assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class, null)); + assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))); + assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)); + assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class)); + assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class)); + assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class)); - assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)})); + assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))); } /** @@ -180,16 +180,16 @@ public final class PointcutsTests { */ @Test public void testUnionOfAllSettersAndSubclassSetters() { - assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)})); - assertTrue(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, MyTestBean.class, new Object[] { new Integer(6)})); - assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class, null)); + assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))); + assertTrue(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, MyTestBean.class, new Integer(6))); + assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class)); Pointcut union = Pointcuts.union(myTestBeanSetterPointcut, allClassGetterPointcut); - assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class, null)); - assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class, null)); + assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)); + assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class)); // Still doesn't match superclass setter - assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, MyTestBean.class, new Object[] { new Integer(6)})); - assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)})); + assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, MyTestBean.class, new Integer(6))); + assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))); } /** @@ -198,44 +198,44 @@ public final class PointcutsTests { */ @Test public void testIntersectionOfSpecificGettersAndSubclassGetters() { - assertTrue(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, TestBean.class, null)); - assertTrue(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, MyTestBean.class, null)); - assertFalse(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, TestBean.class, null)); - assertFalse(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class, null)); - assertTrue(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, MyTestBean.class, null)); - assertTrue(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, MyTestBean.class, null)); + assertTrue(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, TestBean.class)); + assertTrue(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, MyTestBean.class)); + assertFalse(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, TestBean.class)); + assertFalse(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class)); + assertTrue(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, MyTestBean.class)); + assertTrue(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, MyTestBean.class)); Pointcut intersection = Pointcuts.intersection(allClassGetAgePointcut, myTestBeanGetterPointcut); - assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class, null)); - assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class, null)); - assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class, null)); - assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class, null)); + assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class)); + assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class)); + assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class)); + assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class)); // Matches subclass of MyTestBean - assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class, null)); - assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class, null)); + assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class)); + assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class)); // Now intersection with MyTestBeanSubclass getters should eliminate MyTestBean target intersection = Pointcuts.intersection(intersection, myTestBeanSubclassGetterPointcut); - assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class, null)); - assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class, null)); - assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class, null)); - assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class, null)); + assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class)); + assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class)); + assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class)); + assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class)); // Still matches subclass of MyTestBean - assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class, null)); - assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class, null)); + assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class)); + assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class)); // Now union with all TestBean methods Pointcut union = Pointcuts.union(intersection, allTestBeanMethodsPointcut); - assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class, null)); - assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class, null)); - assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBean.class, null)); - assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class, null)); + assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class)); + assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)); + assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBean.class)); + assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class)); // Still matches subclass of MyTestBean - assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class, null)); - assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class, null)); + assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class)); + assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class)); - assertTrue(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class, null)); - assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, MyTestBean.class, null)); + assertTrue(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class)); + assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, MyTestBean.class)); } @@ -245,9 +245,9 @@ public final class PointcutsTests { @Test public void testSimpleIntersection() { Pointcut intersection = Pointcuts.intersection(allClassGetterPointcut, allClassSetterPointcut); - assertFalse(Pointcuts.matches(intersection, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)})); - assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class, null)); - assertFalse(Pointcuts.matches(intersection, TEST_BEAN_ABSQUATULATE, TestBean.class, null)); + assertFalse(Pointcuts.matches(intersection, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))); + assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class)); + assertFalse(Pointcuts.matches(intersection, TEST_BEAN_ABSQUATULATE, TestBean.class)); } } diff --git a/spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java b/spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java index 2e554c192b..3114bf62a8 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java @@ -31,10 +31,13 @@ import java.util.Map; import org.aopalliance.aop.Advice; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; - import org.junit.After; import org.junit.Before; import org.junit.Test; +import test.mixin.LockMixin; +import test.mixin.LockMixinAdvisor; +import test.mixin.Lockable; +import test.mixin.LockedException; import org.springframework.aop.Advisor; import org.springframework.aop.AfterReturningAdvice; @@ -72,11 +75,6 @@ import org.springframework.tests.sample.beans.TestBean; import org.springframework.util.SerializationTestUtils; import org.springframework.util.StopWatch; -import test.mixin.LockMixin; -import test.mixin.LockMixinAdvisor; -import test.mixin.Lockable; -import test.mixin.LockedException; - import static org.junit.Assert.*; /** @@ -123,7 +121,7 @@ public abstract class AbstractAopProxyTests { @Test(expected = AopConfigException.class) public void testNoInterceptorsAndNoTarget() { - AdvisedSupport pc = new AdvisedSupport(new Class[] { ITestBean.class }); + AdvisedSupport pc = new AdvisedSupport(ITestBean.class); // Add no interceptors AopProxy aop = createAopProxy(pc); aop.getProxy(); @@ -408,7 +406,7 @@ public abstract class AbstractAopProxyTests { return s; } }; - AdvisedSupport pc = new AdvisedSupport(new Class[] {ITestBean.class}); + AdvisedSupport pc = new AdvisedSupport(ITestBean.class); if (context) { pc.addAdvice(ExposeInvocationInterceptor.INSTANCE); } @@ -452,7 +450,7 @@ public abstract class AbstractAopProxyTests { throw expectedException; } }; - AdvisedSupport pc = new AdvisedSupport(new Class[] {ITestBean.class}); + AdvisedSupport pc = new AdvisedSupport(ITestBean.class); pc.addAdvice(ExposeInvocationInterceptor.INSTANCE); pc.addAdvice(mi); @@ -487,7 +485,7 @@ public abstract class AbstractAopProxyTests { throw unexpectedException; } }; - AdvisedSupport pc = new AdvisedSupport(new Class[] {ITestBean.class}); + AdvisedSupport pc = new AdvisedSupport(ITestBean.class); pc.addAdvice(ExposeInvocationInterceptor.INSTANCE); pc.addAdvice(mi); @@ -520,7 +518,7 @@ public abstract class AbstractAopProxyTests { throw unexpectedException; } }; - AdvisedSupport pc = new AdvisedSupport(new Class[] {ITestBean.class}); + AdvisedSupport pc = new AdvisedSupport(ITestBean.class); pc.addAdvice(ExposeInvocationInterceptor.INSTANCE); pc.addAdvice(mi); @@ -548,7 +546,7 @@ public abstract class AbstractAopProxyTests { @Test public void testTargetCanGetInvocationEvenIfNoAdviceChain() throws Throwable { NeedsToSeeProxy target = new NeedsToSeeProxy(); - AdvisedSupport pc = new AdvisedSupport(new Class[] {INeedsToSeeProxy.class}); + AdvisedSupport pc = new AdvisedSupport(INeedsToSeeProxy.class); pc.setTarget(target); pc.setExposeProxy(true); @@ -563,7 +561,7 @@ public abstract class AbstractAopProxyTests { public void testTargetCanGetInvocation() throws Throwable { final InvocationCheckExposedInvocationTestBean expectedTarget = new InvocationCheckExposedInvocationTestBean(); - AdvisedSupport pc = new AdvisedSupport(new Class[] {ITestBean.class, IOther.class}); + AdvisedSupport pc = new AdvisedSupport(ITestBean.class, IOther.class); pc.addAdvice(ExposeInvocationInterceptor.INSTANCE); TrapTargetInterceptor tii = new TrapTargetInterceptor() { @Override @@ -600,7 +598,8 @@ public abstract class AbstractAopProxyTests { @Test public void testMixinWithIntroductionAdvisor() throws Throwable { TestBean tb = new TestBean(); - ProxyFactory pc = new ProxyFactory(new Class[] {ITestBean.class}); + ProxyFactory pc = new ProxyFactory(); + pc.addInterface(ITestBean.class); pc.addAdvisor(new LockMixinAdvisor()); pc.setTarget(tb); @@ -610,7 +609,8 @@ public abstract class AbstractAopProxyTests { @Test public void testMixinWithIntroductionInfo() throws Throwable { TestBean tb = new TestBean(); - ProxyFactory pc = new ProxyFactory(new Class[] {ITestBean.class}); + ProxyFactory pc = new ProxyFactory(); + pc.addInterface(ITestBean.class); // We don't use an IntroductionAdvisor, we can just add an advice that implements IntroductionInfo pc.addAdvice(new LockMixin()); pc.setTarget(tb); @@ -648,7 +648,8 @@ public abstract class AbstractAopProxyTests { @Test public void testReplaceArgument() throws Throwable { TestBean tb = new TestBean(); - ProxyFactory pc = new ProxyFactory(new Class[] {ITestBean.class}); + ProxyFactory pc = new ProxyFactory(); + pc.addInterface(ITestBean.class); pc.setTarget(tb); pc.addAdvisor(new StringSetterNullReplacementAdvice()); @@ -825,7 +826,7 @@ public abstract class AbstractAopProxyTests { fail("Shouldn't be able to add introduction advice that introduces a class, rather than an interface"); } catch (IllegalArgumentException ex) { - assertTrue(ex.getMessage().indexOf("interface") > -1); + assertTrue(ex.getMessage().contains("interface")); } // Check it still works: proxy factory state shouldn't have been corrupted ITestBean proxied = (ITestBean) createProxy(pc); @@ -873,7 +874,7 @@ public abstract class AbstractAopProxyTests { fail("Shouldn't be able to add Advisor when frozen"); } catch (AopConfigException ex) { - assertTrue(ex.getMessage().indexOf("frozen") > -1); + assertTrue(ex.getMessage().contains("frozen")); } // Check it still works: proxy factory state shouldn't have been corrupted assertEquals(target.getAge(), proxied.getAge()); @@ -897,7 +898,7 @@ public abstract class AbstractAopProxyTests { fail("Shouldn't be able to remove Advisor when frozen"); } catch (AopConfigException ex) { - assertTrue(ex.getMessage().indexOf("frozen") > -1); + assertTrue(ex.getMessage().contains("frozen")); } // Didn't get removed assertEquals(1, advised.getAdvisors().length); @@ -938,7 +939,7 @@ public abstract class AbstractAopProxyTests { public void testProxyConfigString() { TestBean target = new TestBean(); ProxyFactory pc = new ProxyFactory(target); - pc.setInterfaces(new Class[] {ITestBean.class}); + pc.setInterfaces(ITestBean.class); pc.addAdvice(new NopInterceptor()); MethodBeforeAdvice mba = new CountingBeforeAdvice(); Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut(), mba); @@ -946,15 +947,15 @@ public abstract class AbstractAopProxyTests { ITestBean proxied = (ITestBean) createProxy(pc); String proxyConfigString = ((Advised) proxied).toProxyConfigString(); - assertTrue(proxyConfigString.indexOf(advisor.toString()) != -1); - assertTrue(proxyConfigString.indexOf("1 interface") != -1); + assertTrue(proxyConfigString.contains(advisor.toString())); + assertTrue(proxyConfigString.contains("1 interface")); } @Test public void testCanPreventCastToAdvisedUsingOpaque() { TestBean target = new TestBean(); ProxyFactory pc = new ProxyFactory(target); - pc.setInterfaces(new Class[] {ITestBean.class}); + pc.setInterfaces(ITestBean.class); pc.addAdvice(new NopInterceptor()); CountingBeforeAdvice mba = new CountingBeforeAdvice(); Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut().addMethodName("setAge"), mba); @@ -1055,7 +1056,8 @@ public abstract class AbstractAopProxyTests { @Test public void testDynamicMethodPointcutThatAlwaysAppliesStatically() throws Throwable { TestBean tb = new TestBean(); - ProxyFactory pc = new ProxyFactory(new Class[] {ITestBean.class}); + ProxyFactory pc = new ProxyFactory(); + pc.addInterface(ITestBean.class); TestDynamicPointcutAdvice dp = new TestDynamicPointcutAdvice(new NopInterceptor(), "getAge"); pc.addAdvisor(dp); pc.setTarget(tb); @@ -1071,7 +1073,8 @@ public abstract class AbstractAopProxyTests { @Test public void testDynamicMethodPointcutThatAppliesStaticallyOnlyToSetters() throws Throwable { TestBean tb = new TestBean(); - ProxyFactory pc = new ProxyFactory(new Class[] {ITestBean.class}); + ProxyFactory pc = new ProxyFactory(); + pc.addInterface(ITestBean.class); // Could apply dynamically to getAge/setAge but not to getName TestDynamicPointcutForSettersOnly dp = new TestDynamicPointcutForSettersOnly(new NopInterceptor(), "Age"); pc.addAdvisor(dp); @@ -1093,7 +1096,8 @@ public abstract class AbstractAopProxyTests { @Test public void testStaticMethodPointcut() throws Throwable { TestBean tb = new TestBean(); - ProxyFactory pc = new ProxyFactory(new Class[] {ITestBean.class}); + ProxyFactory pc = new ProxyFactory(); + pc.addInterface(ITestBean.class); NopInterceptor di = new NopInterceptor(); TestStaticPointcutAdvice sp = new TestStaticPointcutAdvice(di, "getAge"); pc.addAdvisor(sp); @@ -1207,6 +1211,7 @@ public abstract class AbstractAopProxyTests { public void testOverloadedMethodsWithDifferentAdvice() throws Throwable { Overloads target = new Overloads(); ProxyFactory pc = new ProxyFactory(target); + NopInterceptor overLoadVoids = new NopInterceptor(); pc.addAdvisor(new StaticMethodMatcherPointcutAdvisor(overLoadVoids) { @Override @@ -1214,12 +1219,13 @@ public abstract class AbstractAopProxyTests { return m.getName().equals("overload") && m.getParameterTypes().length == 0; } }); + NopInterceptor overLoadInts = new NopInterceptor(); pc.addAdvisor(new StaticMethodMatcherPointcutAdvisor(overLoadInts) { @Override public boolean matches(Method m, Class targetClass) { return m.getName().equals("overload") && m.getParameterTypes().length == 1 && - m.getParameterTypes()[0].equals(int.class); + m.getParameterTypes()[0].equals(int.class); } }); @@ -1245,24 +1251,22 @@ public abstract class AbstractAopProxyTests { pf.setExposeProxy(true); final ITestBean proxy = (ITestBean) createProxy(pf); Advised config = (Advised) proxy; + // This class just checks proxy is bound before getTarget() call config.setTargetSource(new TargetSource() { @Override public Class getTargetClass() { return TestBean.class; } - @Override public boolean isStatic() { return false; } - @Override public Object getTarget() throws Exception { assertEquals(proxy, AopContext.currentProxy()); return target; } - @Override public void releaseTarget(Object target) throws Exception { } @@ -1351,7 +1355,7 @@ public abstract class AbstractAopProxyTests { return invocation.proceed(); } }; - AdvisedSupport pc = new AdvisedSupport(new Class[] {ITestBean.class}); + AdvisedSupport pc = new AdvisedSupport(ITestBean.class); MapAwareMethodInterceptor mami1 = new MapAwareMethodInterceptor(new HashMap(), new HashMap()); Map firstValuesToAdd = new HashMap(); firstValuesToAdd.put("test", ""); @@ -1683,7 +1687,7 @@ public abstract class AbstractAopProxyTests { super(cleaner); setPointcut(new DynamicMethodMatcherPointcut() { @Override - public boolean matches(Method m, Class targetClass, Object[] args) { + public boolean matches(Method m, Class targetClass, Object... args) { return args[0] == null; } @Override @@ -1706,8 +1710,8 @@ public abstract class AbstractAopProxyTests { super(mi); setPointcut(new DynamicMethodMatcherPointcut() { @Override - public boolean matches(Method m, Class targetClass, Object[] args) { - boolean run = m.getName().indexOf(pattern) != -1; + public boolean matches(Method m, Class targetClass, Object... args) { + boolean run = m.getName().contains(pattern); if (run) ++count; return run; } @@ -1725,8 +1729,8 @@ public abstract class AbstractAopProxyTests { super(mi); setPointcut(new DynamicMethodMatcherPointcut() { @Override - public boolean matches(Method m, Class targetClass, Object[] args) { - boolean run = m.getName().indexOf(pattern) != -1; + public boolean matches(Method m, Class targetClass, Object... args) { + boolean run = m.getName().contains(pattern); if (run) ++count; return run; } @@ -1750,7 +1754,7 @@ public abstract class AbstractAopProxyTests { } @Override public boolean matches(Method m, Class targetClass) { - return m.getName().indexOf(pattern) != -1; + return m.getName().contains(pattern); } } diff --git a/spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java b/spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java index 1052a2599c..af8b1be5ea 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java @@ -81,7 +81,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab @Test(expected = AopConfigException.class) public void testNoTarget() { - AdvisedSupport pc = new AdvisedSupport(new Class[] { ITestBean.class }); + AdvisedSupport pc = new AdvisedSupport(ITestBean.class); pc.addAdvice(new NopInterceptor()); AopProxy aop = createAopProxy(pc); aop.getProxy(); @@ -93,7 +93,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab bean.value = "foo"; mockTargetSource.setTarget(bean); - AdvisedSupport as = new AdvisedSupport(new Class[]{}); + AdvisedSupport as = new AdvisedSupport(); as.setTargetSource(mockTargetSource); as.addAdvice(new NopInterceptor()); AopProxy aop = new CglibAopProxy(as); @@ -110,7 +110,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab bean.value = "foo"; mockTargetSource.setTarget(bean); - AdvisedSupport as = new AdvisedSupport(new Class[]{}); + AdvisedSupport as = new AdvisedSupport(); as.setTargetSource(mockTargetSource); as.addAdvice(new NopInterceptor()); AopProxy aop = new CglibAopProxy(as); @@ -130,7 +130,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab bean.value = "foo"; mockTargetSource.setTarget(bean); - AdvisedSupport as = new AdvisedSupport(new Class[]{}); + AdvisedSupport as = new AdvisedSupport(); as.setTargetSource(mockTargetSource); as.addAdvice(new NopInterceptor()); AopProxy aop = new CglibAopProxy(as); @@ -164,7 +164,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab CglibTestBean bean = new CglibTestBean(); bean.setName("Rob Harrop"); - AdvisedSupport as = new AdvisedSupport(new Class[]{}); + AdvisedSupport as = new AdvisedSupport(); as.setTarget(bean); as.addAdvice(new NopInterceptor()); AopProxy aop = new CglibAopProxy(as); @@ -178,7 +178,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab CglibTestBean target = new CglibTestBean(); target.setName("Rob Harrop"); - AdvisedSupport pc = new AdvisedSupport(new Class[]{}); + AdvisedSupport pc = new AdvisedSupport(); pc.setFrozen(true); pc.setTarget(target); @@ -264,7 +264,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab target.reset(); mockTargetSource.setTarget(target); - AdvisedSupport pc = new AdvisedSupport(new Class[]{}); + AdvisedSupport pc = new AdvisedSupport(); pc.setTargetSource(mockTargetSource); CglibAopProxy aop = new CglibAopProxy(pc); aop.setConstructorArguments(new Object[] {"Rob Harrop", 22}, new Class[] {String.class, int.class}); @@ -280,7 +280,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab ITestBean target = new TestBean(); mockTargetSource.setTarget(target); - AdvisedSupport as = new AdvisedSupport(new Class[]{}); + AdvisedSupport as = new AdvisedSupport(); as.setTargetSource(mockTargetSource); as.addAdvice(new NopInterceptor()); CglibAopProxy cglib = new CglibAopProxy(as); @@ -301,7 +301,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab ITestBean target = new TestBean(); mockTargetSource.setTarget(target); - AdvisedSupport as = new AdvisedSupport(new Class[]{}); + AdvisedSupport as = new AdvisedSupport(); as.setTargetSource(mockTargetSource); as.addAdvice(new NopInterceptor()); as.addInterface(Serializable.class); @@ -324,7 +324,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab ExceptionThrower bean = new ExceptionThrower(); mockTargetSource.setTarget(bean); - AdvisedSupport as = new AdvisedSupport(new Class[]{}); + AdvisedSupport as = new AdvisedSupport(); as.setTargetSource(mockTargetSource); as.addAdvice(new NopInterceptor()); AopProxy aop = new CglibAopProxy(as); diff --git a/spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java b/spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java index cb5b07e908..dd8d1f3a45 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java @@ -63,7 +63,7 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria public void testProxyIsJustInterface() throws Throwable { TestBean raw = new TestBean(); raw.setAge(32); - AdvisedSupport pc = new AdvisedSupport(new Class[] {ITestBean.class}); + AdvisedSupport pc = new AdvisedSupport(ITestBean.class); pc.setTarget(raw); JdkDynamicAopProxy aop = new JdkDynamicAopProxy(pc); @@ -78,7 +78,7 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria final int age = 25; MethodInterceptor mi = (invocation -> age); - AdvisedSupport pc = new AdvisedSupport(new Class[] {ITestBean.class}); + AdvisedSupport pc = new AdvisedSupport(ITestBean.class); pc.addAdvice(mi); AopProxy aop = createAopProxy(pc); @@ -97,7 +97,7 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria } }; - AdvisedSupport pc = new AdvisedSupport(new Class[] {ITestBean.class, IOther.class}); + AdvisedSupport pc = new AdvisedSupport(ITestBean.class, IOther.class); pc.addAdvice(ExposeInvocationInterceptor.INSTANCE); TrapTargetInterceptor tii = new TrapTargetInterceptor() { @Override @@ -129,7 +129,7 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria @Test public void testEqualsAndHashCodeDefined() throws Exception { - AdvisedSupport as = new AdvisedSupport(new Class[]{Named.class}); + AdvisedSupport as = new AdvisedSupport(Named.class); as.setTarget(new Person()); JdkDynamicAopProxy aopProxy = new JdkDynamicAopProxy(as); Named proxy = (Named) aopProxy.getProxy(); diff --git a/spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java b/spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java index 8eaaed36a1..78b8e5f25b 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -88,6 +88,7 @@ public final class ProxyFactoryBeanTests { private BeanFactory factory; + @Before public void setUp() throws Exception { DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); @@ -97,6 +98,7 @@ public final class ProxyFactoryBeanTests { new ClassPathResource(CONTEXT, getClass())); } + @Test public void testIsDynamicProxyWhenInterfaceSpecified() { ITestBean test1 = (ITestBean) factory.getBean("test1"); @@ -157,7 +159,7 @@ public final class ProxyFactoryBeanTests { catch (BeanCreationException ex) { // Root cause of the problem must be an AOP exception AopConfigException aex = (AopConfigException) ex.getCause(); - assertTrue(aex.getMessage().indexOf("interceptorNames") != -1); + assertTrue(aex.getMessage().contains("interceptorNames")); } } @@ -332,13 +334,6 @@ public final class ProxyFactoryBeanTests { } } - public static class DependsOnITestBean { - public final ITestBean tb; - public DependsOnITestBean(ITestBean tb) { - this.tb = tb; - } - } - /** * Test that inner bean for target means that we can use * autowire without ambiguity from target and proxy @@ -711,6 +706,8 @@ public final class ProxyFactoryBeanTests { ITestBean proxy = (ITestBean) fb.getObject(); assertTrue(AopUtils.isJdkDynamicProxy(proxy)); } + + /** * Fires only on void methods. Saves list of methods intercepted. */ @@ -733,7 +730,7 @@ public final class ProxyFactoryBeanTests { }); setPointcut(new DynamicMethodMatcherPointcut() { @Override - public boolean matches(Method m, Class targetClass, Object[] args) { + public boolean matches(Method m, Class targetClass, Object... args) { return m.getReturnType() == Void.TYPE; } }); @@ -741,10 +738,20 @@ public final class ProxyFactoryBeanTests { } + public static class DependsOnITestBean { + + public final ITestBean tb; + + public DependsOnITestBean(ITestBean tb) { + this.tb = tb; + } + } + /** * Aspect interface */ public interface AddedGlobalInterface { + int globalsAdded(); }