|
41 | 41 | import org.springframework.data.annotation.Id;
|
42 | 42 | import org.springframework.data.mapping.MappingException;
|
43 | 43 | import org.springframework.data.mapping.PersistentEntity;
|
| 44 | +import org.springframework.data.mapping.PropertyHandler; |
| 45 | +import org.springframework.data.mapping.ShadowedPropertyType; |
| 46 | +import org.springframework.data.mapping.ShadowedPropertyTypeWithCtor; |
| 47 | +import org.springframework.data.mapping.ShadowingPropertyType; |
| 48 | +import org.springframework.data.mapping.ShadowingPropertyTypeWithCtor; |
44 | 49 | import org.springframework.data.mapping.model.BasicPersistentEntity;
|
45 | 50 | import org.springframework.data.mapping.model.SimpleTypeHolder;
|
46 | 51 | import org.springframework.data.util.ClassTypeInformation;
|
| 52 | +import org.springframework.data.util.StreamUtils; |
47 | 53 | import org.springframework.data.util.TypeInformation;
|
48 | 54 |
|
49 | 55 | /**
|
|
52 | 58 | * @author Oliver Gierke
|
53 | 59 | * @author Thomas Darimont
|
54 | 60 | * @author Mark Paluch
|
| 61 | + * @author Christoph Stobl |
55 | 62 | */
|
56 | 63 | class AbstractMappingContextUnitTests {
|
57 | 64 |
|
@@ -216,6 +223,37 @@ void cleansUpCacheForRuntimeException() {
|
216 | 223 | .isThrownBy(() -> context.getPersistentEntity(Unsupported.class));
|
217 | 224 | }
|
218 | 225 |
|
| 226 | + @Test // DATACMNS-1509 |
| 227 | + public void shouldIgnoreKotlinOverrideCtorPropertyInSuperClass() { |
| 228 | + |
| 229 | + BasicPersistentEntity<Object, SamplePersistentProperty> entity = context |
| 230 | + .getPersistentEntity(ClassTypeInformation.from(ShadowingPropertyTypeWithCtor.class)); |
| 231 | + entity.doWithProperties((PropertyHandler<SamplePersistentProperty>) property -> { |
| 232 | + assertThat(property.getField().getDeclaringClass()).isNotEqualTo(ShadowedPropertyTypeWithCtor.class); |
| 233 | + }); |
| 234 | + } |
| 235 | + |
| 236 | + @Test // DATACMNS-1509 |
| 237 | + public void shouldIgnoreKotlinOverridePropertyInSuperClass() { |
| 238 | + |
| 239 | + BasicPersistentEntity<Object, SamplePersistentProperty> entity = context |
| 240 | + .getPersistentEntity(ClassTypeInformation.from(ShadowingPropertyType.class)); |
| 241 | + entity.doWithProperties((PropertyHandler<SamplePersistentProperty>) property -> { |
| 242 | + assertThat(property.getField().getDeclaringClass()).isNotEqualTo(ShadowedPropertyType.class); |
| 243 | + }); |
| 244 | + } |
| 245 | + |
| 246 | + @Test // DATACMNS-1509 |
| 247 | + public void shouldStillIncludeNonKotlinShadowedPropertyInSuperClass() { |
| 248 | + |
| 249 | + BasicPersistentEntity<Object, SamplePersistentProperty> entity = context |
| 250 | + .getPersistentEntity(ClassTypeInformation.from(ShadowingProperty.class)); |
| 251 | + |
| 252 | + assertThat(StreamUtils.createStreamFromIterator(entity.iterator()) |
| 253 | + .filter(it -> it.getField().getDeclaringClass().equals(ShadowedProperty.class)).findFirst() // |
| 254 | + ).isNotEmpty(); |
| 255 | + } |
| 256 | + |
219 | 257 | private static void assertHasEntityFor(Class<?> type, SampleMappingContext context, boolean expected) {
|
220 | 258 |
|
221 | 259 | boolean found = false;
|
@@ -306,4 +344,37 @@ public void verify() {
|
306 | 344 | };
|
307 | 345 | }
|
308 | 346 | }
|
| 347 | + |
| 348 | + static class ShadowedProperty { |
| 349 | + |
| 350 | + private final String value; |
| 351 | + |
| 352 | + ShadowedProperty(String value) { |
| 353 | + this.value = value; |
| 354 | + } |
| 355 | + |
| 356 | + public String getValue() { |
| 357 | + return value; |
| 358 | + } |
| 359 | + } |
| 360 | + |
| 361 | + static class ShadowingProperty extends ShadowedProperty { |
| 362 | + |
| 363 | + private String value; |
| 364 | + |
| 365 | + ShadowingProperty(String value) { |
| 366 | + super(value); |
| 367 | + this.value = value; |
| 368 | + } |
| 369 | + |
| 370 | + public void setValue(String value) { |
| 371 | + this.value = value; |
| 372 | + } |
| 373 | + |
| 374 | + @Override |
| 375 | + public String getValue() { |
| 376 | + return value; |
| 377 | + } |
| 378 | + } |
| 379 | + |
309 | 380 | }
|
0 commit comments