DATACMNS-1208 - AbstractMappingContext.hasPersistentEntityFor(…) now properly considers cached absence.

AbstractMappingContext.hasPersistentEntityFor(…) now also properly consideres the empty Optional as non-presence as that is held to allow to distinguish between a type completely unkown to the context, or already known but not considered a persistent entity.

Related pull request: #258.
This commit is contained in:
Oliver Gierke
2017-11-14 09:56:37 +01:00
parent 5d0cd54a94
commit d8cea8ba1c
2 changed files with 13 additions and 1 deletions
@@ -181,7 +181,9 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
Assert.notNull(type, "Type must not be null!");
return persistentEntities.containsKey(ClassTypeInformation.from(type));
Optional<E> entity = persistentEntities.get(ClassTypeInformation.from(type));
return entity == null ? false : entity.isPresent();
}
/*
@@ -244,6 +244,16 @@ public class AbstractMappingContextUnitTests {
.isSameAs(context.getPersistentPropertyPath("persons.name", Sample.class));
}
@Test // DATACMNS-1208
public void ensureHasPersistentEntityReportsFalseForTypesThatShouldntBeCreated() {
SampleMappingContext context = new SampleMappingContext();
assertThat(context.hasPersistentEntityFor(String.class)).isFalse();
assertThat(context.getPersistentEntity(String.class)).isNull();
assertThat(context.hasPersistentEntityFor(String.class)).isFalse();
}
private static void assertHasEntityFor(Class<?> type, SampleMappingContext context, boolean expected) {
boolean found = false;