|
22 | 22 | import java.util.Collections;
|
23 | 23 | import java.util.Locale;
|
24 | 24 | import java.util.Map;
|
| 25 | +import java.util.Optional; |
25 | 26 |
|
26 | 27 | import org.junit.jupiter.api.Test;
|
27 | 28 | import org.junit.jupiter.api.extension.ExtendWith;
|
|
35 | 36 | import org.springframework.data.mapping.model.FieldNamingStrategy;
|
36 | 37 |
|
37 | 38 | import com.mongodb.DBRef;
|
| 39 | +import org.springframework.data.util.TypeInformation; |
38 | 40 |
|
39 | 41 | /**
|
40 | 42 | * Unit tests for {@link MongoMappingContext}.
|
@@ -173,6 +175,26 @@ void shouldNotCreateEntityForEnum() {
|
173 | 175 | assertThat(context.getPersistentEntity(ChronoUnit.class)).isNull();
|
174 | 176 | }
|
175 | 177 |
|
| 178 | + @Test // GH-3656 |
| 179 | + void shouldNotCreateEntityForOptionalGetter() { |
| 180 | + |
| 181 | + MongoMappingContext context = new MongoMappingContext(); |
| 182 | + MongoPersistentEntity<?> entity = context.getRequiredPersistentEntity(InterfaceWithMethodReturningOptional.class); |
| 183 | + |
| 184 | + assertThat(context.getPersistentEntities()).map(it -> it.getType()).doesNotContain((Class) |
| 185 | + Optional.class).contains((Class)Person.class); |
| 186 | + } |
| 187 | + |
| 188 | + @Test // GH-3656 |
| 189 | + void shouldNotCreateEntityForOptionalField() { |
| 190 | + |
| 191 | + MongoMappingContext context = new MongoMappingContext(); |
| 192 | + MongoPersistentEntity<?> entity = context.getRequiredPersistentEntity(ClassWithOptionalField.class); |
| 193 | + |
| 194 | + assertThat(context.getPersistentEntities()).map(it -> it.getType()).doesNotContain((Class) |
| 195 | + Optional.class).contains((Class)Person.class); |
| 196 | + } |
| 197 | + |
176 | 198 | public class SampleClass {
|
177 | 199 |
|
178 | 200 | Map<String, SampleClass> children;
|
@@ -244,4 +266,13 @@ class ClassWithChronoUnit {
|
244 | 266 |
|
245 | 267 | ChronoUnit unit;
|
246 | 268 | }
|
| 269 | + |
| 270 | + interface InterfaceWithMethodReturningOptional { |
| 271 | + |
| 272 | + Optional<Person> getPerson(); |
| 273 | + } |
| 274 | + |
| 275 | + class ClassWithOptionalField { |
| 276 | + Optional<Person> person; |
| 277 | + } |
247 | 278 | }
|
0 commit comments