|
24 | 24 | import java.io.Serializable;
|
25 | 25 | import java.lang.reflect.Method;
|
26 | 26 | import java.util.List;
|
| 27 | +import java.util.Map; |
| 28 | +import java.util.Map.Entry; |
| 29 | +import java.util.Optional; |
27 | 30 | import java.util.concurrent.CompletableFuture;
|
28 | 31 | import java.util.concurrent.Future;
|
29 | 32 | import java.util.stream.Stream;
|
30 | 33 |
|
31 | 34 | import org.eclipse.collections.api.list.ImmutableList;
|
| 35 | +import org.junit.jupiter.api.DynamicTest; |
32 | 36 | import org.junit.jupiter.api.Test;
|
| 37 | +import org.junit.jupiter.api.TestFactory; |
33 | 38 | import org.springframework.data.domain.Page;
|
34 | 39 | import org.springframework.data.domain.Pageable;
|
35 | 40 | import org.springframework.data.domain.Slice;
|
|
39 | 44 | import org.springframework.data.repository.core.RepositoryMetadata;
|
40 | 45 | import org.springframework.data.repository.core.support.AbstractRepositoryMetadata;
|
41 | 46 | import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
|
| 47 | +import org.springframework.data.util.Streamable; |
42 | 48 |
|
43 | 49 | /**
|
44 | 50 | * Unit tests for {@link QueryMethod}.
|
@@ -258,6 +264,28 @@ void considersEclipseCollectionCollectionQuery() throws Exception {
|
258 | 264 | assertThat(queryMethod.isCollectionQuery()).isTrue();
|
259 | 265 | }
|
260 | 266 |
|
| 267 | + @TestFactory // GH-2869 |
| 268 | + Stream<DynamicTest> doesNotConsiderQueryMethodReturningAggregateImplementingStreamableACollectionQuery() |
| 269 | + throws Exception { |
| 270 | + |
| 271 | + RepositoryMetadata metadata = AbstractRepositoryMetadata.getMetadata(StreamableAggregateRepository.class); |
| 272 | + Stream<Entry<String, Boolean>> stream = Stream.of( |
| 273 | + Map.entry("findBy", false), |
| 274 | + Map.entry("findSubTypeBy", false), |
| 275 | + Map.entry("findAllBy", true), |
| 276 | + Map.entry("findOptionalBy", false)); |
| 277 | + |
| 278 | + return DynamicTest.stream(stream, // |
| 279 | + it -> it.getKey() + " considered collection query -> " + it.getValue(), // |
| 280 | + it -> { |
| 281 | + |
| 282 | + Method method = StreamableAggregateRepository.class.getMethod(it.getKey()); |
| 283 | + QueryMethod queryMethod = new QueryMethod(method, metadata, factory); |
| 284 | + |
| 285 | + assertThat(queryMethod.isCollectionQuery()).isEqualTo(it.getValue()); |
| 286 | + }); |
| 287 | + } |
| 288 | + |
261 | 289 | interface SampleRepository extends Repository<User, Serializable> {
|
262 | 290 |
|
263 | 291 | String pagingMethodWithInvalidReturnType(Pageable pageable);
|
@@ -325,4 +353,21 @@ abstract class Container implements Iterable<Element> {}
|
325 | 353 | interface ContainerRepository extends Repository<Container, Long> {
|
326 | 354 | Container someMethod();
|
327 | 355 | }
|
| 356 | + |
| 357 | + // GH-2869 |
| 358 | + |
| 359 | + static abstract class StreamableAggregate implements Streamable<Object> {} |
| 360 | + |
| 361 | + interface StreamableAggregateRepository extends Repository<StreamableAggregate, Object> { |
| 362 | + |
| 363 | + StreamableAggregate findBy(); |
| 364 | + |
| 365 | + StreamableAggregateSubType findSubTypeBy(); |
| 366 | + |
| 367 | + Optional<StreamableAggregate> findOptionalBy(); |
| 368 | + |
| 369 | + Streamable<StreamableAggregate> findAllBy(); |
| 370 | + } |
| 371 | + |
| 372 | + static abstract class StreamableAggregateSubType extends StreamableAggregate {} |
328 | 373 | }
|
0 commit comments