Browse Source

Polishing.

Consistent offending method name format.

Use String.format(…) instead of formatted(…).

Original pull request: #4547
See #4546
pull/4550/head
Mark Paluch 2 years ago
parent
commit
6413b20da2
No known key found for this signature in database
GPG Key ID: 4406B84C1661DCD1
  1. 23
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java
  2. 4
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/MongoQueryMethodUnitTests.java

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

@ -493,25 +493,32 @@ public class MongoQueryMethod extends QueryMethod { @@ -493,25 +493,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()));
}
}
}

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

@ -359,9 +359,9 @@ public class MongoQueryMethodUnitTests { @@ -359,9 +359,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");

Loading…
Cancel
Save