diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java index 875f5547b..99a5dc77f 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java @@ -445,25 +445,32 @@ public class MongoQueryMethod extends QueryMethod { if (isCollectionQuery() || isScrollQuery() || isSliceQuery() || isPageQuery() || isGeoNearQuery() || !isNumericOrVoidReturnValue()) { // throw new IllegalStateException( - String.format("Update method may be void or return a numeric value (the number of updated documents)." - + "Offending method: %s", method)); + String.format( + "Update method may be void or return a numeric value (the number of updated documents)." + + " Offending Method: %s.%s", + ClassUtils.getShortName(method.getDeclaringClass()), method.getName())); } if (hasAnnotatedUpdate()) { // must define either an update or an update pipeline if (!StringUtils.hasText(getUpdateSource().update()) && ObjectUtils.isEmpty(getUpdateSource().pipeline())) { throw new IllegalStateException( - String.format("Update method must define either 'Update#update' or 'Update#pipeline' attribute;" - + " Offending method: %s", method)); + String.format( + "Update method must define either 'Update#update' or 'Update#pipeline' attribute;" + + " Offending Method: %s.%s", + ClassUtils.getShortName(method.getDeclaringClass()), method.getName())); } } } + if (hasAnnotatedAggregation()) { for (String stage : getAnnotatedAggregation()) { if (BsonUtils.isJsonArray(stage)) { - throw new IllegalStateException(""" - Invalid aggregation pipeline. Please split Aggregation.pipeline from "[{...}, {...}]" to "{...}", "{...}". - Offending Method: %s.%s - """.formatted(method.getDeclaringClass().getSimpleName(), method.getName())); + throw new IllegalStateException(String.format( + """ + Invalid aggregation pipeline. Please split the definition from @Aggregation("[{...}, {...}]") to @Aggregation({ "{...}", "{...}" }). + Offending Method: %s.%s + """, + ClassUtils.getShortName(method.getDeclaringClass()), method.getName())); } } } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryMethodUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryMethodUnitTests.java index 85b3d47fd..daf4d4e69 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryMethodUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryMethodUnitTests.java @@ -312,9 +312,9 @@ public class MongoQueryMethodUnitTests { } @Test // GH-4546 - void errorsOnInvalidAggregation() throws Exception { + void errorsOnInvalidAggregation() { - assertThatExceptionOfType(IllegalStateException.class) // + assertThatIllegalStateException() // .isThrownBy(() -> queryMethod(InvalidAggregationMethodRepo.class, "findByAggregation").verify()) // .withMessageContaining("Invalid aggregation") // .withMessageContaining("findByAggregation");