|
33 | 33 | * @author Oliver Gierke
|
34 | 34 | * @author Roman Rodov
|
35 | 35 | * @author Mark Paluch
|
| 36 | + * @author Christoph Strobl |
36 | 37 | */
|
37 | 38 | public class PreferredConstructorDiscovererUnitTests<P extends PersistentProperty<P>> {
|
38 | 39 |
|
@@ -112,6 +113,30 @@ public void skipsSyntheticConstructor() {
|
112 | 113 | });
|
113 | 114 | }
|
114 | 115 |
|
| 116 | + @Test // GH-2313 |
| 117 | + void capturesEnclosingTypeParameterOfNonStaticInnerClass() { |
| 118 | + |
| 119 | + assertThat(PreferredConstructorDiscoverer.discover(NonStaticWithGenericTypeArgUsedInCtor.class)) |
| 120 | + .satisfies(ctor -> { |
| 121 | + |
| 122 | + assertThat(ctor.getParameters()).hasSize(2); |
| 123 | + assertThat(ctor.getParameters().get(0).getName()).isEqualTo("this$0"); |
| 124 | + assertThat(ctor.getParameters().get(1).getName()).isEqualTo("value"); |
| 125 | + }); |
| 126 | + } |
| 127 | + |
| 128 | + @Test // GH-2313 |
| 129 | + void capturesSuperClassEnclosingTypeParameterOfNonStaticInnerClass() { |
| 130 | + |
| 131 | + assertThat(PreferredConstructorDiscoverer.discover(NonStaticInnerWithGenericArgUsedInCtor.class)) |
| 132 | + .satisfies(ctor -> { |
| 133 | + |
| 134 | + assertThat(ctor.getParameters()).hasSize(2); |
| 135 | + assertThat(ctor.getParameters().get(0).getName()).isEqualTo("this$0"); |
| 136 | + assertThat(ctor.getParameters().get(1).getName()).isEqualTo("value"); |
| 137 | + }); |
| 138 | + } |
| 139 | + |
115 | 140 | static class SyntheticConstructor {
|
116 | 141 | @PersistenceConstructor
|
117 | 142 | private SyntheticConstructor(String x) {}
|
@@ -164,4 +189,22 @@ class Inner {
|
164 | 189 |
|
165 | 190 | }
|
166 | 191 | }
|
| 192 | + |
| 193 | + static class GenericTypeArgUsedInCtor<T> { |
| 194 | + |
| 195 | + protected GenericTypeArgUsedInCtor(T value) {} |
| 196 | + } |
| 197 | + |
| 198 | + |
| 199 | + class NonStaticWithGenericTypeArgUsedInCtor<T> { |
| 200 | + |
| 201 | + protected NonStaticWithGenericTypeArgUsedInCtor(T value) {} |
| 202 | + } |
| 203 | + |
| 204 | + class NonStaticInnerWithGenericArgUsedInCtor<T> extends GenericTypeArgUsedInCtor<T> { |
| 205 | + |
| 206 | + public NonStaticInnerWithGenericArgUsedInCtor(T value) { |
| 207 | + super(value); |
| 208 | + } |
| 209 | + } |
167 | 210 | }
|
0 commit comments