Skip to content

Commit e83e3ec

Browse files
committed
Add failing test for @qualifier as composed annotation
Issue: SPR-14058
1 parent dfd4aae commit e83e3ec

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

spring-context/src/test/java/org/springframework/beans/factory/support/QualifierAnnotationAutowireContextTests.java

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121
import java.lang.annotation.RetentionPolicy;
2222
import java.lang.annotation.Target;
2323

24+
import org.junit.Ignore;
2425
import org.junit.Test;
2526

2627
import org.springframework.aop.scope.ScopedProxyUtils;
@@ -33,6 +34,7 @@
3334
import org.springframework.beans.factory.config.ConstructorArgumentValues;
3435
import org.springframework.context.annotation.AnnotationConfigUtils;
3536
import org.springframework.context.support.GenericApplicationContext;
37+
import org.springframework.core.annotation.AliasFor;
3638

3739
import static org.junit.Assert.*;
3840

@@ -42,13 +44,15 @@
4244
* @author Mark Fisher
4345
* @author Juergen Hoeller
4446
* @author Chris Beams
47+
* @author Sam Brannen
4548
*/
4649
public class QualifierAnnotationAutowireContextTests {
4750

4851
private static final String JUERGEN = "juergen";
4952

5053
private static final String MARK = "mark";
5154

55+
private static final String SAM = "sam";
5256

5357
@Test
5458
public void testAutowiredFieldWithSingleNonQualifiedCandidate() {
@@ -308,6 +312,24 @@ public void testAutowiredFieldResolvesMetaQualifiedCandidate() {
308312
assertEquals(JUERGEN, bean.getPerson().getName());
309313
}
310314

315+
/**
316+
* @see SpringBean
317+
*/
318+
@Test
319+
@Ignore("Disabled until SPR-14058 is resolved")
320+
public void autowiredFieldResolutionIgnoresEmptyQualifierFromComposedQualifierAnnotation() {
321+
GenericApplicationContext context = new GenericApplicationContext();
322+
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
323+
cavs1.addGenericArgumentValue(SAM);
324+
RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
325+
context.registerBeanDefinition(SAM, person1);
326+
context.registerBeanDefinition("autowired", new RootBeanDefinition(ComposedAnnotationQualifiedFieldTestBean.class));
327+
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
328+
context.refresh();
329+
ComposedAnnotationQualifiedFieldTestBean bean = context.getBean(ComposedAnnotationQualifiedFieldTestBean.class);
330+
assertEquals(SAM, bean.getPerson().getName());
331+
}
332+
311333
@Test
312334
public void testAutowiredMethodParameterResolvesQualifiedCandidate() {
313335
GenericApplicationContext context = new GenericApplicationContext();
@@ -635,6 +657,37 @@ public Person getPerson() {
635657
}
636658

637659

660+
/**
661+
* {@code @SpringBean} is a composed annotation that combines the semantics of
662+
* {@code Autowired @Autowired} and {@code Qualifier @Qualifier}
663+
*/
664+
@Autowired
665+
@Qualifier
666+
@Retention(RetentionPolicy.RUNTIME)
667+
public @interface SpringBean {
668+
669+
@AliasFor(annotation = Qualifier.class)
670+
String value() default "";
671+
672+
@AliasFor(annotation = Qualifier.class, attribute = "value")
673+
String qualifier() default "";
674+
675+
@AliasFor(annotation = Autowired.class)
676+
boolean required() default true;
677+
678+
}
679+
680+
private static class ComposedAnnotationQualifiedFieldTestBean {
681+
682+
@SpringBean
683+
private Person person;
684+
685+
public Person getPerson() {
686+
return this.person;
687+
}
688+
}
689+
690+
638691
private static class QualifiedMethodParameterTestBean {
639692

640693
private Person person;

0 commit comments

Comments
 (0)