|
16 | 16 | package org.springframework.data.mapping; |
17 | 17 |
|
18 | 18 | import static org.assertj.core.api.Assertions.*; |
| 19 | +import static org.mockito.Mockito.*; |
19 | 20 |
|
20 | 21 | import java.lang.annotation.Annotation; |
21 | 22 |
|
22 | 23 | import org.junit.jupiter.api.Test; |
23 | 24 | import org.junit.jupiter.api.extension.ExtendWith; |
24 | 25 | import org.mockito.Mock; |
| 26 | +import org.mockito.Mockito; |
25 | 27 | import org.mockito.junit.jupiter.MockitoExtension; |
| 28 | +import org.springframework.data.mapping.ParameterUnitTests.IFace.ClassMember; |
| 29 | +import org.springframework.data.mapping.ParameterUnitTests.IFace.RecordMember; |
| 30 | +import org.springframework.data.mapping.ParameterUnitTests.StaticType.NonStaticInner; |
| 31 | +import org.springframework.data.mapping.ParameterUnitTests.StaticType.RecordInner; |
| 32 | +import org.springframework.data.mapping.ParameterUnitTests.StaticType.StaticInner; |
26 | 33 | import org.springframework.data.util.TypeInformation; |
27 | 34 |
|
28 | 35 | /** |
29 | 36 | * Unit tests for {@link Parameter}. |
30 | 37 | * |
31 | 38 | * @author Oliver Gierke |
| 39 | + * @author Christoph Strobl |
32 | 40 | */ |
33 | 41 | @ExtendWith(MockitoExtension.class) |
34 | 42 | class ParameterUnitTests<P extends PersistentProperty<P>> { |
@@ -87,4 +95,81 @@ void twoParametersWithDifferenTypeAreNotEqual() { |
87 | 95 |
|
88 | 96 | assertThat(left).isNotEqualTo(right); |
89 | 97 | } |
| 98 | + |
| 99 | + @Test // GH-3038 |
| 100 | + void shouldNotConsiderRecordTypeOfInterfaceEnclosingClassParameter() { |
| 101 | + |
| 102 | + PersistentEntity pe = Mockito.mock(PersistentEntity.class); |
| 103 | + when(pe.getType()).thenReturn(RecordMember.class); |
| 104 | + |
| 105 | + Parameter<IFace, P> iFace = new Parameter<IFace, P>("iFace", TypeInformation.of(IFace.class), annotations, pe); |
| 106 | + assertThat(iFace.isEnclosingClassParameter()).isFalse(); |
| 107 | + } |
| 108 | + |
| 109 | + @Test // GH-3038 |
| 110 | + void shouldNotConsiderMemberTypeOfInterfaceEnclosingClassParameter() { |
| 111 | + |
| 112 | + PersistentEntity pe = Mockito.mock(PersistentEntity.class); |
| 113 | + when(pe.getType()).thenReturn(ClassMember.class); |
| 114 | + |
| 115 | + Parameter<IFace, P> iFace = new Parameter<IFace, P>("iFace", TypeInformation.of(IFace.class), annotations, pe); |
| 116 | + assertThat(iFace.isEnclosingClassParameter()).isFalse(); |
| 117 | + } |
| 118 | + |
| 119 | + @Test // GH-3038 |
| 120 | + void shouldConsiderMemberTypeOfClassEnclosingClassParameter() { |
| 121 | + |
| 122 | + PersistentEntity pe = Mockito.mock(PersistentEntity.class); |
| 123 | + when(pe.getType()).thenReturn(NonStaticInner.class); |
| 124 | + |
| 125 | + Parameter<StaticType, P> iFace = new Parameter<StaticType, P>("outer", TypeInformation.of(StaticType.class), |
| 126 | + annotations, pe); |
| 127 | + assertThat(iFace.isEnclosingClassParameter()).isTrue(); |
| 128 | + } |
| 129 | + |
| 130 | + @Test // GH-3038 |
| 131 | + void shouldNotConsiderStaticMemberTypeOfClassEnclosingClassParameter() { |
| 132 | + |
| 133 | + PersistentEntity pe = Mockito.mock(PersistentEntity.class); |
| 134 | + when(pe.getType()).thenReturn(StaticInner.class); |
| 135 | + |
| 136 | + Parameter<StaticType, P> iFace = new Parameter<StaticType, P>("outer", TypeInformation.of(StaticType.class), |
| 137 | + annotations, pe); |
| 138 | + assertThat(iFace.isEnclosingClassParameter()).isFalse(); |
| 139 | + } |
| 140 | + |
| 141 | + @Test // GH-3038 |
| 142 | + void shouldNotConsiderRecordMemberTypeOfClassEnclosingClassParameter() { |
| 143 | + |
| 144 | + PersistentEntity pe = Mockito.mock(PersistentEntity.class); |
| 145 | + when(pe.getType()).thenReturn(RecordInner.class); |
| 146 | + |
| 147 | + Parameter<StaticType, P> iFace = new Parameter<StaticType, P>("outer", TypeInformation.of(StaticType.class), |
| 148 | + annotations, pe); |
| 149 | + assertThat(iFace.isEnclosingClassParameter()).isFalse(); |
| 150 | + } |
| 151 | + |
| 152 | + interface IFace { |
| 153 | + |
| 154 | + record RecordMember(IFace iFace) { |
| 155 | + } |
| 156 | + |
| 157 | + class ClassMember { |
| 158 | + ClassMember(IFace iface) {} |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + static class StaticType { |
| 163 | + |
| 164 | + class NonStaticInner { |
| 165 | + NonStaticInner(StaticType outer) {} |
| 166 | + } |
| 167 | + |
| 168 | + static class StaticInner { |
| 169 | + StaticInner(StaticType outer) {} |
| 170 | + } |
| 171 | + |
| 172 | + record RecordInner(StaticType outer) { |
| 173 | + } |
| 174 | + } |
90 | 175 | } |
0 commit comments