DATACMNS-596 - Polishing.

PersistentEntityInformation now falls back to null values for PersistentEntity instances that don't expose an identifier property.
This commit is contained in:
Oliver Gierke
2014-11-18 16:46:18 +01:00
parent 6a849bc8ef
commit 3446c457d5
2 changed files with 29 additions and 1 deletions

View File

@@ -18,6 +18,8 @@ package org.springframework.data.repository.core.support;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.io.Serializable;
import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.mapping.PersistentEntity;
@@ -50,8 +52,26 @@ public class PersistentEntityInformationUnitTests {
assertThat(information.getId(sample), is(5L));
}
/**
* @see DATACMNS-596
*/
@Test
public void returnsNullIfNoIdPropertyPresent() {
SampleMappingContext context = new SampleMappingContext();
PersistentEntity<Object, SamplePersistentProperty> entity = context.getPersistentEntity(EntityWithoutId.class);
PersistentEntityInformation<Object, Serializable> information = new PersistentEntityInformation<Object, Serializable>(
entity);
assertThat(information.getId(new EntityWithoutId()), is(nullValue()));
}
static class Sample {
@Id Long id;
}
static class EntityWithoutId {
}
}