DATACMNS-934 - BasicPersistentEntity.addAssociation(…) drops null values now.

Previously a null value was added to the list of associations if it was handed to BasicaPersistentEntity.addAssociation(…). We now drop those null values and log a warning as it usually indicates a MappingContext implementation identifying a property as association but subsequently failing to look it up.
This commit is contained in:
Oliver Gierke
2016-12-05 16:39:05 +01:00
parent 9354800225
commit d3f235872c
2 changed files with 32 additions and 1 deletions

View File

@@ -27,6 +27,7 @@ import java.util.Iterator;
import java.util.List;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -39,11 +40,13 @@ import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.TypeAlias;
import org.springframework.data.mapping.Association;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentEntitySpec;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.Person;
import org.springframework.data.mapping.SimpleAssociationHandler;
import org.springframework.data.mapping.context.SampleMappingContext;
import org.springframework.data.mapping.context.SamplePersistentProperty;
import org.springframework.data.util.ClassTypeInformation;
@@ -275,6 +278,24 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
entity.getPropertyAccessor(new Object());
}
/**
* @see DATACMNS-934
*/
@Test
public void doesNotThrowAnExceptionForNullAssociation() {
BasicPersistentEntity<Entity, T> entity = createEntity(Entity.class);
entity.addAssociation(null);
entity.doWithAssociations(new SimpleAssociationHandler() {
@Override
public void doWithAssociation(Association<? extends PersistentProperty<?>> association) {
Assert.fail("Expected the method to never be called!");
}
});
}
private <S> BasicPersistentEntity<S, T> createEntity(Class<S> type) {
return createEntity(type, null);
}