diff --git a/src/main/java/org/springframework/data/mapping/PersistentProperty.java b/src/main/java/org/springframework/data/mapping/PersistentProperty.java index d23a515d6..d4d7d250f 100644 --- a/src/main/java/org/springframework/data/mapping/PersistentProperty.java +++ b/src/main/java/org/springframework/data/mapping/PersistentProperty.java @@ -87,7 +87,7 @@ public interface PersistentProperty

> { Method getter = getGetter(); if (getter == null) { - throw new IllegalArgumentException("No getter available for this persistent property!"); + throw new IllegalArgumentException(String.format("No getter available for persistent property %s!", this)); } return getter; @@ -107,7 +107,7 @@ public interface PersistentProperty

> { Method setter = getSetter(); if (setter == null) { - throw new IllegalArgumentException("No setter available for this persistent property!"); + throw new IllegalArgumentException(String.format("No setter available for persistent property %s!", this)); } return setter; @@ -145,7 +145,7 @@ public interface PersistentProperty

> { Method wither = getWither(); if (wither == null) { - throw new IllegalArgumentException("No wither available for this persistent property!"); + throw new IllegalArgumentException(String.format("No wither available for persistent property %s!", this)); } return wither; @@ -159,7 +159,7 @@ public interface PersistentProperty

> { Field field = getField(); if (field == null) { - throw new IllegalArgumentException("No field backing this persistent property!"); + throw new IllegalArgumentException(String.format("No field backing persistent property %s!", this)); } return field; diff --git a/src/main/java/org/springframework/data/mapping/model/Property.java b/src/main/java/org/springframework/data/mapping/model/Property.java index 34fc4f07e..a15e0e6dc 100644 --- a/src/main/java/org/springframework/data/mapping/model/Property.java +++ b/src/main/java/org/springframework/data/mapping/model/Property.java @@ -67,7 +67,8 @@ public class Property { ); this.hashCode = Lazy.of(() -> withFieldOrDescriptor(Object::hashCode)); this.name = Lazy.of(() -> withFieldOrDescriptor(Field::getName, FeatureDescriptor::getName)); - this.toString = Lazy.of(() -> withFieldOrDescriptor(Object::toString)); + this.toString = Lazy.of(() -> withFieldOrDescriptor(Object::toString, + it -> String.format("%s.%s", type.getType().getName(), it.getDisplayName()))); this.getter = descriptor.map(PropertyDescriptor::getReadMethod)// .filter(it -> getType() != null)// diff --git a/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java b/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java index 2dd950f37..71d040abb 100755 --- a/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java @@ -249,6 +249,50 @@ public class AnnotationBasedPersistentPropertyUnitTests

property.getRequiredGetter()) // + .withMessageContaining("field") // + .withMessageContaining(Sample.class.getName()); + } + + @Test // DATACMNS-1359 + public void missingRequiredSetterThrowsException() { + + SamplePersistentProperty property = getProperty(Sample.class, "field"); + + assertThatExceptionOfType(IllegalArgumentException.class) // + .isThrownBy(() -> property.getRequiredSetter()) // + .withMessageContaining("field") // + .withMessageContaining(Sample.class.getName()); + } + + @Test // DATACMNS-1359 + public void missingRequiredWitherThrowsException() { + + SamplePersistentProperty property = getProperty(Sample.class, "field"); + + assertThatExceptionOfType(IllegalArgumentException.class) // + .isThrownBy(() -> property.getRequiredWither()) // + .withMessageContaining("field") // + .withMessageContaining(Sample.class.getName()); + } + + @Test + public void missingRequiredFieldThrowsException() { + + SamplePersistentProperty property = getProperty(NoField.class, "firstname"); + + assertThatExceptionOfType(IllegalArgumentException.class) // + .isThrownBy(() -> property.getRequiredField()) // + .withMessageContaining("firstname") // + .withMessageContaining(NoField.class.getName()); + } + @SuppressWarnings("unchecked") private Map, Annotation> getAnnotationCache(SamplePersistentProperty property) { return (Map, Annotation>) ReflectionTestUtils.getField(property, "annotationCache"); @@ -428,4 +472,9 @@ public class AnnotationBasedPersistentPropertyUnitTests