@Test(expected = IllegalArgumentException.class) public void multipleAnnotations() { AnnotationMethodResolver resolver = new AnnotationMethodResolver(TestAnnotation.class); resolver.findMethod(MultipleAnnotationTestBean.class); }
/** * Find a <em>single</em> Method on the Class of the given candidate object * that contains the annotation type for which this resolver is searching. * * @param candidate the instance whose Class will be checked for the * annotation * * @return a single matching Method instance or <code>null</code> if the * candidate's Class contains no Methods with the specified annotation * * @throws IllegalArgumentException if more than one Method has the * specified annotation */ @Override public Method findMethod(Object candidate) { Assert.notNull(candidate, "candidate object must not be null"); Class<?> targetClass = AopUtils.getTargetClass(candidate); if (targetClass == null) { targetClass = candidate.getClass(); } return this.findMethod(targetClass); }
/** * Find a <em>single</em> Method on the Class of the given candidate object * that contains the annotation type for which this resolver is searching. * * @param candidate the instance whose Class will be checked for the * annotation * * @return a single matching Method instance or <code>null</code> if the * candidate's Class contains no Methods with the specified annotation * * @throws IllegalArgumentException if more than one Method has the * specified annotation */ @Override public Method findMethod(Object candidate) { Assert.notNull(candidate, "candidate object must not be null"); Class<?> targetClass = AopUtils.getTargetClass(candidate); if (targetClass == null) { targetClass = candidate.getClass(); } return this.findMethod(targetClass); }
@Test public void noAnnotations() { AnnotationMethodResolver resolver = new AnnotationMethodResolver(TestAnnotation.class); Method method = resolver.findMethod(NoAnnotationTestBean.class); assertNull(method); }
@Test public void singleAnnotation() { AnnotationMethodResolver resolver = new AnnotationMethodResolver(TestAnnotation.class); Method method = resolver.findMethod(SingleAnnotationTestBean.class); assertNotNull(method); }