|
32 | 32 | * Unit tests for {@link PreferredConstructorDiscoverer}.
|
33 | 33 | *
|
34 | 34 | * @author Oliver Gierke
|
| 35 | + * @author Roman Rodov |
35 | 36 | */
|
36 | 37 | public class PreferredConstructorDiscovererUnitTests<P extends PersistentProperty<P>> {
|
37 | 38 |
|
@@ -97,6 +98,34 @@ public void discoversInnerClassConstructorCorrectly() {
|
97 | 98 | assertThat(constructor.isEnclosingClassParameter(parameter), is(true));
|
98 | 99 | }
|
99 | 100 |
|
| 101 | + @Test // DATACMNS-1082 |
| 102 | + public void skipsSyntheticConstructor() { |
| 103 | + |
| 104 | + PersistentEntity<SyntheticConstructor, P> entity = new BasicPersistentEntity<SyntheticConstructor, P>( |
| 105 | + ClassTypeInformation.from(SyntheticConstructor.class)); |
| 106 | + PreferredConstructorDiscoverer<SyntheticConstructor, P> discoverer = // |
| 107 | + new PreferredConstructorDiscoverer<SyntheticConstructor, P>(entity); |
| 108 | + |
| 109 | + PreferredConstructor<SyntheticConstructor, P> constructor = discoverer.getConstructor(); |
| 110 | + |
| 111 | + PersistenceConstructor annotation = constructor.getConstructor().getAnnotation(PersistenceConstructor.class); |
| 112 | + assertNotNull("The preferred constructor should have 'PersistenctConstructor' annotation.", annotation); |
| 113 | + assertFalse("The preferred constructor must not be synthetic", constructor.getConstructor().isSynthetic()); |
| 114 | + } |
| 115 | + |
| 116 | + static class SyntheticConstructor { |
| 117 | + @PersistenceConstructor |
| 118 | + private SyntheticConstructor(String x) {} |
| 119 | + |
| 120 | + class InnerSynthetic { |
| 121 | + // Compiler will generate a synthetic constructor since |
| 122 | + // SyntheticConstructor() is private. |
| 123 | + InnerSynthetic() { |
| 124 | + new SyntheticConstructor(""); |
| 125 | + } |
| 126 | + } |
| 127 | + } |
| 128 | + |
100 | 129 | static class EntityWithoutConstructor {
|
101 | 130 |
|
102 | 131 | }
|
|
0 commit comments