mirror of
https://github.com/spring-projects/spring-data-commons.git
synced 2026-05-03 03:34:35 +01:00
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:
@@ -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();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+10
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user