Skip to content

Commit ce9fcf9

Browse files
committed
Refine PropertyReferenceException message.
Use single-quotes to indicate which elements belong to the underlying type and which are part of the textual message. Closes #2395
1 parent da64183 commit ce9fcf9

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/main/java/org/springframework/data/mapping/PropertyReferenceException.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,8 +37,8 @@
3737
public class PropertyReferenceException extends RuntimeException {
3838

3939
private static final long serialVersionUID = -5254424051438976570L;
40-
private static final String ERROR_TEMPLATE = "No property %s found for type %s!";
41-
private static final String HINTS_TEMPLATE = " Did you mean %s?";
40+
private static final String ERROR_TEMPLATE = "No property '%s' found for type '%s'!";
41+
private static final String HINTS_TEMPLATE = " Did you mean '%s'?";
4242

4343
private final String propertyName;
4444
private final TypeInformation<?> type;

src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -187,28 +187,28 @@ void returnsCorrectIteratorForMultipleElement() {
187187
assertThat(iterator.hasNext()).isFalse();
188188
}
189189

190-
@Test // DATACMNS-139
190+
@Test // DATACMNS-139, GH-2395
191191
void rejectsInvalidPropertyWithLeadingUnderscore() {
192192

193193
assertThatExceptionOfType(PropertyReferenceException.class)//
194194
.isThrownBy(() -> PropertyPath.from("_id", Foo.class))//
195-
.withMessageContaining("property _id");
195+
.withMessageContaining("property '_id'");
196196
}
197197

198-
@Test // DATACMNS-139
198+
@Test // DATACMNS-139, GH-2395
199199
void rejectsNestedInvalidPropertyWithLeadingUnderscore() {
200200

201201
assertThatExceptionOfType(PropertyReferenceException.class)//
202202
.isThrownBy(() -> PropertyPath.from("_foo_id", Sample2.class))//
203-
.withMessageContaining("property id");
203+
.withMessageContaining("property 'id'");
204204
}
205205

206-
@Test // DATACMNS-139
206+
@Test // DATACMNS-139, GH-2395
207207
void rejectsNestedInvalidPropertyExplictlySplitWithLeadingUnderscore() {
208208

209209
assertThatExceptionOfType(PropertyReferenceException.class)//
210210
.isThrownBy(() -> PropertyPath.from("_foo__id", Sample2.class))//
211-
.withMessageContaining("property _id");
211+
.withMessageContaining("property '_id'");
212212
}
213213

214214
@Test // DATACMNS 158

src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ void dummyRepositoryNotSupportingReactiveQbeShouldRaiseException() {
452452
.hasMessageContaining("does not support Reactive Query by Example");
453453
}
454454

455-
@Test // GH-2341
455+
@Test // GH-2341, GH-2395
456456
void derivedQueryMethodCannotBeImplemented() {
457457

458458
var factory = new DummyRepositoryFactory(backingRepo) {
@@ -468,7 +468,7 @@ protected Optional<QueryLookupStrategy> getQueryLookupStrategy(QueryLookupStrate
468468

469469
assertThatThrownBy(() -> factory.getRepository(WithQueryMethodUsingInvalidProperty.class))
470470
.isInstanceOf(QueryCreationException.class).hasMessageContaining("findAllByName")
471-
.hasMessageContaining("No property name found for type Object");
471+
.hasMessageContaining("No property 'name' found for type 'Object'");
472472
}
473473

474474
private ConvertingRepository prepareConvertingRepository(final Object expectedValue) {

0 commit comments

Comments
 (0)