From 86945f81d1120d0163f874944f87adcc96495681 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 21 Jul 2017 08:54:39 +0200 Subject: [PATCH] =?UTF-8?q?DATACMNS-1122=20-=20Improve=20message=20for=20a?= =?UTF-8?q?bsent=20required=20property=20in=20PersistentEntity.getRequired?= =?UTF-8?q?PersistentProperty(=E2=80=A6).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Exception message now contains the property name. --- .../springframework/data/mapping/PersistentEntity.java | 2 +- .../mapping/model/BasicPersistentEntityUnitTests.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/data/mapping/PersistentEntity.java b/src/main/java/org/springframework/data/mapping/PersistentEntity.java index 622996118..44444628c 100644 --- a/src/main/java/org/springframework/data/mapping/PersistentEntity.java +++ b/src/main/java/org/springframework/data/mapping/PersistentEntity.java @@ -151,7 +151,7 @@ public interface PersistentEntity> extends It return property; } - throw new IllegalStateException(String.format("Required identifier property not found for %s!", getType())); + throw new IllegalStateException(String.format("Required property %s not found for %s!", name, getType())); } /** diff --git a/src/test/java/org/springframework/data/mapping/model/BasicPersistentEntityUnitTests.java b/src/test/java/org/springframework/data/mapping/model/BasicPersistentEntityUnitTests.java index 33e23e281..69ffd9176 100755 --- a/src/test/java/org/springframework/data/mapping/model/BasicPersistentEntityUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/model/BasicPersistentEntityUnitTests.java @@ -165,6 +165,16 @@ public class BasicPersistentEntityUnitTests> { assertThat(entity.getPersistentProperty(CreatedDate.class)).isNull(); } + @Test // DATACMNS-1122 + public void reportsRequiredPropertyName() { + + SampleMappingContext context = new SampleMappingContext(); + PersistentEntity entity = context.getRequiredPersistentEntity(Entity.class); + + assertThatThrownBy(() -> entity.getRequiredPersistentProperty("foo")) + .hasMessageContaining("Required property foo not found"); + } + @Test // DATACMNS-596 public void returnsBeanWrapperForPropertyAccessor() {