Fix formatting in PropertyReferenceException message.
A message like, "No property 'creat' found for type 'User' Did you mean ''created''" is now properly formatted as: "No property 'creat' found for type 'User'; Did you mean 'created'". Closes #2750.
This commit is contained in:
@@ -28,6 +28,7 @@ import org.springframework.data.util.TypeInformation;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
* @author John Blum
|
||||
*/
|
||||
public class PropertyReferenceExceptionUnitTests {
|
||||
|
||||
@@ -65,6 +66,33 @@ public class PropertyReferenceExceptionUnitTests {
|
||||
assertThat(matches).containsExactly("name");
|
||||
}
|
||||
|
||||
@Test // GH-2750
|
||||
public void formatsMessageWithTypeInfoAndHintsCorrectly() {
|
||||
|
||||
var exception = new PropertyReferenceException("nme", TYPE_INFO, NO_PATHS);
|
||||
|
||||
String expectedMessage = String.format("%s; %s", PropertyReferenceException.ERROR_TEMPLATE,
|
||||
PropertyReferenceException.HINTS_TEMPLATE);
|
||||
|
||||
assertThat(exception)
|
||||
.hasMessage(expectedMessage,"nme", TYPE_INFO.getType().getSimpleName(), "'name'");
|
||||
}
|
||||
|
||||
@Test // GH-2750
|
||||
public void formatsMessageWithTypeInfoHintsAndPathCorrectly() {
|
||||
|
||||
var ctype = TypeInformation.of(C.class);
|
||||
|
||||
var exception = new PropertyReferenceException("nme", TYPE_INFO,
|
||||
Collections.singletonList(PropertyPath.from("b.a", ctype)));
|
||||
|
||||
String expectedMessage = String.format("%s; %s; %s", PropertyReferenceException.ERROR_TEMPLATE,
|
||||
PropertyReferenceException.HINTS_TEMPLATE, "Traversed path: C.b.a");
|
||||
|
||||
assertThat(exception)
|
||||
.hasMessage(expectedMessage,"nme", TYPE_INFO.getType().getSimpleName(), "'name'");
|
||||
}
|
||||
|
||||
static class Sample {
|
||||
|
||||
String name;
|
||||
@@ -77,4 +105,16 @@ public class PropertyReferenceExceptionUnitTests {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
static class A {
|
||||
|
||||
}
|
||||
|
||||
static class B {
|
||||
A a;
|
||||
}
|
||||
|
||||
static class C {
|
||||
B b;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user