@Override public boolean isAnnotated(String annotationName) { return AnnotatedElementUtils.isAnnotated(this.introspectedMethod, annotationName); }
/** * Determine whether the given class is an {@code org.springframework} * bean class that is not annotated as a user or test {@link Component}... * which indicates that there is no {@link EventListener} to be found there. * @since 5.1 */ private static boolean isSpringContainerClass(Class<?> clazz) { return (clazz.getName().startsWith("org.springframework.") && !AnnotatedElementUtils.isAnnotated(ClassUtils.getUserClass(clazz), Component.class)); }
@Override public boolean isAnnotated(String annotationName) { return (this.annotations.length > 0 && AnnotatedElementUtils.isAnnotated(getIntrospectedClass(), annotationName)); }
@Test public void isAnnotatedOnClassWithMetaDepth2() { assertTrue(isAnnotated(ComposedTransactionalComponentClass.class, TX_NAME)); assertTrue(isAnnotated(ComposedTransactionalComponentClass.class, Component.class.getName())); assertTrue(isAnnotated(ComposedTransactionalComponentClass.class, ComposedTransactionalComponent.class.getName())); }
@Test public void isAnnotatedOnClassWithMetaDepth1() { assertTrue(isAnnotated(TransactionalComponentClass.class, TX_NAME)); assertTrue(isAnnotated(TransactionalComponentClass.class, Component.class.getName())); }
@Test public void isAnnotatedOnSubclassWithMetaDepth0() { assertFalse("isAnnotated() does not search the class hierarchy.", isAnnotated(SubTransactionalComponentClass.class, TransactionalComponent.class.getName())); }
@Test public void isAnnotatedOnClassWithMetaDepth0() { assertTrue(isAnnotated(TransactionalComponentClass.class, TransactionalComponent.class.getName())); }
@Test public void getMergedAnnotationAttributesOnNonInheritedAnnotationInterface() { Class<?> element = NonInheritedAnnotationInterface.class; String name = Order.class.getName(); AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name); assertNotNull("Should find @Order on NonInheritedAnnotationInterface", attributes); // Verify contracts between utility methods: assertTrue(isAnnotated(element, name)); }
private void getMergedAnnotationAttributesWithHalfConventionBasedAndHalfAliasedComposedAnnotation(Class<?> clazz) { String[] expected = asArray("explicitDeclaration"); String name = ContextConfig.class.getName(); String simpleName = clazz.getSimpleName(); AnnotationAttributes attributes = getMergedAnnotationAttributes(clazz, name); assertNotNull("Should find @ContextConfig on " + simpleName, attributes); assertArrayEquals("locations for class [" + clazz.getSimpleName() + "]", expected, attributes.getStringArray("locations")); assertArrayEquals("value for class [" + clazz.getSimpleName() + "]", expected, attributes.getStringArray("value")); // Verify contracts between utility methods: assertTrue(isAnnotated(clazz, name)); }
@Test public void getMergedAnnotationAttributesOnInheritedAnnotationInterface() { Class<?> element = InheritedAnnotationInterface.class; String name = TX_NAME; AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name); assertNotNull("Should find @Transactional on InheritedAnnotationInterface", attributes); // Verify contracts between utility methods: assertTrue(isAnnotated(element, name)); }
@Test public void getMergedAnnotationAttributesFromInterfaceImplementedBySuperclass() { Class<?> element = ConcreteClassWithInheritedAnnotation.class; String name = TX_NAME; AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name); assertNull("Should not find @Transactional on ConcreteClassWithInheritedAnnotation", attributes); // Verify contracts between utility methods: assertFalse(isAnnotated(element, name)); }
private void assertGetMergedAnnotation(Class<?> element, String... expected) { String name = ContextConfig.class.getName(); ContextConfig contextConfig = getMergedAnnotation(element, ContextConfig.class); assertNotNull("Should find @ContextConfig on " + element.getSimpleName(), contextConfig); assertArrayEquals("locations", expected, contextConfig.locations()); assertArrayEquals("value", expected, contextConfig.value()); assertArrayEquals("classes", new Class<?>[0], contextConfig.classes()); // Verify contracts between utility methods: assertTrue(isAnnotated(element, name)); }
@Test public void getMergedAnnotationAttributesWithAliasedComposedAnnotation() { Class<?> element = AliasedComposedContextConfigClass.class; String name = ContextConfig.class.getName(); AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name); assertNotNull("Should find @ContextConfig on " + element.getSimpleName(), attributes); assertArrayEquals("value", asArray("test.xml"), attributes.getStringArray("value")); assertArrayEquals("locations", asArray("test.xml"), attributes.getStringArray("locations")); // Verify contracts between utility methods: assertTrue(isAnnotated(element, name)); }
@Test public void getMergedAnnotationAttributesWithAliasedValueComposedAnnotation() { Class<?> element = AliasedValueComposedContextConfigClass.class; String name = ContextConfig.class.getName(); AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name); assertNotNull("Should find @ContextConfig on " + element.getSimpleName(), attributes); assertArrayEquals("locations", asArray("test.xml"), attributes.getStringArray("locations")); assertArrayEquals("value", asArray("test.xml"), attributes.getStringArray("value")); // Verify contracts between utility methods: assertTrue(isAnnotated(element, name)); }
@Test public void getMergedAnnotationAttributesWithConventionBasedComposedAnnotation() { Class<?> element = ConventionBasedComposedContextConfigClass.class; String name = ContextConfig.class.getName(); AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name); assertNotNull("Should find @ContextConfig on " + element.getSimpleName(), attributes); assertArrayEquals("locations", asArray("explicitDeclaration"), attributes.getStringArray("locations")); assertArrayEquals("value", asArray("explicitDeclaration"), attributes.getStringArray("value")); // Verify contracts between utility methods: assertTrue(isAnnotated(element, name)); }
@Test public void getMergedAnnotationAttributesFavorsInheritedComposedAnnotationsOverMoreLocallyDeclaredComposedAnnotations() { Class<?> element = SubSubClassWithInheritedComposedAnnotation.class; String name = TX_NAME; AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name); assertNotNull("AnnotationAttributes for @Transactional on SubSubClassWithInheritedComposedAnnotation.", attributes); // Verify contracts between utility methods: assertTrue(isAnnotated(element, name)); assertFalse("readOnly flag for SubSubClassWithInheritedComposedAnnotation.", attributes.getBoolean("readOnly")); }
@Test public void getMergedAnnotationAttributesFavorsLocalComposedAnnotationOverInheritedAnnotation() { Class<?> element = SubClassWithInheritedAnnotation.class; String name = TX_NAME; AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name); assertNotNull("AnnotationAttributes for @Transactional on SubClassWithInheritedAnnotation", attributes); // Verify contracts between utility methods: assertTrue(isAnnotated(element, name)); assertTrue("readOnly flag for SubClassWithInheritedAnnotation.", attributes.getBoolean("readOnly")); }
@Test public void getMergedAnnotationAttributesOnClassWithLocalAnnotation() { Class<?> element = TxConfig.class; String name = TX_NAME; AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name); assertNotNull("Annotation attributes for @Transactional on TxConfig", attributes); assertEquals("value for TxConfig.", "TxConfig", attributes.getString("value")); // Verify contracts between utility methods: assertTrue(isAnnotated(element, name)); }
@Test public void getMergedAnnotationAttributesOnClassWithLocalAnnotationThatShadowsAnnotationFromSuperclass() { Class<?> element = DerivedTxConfig.class; String name = TX_NAME; AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name); assertNotNull("Annotation attributes for @Transactional on DerivedTxConfig", attributes); assertEquals("value for DerivedTxConfig.", "DerivedTxConfig", attributes.getString("value")); // Verify contracts between utility methods: assertTrue(isAnnotated(element, name)); }
@Test public void getMergedAnnotationAttributesFavorsInheritedAnnotationsOverMoreLocallyDeclaredComposedAnnotations() { Class<?> element = SubSubClassWithInheritedAnnotation.class; String name = TX_NAME; AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name); assertNotNull("AnnotationAttributes for @Transactional on SubSubClassWithInheritedAnnotation", attributes); // Verify contracts between utility methods: assertTrue(isAnnotated(element, name)); assertFalse("readOnly flag for SubSubClassWithInheritedAnnotation.", attributes.getBoolean("readOnly")); }