Skip to content

Commit e2bb06e

Browse files
committed
Unit tests for unresolvable generics with partial mismatch
Issue: SPR-16179
1 parent 3091fee commit e2bb06e

File tree

2 files changed

+100
-2
lines changed

2 files changed

+100
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright 2002-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.context.annotation;
18+
19+
import org.junit.Test;
20+
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
23+
import static org.junit.Assert.*;
24+
25+
/**
26+
* @author Juergen Hoeller
27+
* @author Oliver Gierke
28+
*/
29+
public class Spr16179Tests {
30+
31+
@Test
32+
public void repro() {
33+
AnnotationConfigApplicationContext bf =
34+
new AnnotationConfigApplicationContext(AssemblerConfig.class, AssemblerInjection.class);
35+
36+
assertSame(bf.getBean("someAssembler"), bf.getBean(AssemblerInjection.class).assembler0);
37+
// assertNull(bf.getBean(AssemblerInjection.class).assembler1); TODO: accidental match
38+
// assertNull(bf.getBean(AssemblerInjection.class).assembler2);
39+
assertSame(bf.getBean("pageAssembler"), bf.getBean(AssemblerInjection.class).assembler3);
40+
assertSame(bf.getBean("pageAssembler"), bf.getBean(AssemblerInjection.class).assembler4);
41+
assertSame(bf.getBean("pageAssembler"), bf.getBean(AssemblerInjection.class).assembler5);
42+
assertSame(bf.getBean("pageAssembler"), bf.getBean(AssemblerInjection.class).assembler6);
43+
}
44+
45+
46+
@Configuration
47+
static class AssemblerConfig {
48+
49+
@Bean
50+
PageAssemblerImpl<?> pageAssembler() {
51+
return new PageAssemblerImpl<>();
52+
}
53+
54+
@Bean
55+
Assembler<SomeType> someAssembler() {
56+
return new Assembler<SomeType>() {};
57+
}
58+
}
59+
60+
61+
public static class AssemblerInjection {
62+
63+
@Autowired(required = false)
64+
Assembler<SomeType> assembler0;
65+
66+
@Autowired(required = false)
67+
Assembler<SomeOtherType> assembler1;
68+
69+
@Autowired(required = false)
70+
Assembler<Page<String>> assembler2;
71+
72+
@Autowired(required = false)
73+
Assembler<Page> assembler3;
74+
75+
@Autowired(required = false)
76+
Assembler<Page<?>> assembler4;
77+
78+
@Autowired(required = false)
79+
PageAssembler<?> assembler5;
80+
81+
@Autowired(required = false)
82+
PageAssembler<String> assembler6;
83+
}
84+
85+
86+
interface Assembler<T> {}
87+
88+
interface PageAssembler<T> extends Assembler<Page<T>> {}
89+
90+
static class PageAssemblerImpl<T> implements PageAssembler<T> {}
91+
92+
interface Page<T> {}
93+
94+
interface SomeType {}
95+
96+
interface SomeOtherType {}
97+
98+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -39,7 +39,7 @@
3939
* @author Oliver Gierke
4040
*/
4141
@SuppressWarnings("resource")
42-
public class ConfigurationClassSpr8954Tests {
42+
public class Spr8954Tests {
4343

4444
@Test
4545
public void repro() {

0 commit comments

Comments
 (0)