DATACMNS-1359 - Improved exception message for missing accessors and getters.
The exception messages used in the PersistentProperty.getRequired(Getter|Setter|Wither|Field)(…) now mention the name of the property that's offending.
This commit is contained in:
@@ -249,6 +249,50 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1359
|
||||
public void missingRequiredGetterThrowsException() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(Sample.class, "field");
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
.isThrownBy(() -> 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<Class<? extends Annotation>, Annotation> getAnnotationCache(SamplePersistentProperty property) {
|
||||
return (Map<Class<? extends Annotation>, Annotation>) ReflectionTestUtils.getField(property, "annotationCache");
|
||||
@@ -428,4 +472,9 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
|
||||
@Reference Sample sample;
|
||||
Sample withoutAnnotation;
|
||||
}
|
||||
|
||||
interface NoField {
|
||||
|
||||
String getFirstname();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user