Skip to content

Commit ca5676d

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 8e8ce00 commit ca5676d

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
@@ -188,28 +188,28 @@ void returnsCorrectIteratorForMultipleElement() {
188188
assertThat(iterator.hasNext()).isFalse();
189189
}
190190

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

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

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

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

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

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

215215
@Test // DATACMNS 158

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

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

456-
@Test // GH-2341
456+
@Test // GH-2341, GH-2395
457457
void derivedQueryMethodCannotBeImplemented() {
458458

459459
DummyRepositoryFactory factory = new DummyRepositoryFactory(backingRepo) {
@@ -469,7 +469,7 @@ protected Optional<QueryLookupStrategy> getQueryLookupStrategy(QueryLookupStrate
469469

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

475475
private ConvertingRepository prepareConvertingRepository(final Object expectedValue) {

0 commit comments

Comments
 (0)