diff --git a/spring-context/src/test/java/org/springframework/context/annotation/Spr16179Tests.java b/spring-context/src/test/java/org/springframework/context/annotation/Spr16179Tests.java new file mode 100644 index 00000000000..1cb2e2e771b --- /dev/null +++ b/spring-context/src/test/java/org/springframework/context/annotation/Spr16179Tests.java @@ -0,0 +1,98 @@ +/* + * Copyright 2002-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.context.annotation; + +import org.junit.Test; + +import org.springframework.beans.factory.annotation.Autowired; + +import static org.junit.Assert.*; + +/** + * @author Juergen Hoeller + * @author Oliver Gierke + */ +public class Spr16179Tests { + + @Test + public void repro() { + AnnotationConfigApplicationContext bf = + new AnnotationConfigApplicationContext(AssemblerConfig.class, AssemblerInjection.class); + + assertSame(bf.getBean("someAssembler"), bf.getBean(AssemblerInjection.class).assembler0); + // assertNull(bf.getBean(AssemblerInjection.class).assembler1); TODO: accidental match + // assertNull(bf.getBean(AssemblerInjection.class).assembler2); + assertSame(bf.getBean("pageAssembler"), bf.getBean(AssemblerInjection.class).assembler3); + assertSame(bf.getBean("pageAssembler"), bf.getBean(AssemblerInjection.class).assembler4); + assertSame(bf.getBean("pageAssembler"), bf.getBean(AssemblerInjection.class).assembler5); + assertSame(bf.getBean("pageAssembler"), bf.getBean(AssemblerInjection.class).assembler6); + } + + + @Configuration + static class AssemblerConfig { + + @Bean + PageAssemblerImpl pageAssembler() { + return new PageAssemblerImpl<>(); + } + + @Bean + Assembler someAssembler() { + return new Assembler() {}; + } + } + + + public static class AssemblerInjection { + + @Autowired(required = false) + Assembler assembler0; + + @Autowired(required = false) + Assembler assembler1; + + @Autowired(required = false) + Assembler> assembler2; + + @Autowired(required = false) + Assembler assembler3; + + @Autowired(required = false) + Assembler> assembler4; + + @Autowired(required = false) + PageAssembler assembler5; + + @Autowired(required = false) + PageAssembler assembler6; + } + + + interface Assembler {} + + interface PageAssembler extends Assembler> {} + + static class PageAssemblerImpl implements PageAssembler {} + + interface Page {} + + interface SomeType {} + + interface SomeOtherType {} + +} diff --git a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassSpr8954Tests.java b/spring-context/src/test/java/org/springframework/context/annotation/Spr8954Tests.java similarity index 97% rename from spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassSpr8954Tests.java rename to spring-context/src/test/java/org/springframework/context/annotation/Spr8954Tests.java index 114fea7c221..c321cdbeacf 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassSpr8954Tests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/Spr8954Tests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2017 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. @@ -39,7 +39,7 @@ import static org.junit.Assert.*; * @author Oliver Gierke */ @SuppressWarnings("resource") -public class ConfigurationClassSpr8954Tests { +public class Spr8954Tests { @Test public void repro() {