Skip to content

Commit faccaf0

Browse files
committed
Polishing.
Consistent offending method name format. Use String.format(…) instead of formatted(…). Original pull request: #4547 See #4546
1 parent 512f81f commit faccaf0

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,25 +445,32 @@ public void verify() {
445445
if (isCollectionQuery() || isScrollQuery() || isSliceQuery() || isPageQuery() || isGeoNearQuery()
446446
|| !isNumericOrVoidReturnValue()) { //
447447
throw new IllegalStateException(
448-
String.format("Update method may be void or return a numeric value (the number of updated documents)."
449-
+ "Offending method: %s", method));
448+
String.format(
449+
"Update method may be void or return a numeric value (the number of updated documents)."
450+
+ " Offending Method: %s.%s",
451+
ClassUtils.getShortName(method.getDeclaringClass()), method.getName()));
450452
}
451453

452454
if (hasAnnotatedUpdate()) { // must define either an update or an update pipeline
453455
if (!StringUtils.hasText(getUpdateSource().update()) && ObjectUtils.isEmpty(getUpdateSource().pipeline())) {
454456
throw new IllegalStateException(
455-
String.format("Update method must define either 'Update#update' or 'Update#pipeline' attribute;"
456-
+ " Offending method: %s", method));
457+
String.format(
458+
"Update method must define either 'Update#update' or 'Update#pipeline' attribute;"
459+
+ " Offending Method: %s.%s",
460+
ClassUtils.getShortName(method.getDeclaringClass()), method.getName()));
457461
}
458462
}
459463
}
464+
460465
if (hasAnnotatedAggregation()) {
461466
for (String stage : getAnnotatedAggregation()) {
462467
if (BsonUtils.isJsonArray(stage)) {
463-
throw new IllegalStateException("""
464-
Invalid aggregation pipeline. Please split Aggregation.pipeline from "[{...}, {...}]" to "{...}", "{...}".
465-
Offending Method: %s.%s
466-
""".formatted(method.getDeclaringClass().getSimpleName(), method.getName()));
468+
throw new IllegalStateException(String.format(
469+
"""
470+
Invalid aggregation pipeline. Please split the definition from @Aggregation("[{...}, {...}]") to @Aggregation({ "{...}", "{...}" }).
471+
Offending Method: %s.%s
472+
""",
473+
ClassUtils.getShortName(method.getDeclaringClass()), method.getName()));
467474
}
468475
}
469476
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryMethodUnitTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,9 @@ void annotatedCollationClashSelectsAtCollationAnnotationValue() throws Exception
312312
}
313313

314314
@Test // GH-4546
315-
void errorsOnInvalidAggregation() throws Exception {
315+
void errorsOnInvalidAggregation() {
316316

317-
assertThatExceptionOfType(IllegalStateException.class) //
317+
assertThatIllegalStateException() //
318318
.isThrownBy(() -> queryMethod(InvalidAggregationMethodRepo.class, "findByAggregation").verify()) //
319319
.withMessageContaining("Invalid aggregation") //
320320
.withMessageContaining("findByAggregation");

0 commit comments

Comments
 (0)