|
23 | 23 | import java.lang.reflect.Constructor;
|
24 | 24 | import java.util.Arrays;
|
25 | 25 | import java.util.List;
|
| 26 | +import java.util.Map; |
26 | 27 | import java.util.stream.IntStream;
|
27 | 28 |
|
28 | 29 | import org.junit.jupiter.api.Test;
|
|
39 | 40 | import org.springframework.data.mapping.PreferredConstructor.Parameter;
|
40 | 41 | import org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator.ObjectInstantiator;
|
41 | 42 | import org.springframework.data.mapping.model.ClassGeneratingEntityInstantiatorUnitTests.Outer.Inner;
|
| 43 | +import org.springframework.data.util.TypeInformation; |
| 44 | +import org.springframework.test.util.ReflectionTestUtils; |
42 | 45 | import org.springframework.util.ReflectionUtils;
|
43 | 46 |
|
44 | 47 | /**
|
@@ -210,6 +213,9 @@ void instantiateObjCtorNoArgs() {
|
210 | 213 | assertThat(instance).isInstanceOf(ObjCtorNoArgs.class);
|
211 | 214 | assertThat(((ObjCtorNoArgs) instance).ctorInvoked).isTrue();
|
212 | 215 | });
|
| 216 | + |
| 217 | + ClassGeneratingEntityInstantiator classGeneratingEntityInstantiator = new ClassGeneratingEntityInstantiator(); |
| 218 | + classGeneratingEntityInstantiator.createInstance(entity, provider); |
213 | 219 | }
|
214 | 220 |
|
215 | 221 | @Test // DATACMNS-578, DATACMNS-1126
|
@@ -360,6 +366,26 @@ void shouldNotInstantiateClassWithPrivateConstructor() {
|
360 | 366 | assertThat(this.instance.shouldUseReflectionEntityInstantiator(entity)).isTrue();
|
361 | 367 | }
|
362 | 368 |
|
| 369 | + @Test // GH-2446 |
| 370 | + void shouldReuseGeneratedClasses() { |
| 371 | + |
| 372 | + prepareMocks(ProtectedInnerClass.class); |
| 373 | + |
| 374 | + this.instance.createInstance(entity, provider); |
| 375 | + |
| 376 | + ClassGeneratingEntityInstantiator instantiator = new ClassGeneratingEntityInstantiator(); |
| 377 | + instantiator.createInstance(entity, provider); |
| 378 | + |
| 379 | + Map<TypeInformation<?>, EntityInstantiator> first = (Map<TypeInformation<?>, EntityInstantiator>) ReflectionTestUtils |
| 380 | + .getField(this.instance, "entityInstantiators"); |
| 381 | + |
| 382 | + Map<TypeInformation<?>, EntityInstantiator> second = (Map<TypeInformation<?>, EntityInstantiator>) ReflectionTestUtils |
| 383 | + .getField(instantiator, "entityInstantiators"); |
| 384 | + |
| 385 | + assertThat(first.get(null)).isNotNull().isNotInstanceOf(Enum.class); |
| 386 | + assertThat(second.get(null)).isNotNull().isNotInstanceOf(Enum.class); |
| 387 | + } |
| 388 | + |
363 | 389 | @Test // DATACMNS-1422
|
364 | 390 | void shouldUseReflectionIfFrameworkTypesNotVisible() throws Exception {
|
365 | 391 |
|
|
0 commit comments