|
34 | 34 | import org.mockito.ArgumentCaptor;
|
35 | 35 | import org.mockito.Mock;
|
36 | 36 | import org.mockito.junit.jupiter.MockitoExtension;
|
37 |
| - |
| 37 | +import org.mockito.junit.jupiter.MockitoSettings; |
| 38 | +import org.mockito.quality.Strictness; |
| 39 | +import org.springframework.data.domain.Page; |
| 40 | +import org.springframework.data.domain.PageRequest; |
| 41 | +import org.springframework.data.domain.Pageable; |
38 | 42 | import org.springframework.data.domain.Sort;
|
39 | 43 | import org.springframework.data.domain.Sort.Direction;
|
| 44 | +import org.springframework.data.mongodb.InvalidMongoDbApiUsageException; |
40 | 45 | import org.springframework.data.mongodb.core.MongoOperations;
|
41 | 46 | import org.springframework.data.mongodb.core.aggregation.AggregationOperationContext;
|
42 | 47 | import org.springframework.data.mongodb.core.aggregation.AggregationOptions;
|
|
68 | 73 | * @author Mark Paluch
|
69 | 74 | */
|
70 | 75 | @ExtendWith(MockitoExtension.class)
|
| 76 | +@MockitoSettings(strictness = Strictness.LENIENT) |
71 | 77 | public class StringBasedAggregationUnitTests {
|
72 | 78 |
|
73 | 79 | SpelExpressionParser PARSER = new SpelExpressionParser();
|
@@ -202,6 +208,16 @@ public void aggregateWithCollationParameter() {
|
202 | 208 | assertThat(collationOf(invocation)).isEqualTo(Collation.of("en_US"));
|
203 | 209 | }
|
204 | 210 |
|
| 211 | + @Test // DATAMONGO-2506 |
| 212 | + public void aggregateRaisesErrorOnInvalidReturnType() { |
| 213 | + |
| 214 | + StringBasedAggregation sba = createAggregationForMethod("invalidPageReturnType", Pageable.class); |
| 215 | + assertThatExceptionOfType(InvalidMongoDbApiUsageException.class) // |
| 216 | + .isThrownBy(() -> sba.execute(new Object[] { PageRequest.of(0, 1) })) // |
| 217 | + .withMessageContaining("invalidPageReturnType") // |
| 218 | + .withMessageContaining("Page"); |
| 219 | + } |
| 220 | + |
205 | 221 | private AggregationInvocation executeAggregation(String name, Object... args) {
|
206 | 222 |
|
207 | 223 | Class<?>[] argTypes = Arrays.stream(args).map(Object::getClass).toArray(Class[]::new);
|
@@ -280,6 +296,9 @@ private interface SampleRepository extends Repository<Person, Long> {
|
280 | 296 |
|
281 | 297 | @Aggregation(pipeline = RAW_GROUP_BY_LASTNAME_STRING, collation = "de_AT")
|
282 | 298 | PersonAggregate aggregateWithCollation(Collation collation);
|
| 299 | + |
| 300 | + @Aggregation(RAW_GROUP_BY_LASTNAME_STRING) |
| 301 | + Page<Person> invalidPageReturnType(Pageable page); |
283 | 302 | }
|
284 | 303 |
|
285 | 304 | static class PersonAggregate {
|
|
0 commit comments