Skip to content

Commit 6413b20

Browse files
committed
Polishing.
Consistent offending method name format. Use String.format(…) instead of formatted(…). Original pull request: spring-projects#4547 See spring-projects#4546
1 parent 77699dd commit 6413b20

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

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

+15-8
Original file line numberDiff line numberDiff line change
@@ -493,25 +493,32 @@ public void verify() {
493493
if (isCollectionQuery() || isScrollQuery() || isSliceQuery() || isPageQuery() || isGeoNearQuery()
494494
|| !isNumericOrVoidReturnValue()) { //
495495
throw new IllegalStateException(
496-
String.format("Update method may be void or return a numeric value (the number of updated documents)."
497-
+ "Offending method: %s", method));
496+
String.format(
497+
"Update method may be void or return a numeric value (the number of updated documents)."
498+
+ " Offending Method: %s.%s",
499+
ClassUtils.getShortName(method.getDeclaringClass()), method.getName()));
498500
}
499501

500502
if (hasAnnotatedUpdate()) { // must define either an update or an update pipeline
501503
if (!StringUtils.hasText(getUpdateSource().update()) && ObjectUtils.isEmpty(getUpdateSource().pipeline())) {
502504
throw new IllegalStateException(
503-
String.format("Update method must define either 'Update#update' or 'Update#pipeline' attribute;"
504-
+ " Offending method: %s", method));
505+
String.format(
506+
"Update method must define either 'Update#update' or 'Update#pipeline' attribute;"
507+
+ " Offending Method: %s.%s",
508+
ClassUtils.getShortName(method.getDeclaringClass()), method.getName()));
505509
}
506510
}
507511
}
512+
508513
if (hasAnnotatedAggregation()) {
509514
for (String stage : getAnnotatedAggregation()) {
510515
if (BsonUtils.isJsonArray(stage)) {
511-
throw new IllegalStateException("""
512-
Invalid aggregation pipeline. Please split Aggregation.pipeline from "[{...}, {...}]" to "{...}", "{...}".
513-
Offending Method: %s.%s
514-
""".formatted(method.getDeclaringClass().getSimpleName(), method.getName()));
516+
throw new IllegalStateException(String.format(
517+
"""
518+
Invalid aggregation pipeline. Please split the definition from @Aggregation("[{...}, {...}]") to @Aggregation({ "{...}", "{...}" }).
519+
Offending Method: %s.%s
520+
""",
521+
ClassUtils.getShortName(method.getDeclaringClass()), method.getName()));
515522
}
516523
}
517524
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ void detectsReadPreferenceForAggregation() throws Exception {
359359
}
360360

361361
@Test // GH-4546
362-
void errorsOnInvalidAggregation() throws Exception {
362+
void errorsOnInvalidAggregation() {
363363

364-
assertThatExceptionOfType(IllegalStateException.class) //
364+
assertThatIllegalStateException() //
365365
.isThrownBy(() -> queryMethod(InvalidAggregationMethodRepo.class, "findByAggregation").verify()) //
366366
.withMessageContaining("Invalid aggregation") //
367367
.withMessageContaining("findByAggregation");

0 commit comments

Comments
 (0)