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:
John Blum
2022-12-12 12:31:08 -08:00
parent f8d6c9f026
commit bdfb1f8a7f
2 changed files with 46 additions and 4 deletions

View File

@@ -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;
}
}