Skip to content

Commit ce3066d

Browse files
committed
Polishing.
Align type variable naming with imperative extensions(I, O). Add extension without accepting KClass. Update since tags and tests. See #3508. Original pull request: #893.
1 parent c11dcd1 commit ce3066d

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/ReactiveMongoOperationsExtensions.kt

+21-12
Original file line numberDiff line numberDiff line change
@@ -217,37 +217,46 @@ inline fun <reified T : Any, reified E : Any> ReactiveMongoOperations.findDistin
217217
* Extension for [ReactiveMongoOperations.aggregate] leveraging reified type parameters.
218218
*
219219
* @author Wonwoo Lee
220-
* @since 3.1
220+
* @since 3.1.4
221221
*/
222-
inline fun <reified T : Any> ReactiveMongoOperations.aggregate(aggregation: TypedAggregation<*>, collectionName: String): Flux<T> =
223-
this.aggregate(aggregation, collectionName, T::class.java)
222+
inline fun <reified O : Any> ReactiveMongoOperations.aggregate(
223+
aggregation: TypedAggregation<*>,
224+
collectionName: String
225+
): Flux<O> =
226+
this.aggregate(aggregation, collectionName, O::class.java)
224227

225228
/**
226229
* Extension for [ReactiveMongoOperations.aggregate] leveraging reified type parameters.
227230
*
228231
* @author Wonwoo Lee
229-
* @since 3.1
232+
* @since 3.1.4
230233
*/
231-
inline fun <reified T : Any> ReactiveMongoOperations.aggregate(aggregation: TypedAggregation<*>): Flux<T> =
232-
this.aggregate(aggregation, T::class.java)
234+
inline fun <reified O : Any> ReactiveMongoOperations.aggregate(aggregation: TypedAggregation<*>): Flux<O> =
235+
this.aggregate(aggregation, O::class.java)
233236

234237
/**
235238
* Extension for [ReactiveMongoOperations.aggregate] leveraging reified type parameters.
236239
*
237240
* @author Wonwoo Lee
238-
* @since 3.1
241+
* @author Mark Paluch
242+
* @since 3.1.4
239243
*/
240-
inline fun <reified T : Any> ReactiveMongoOperations.aggregate(aggregation: Aggregation, entityClass: KClass<*>): Flux<T> =
241-
this.aggregate(aggregation, entityClass.java, T::class.java)
244+
inline fun <reified I : Any, reified O : Any> ReactiveMongoOperations.aggregate(
245+
aggregation: Aggregation
246+
): Flux<O> =
247+
this.aggregate(aggregation, I::class.java, O::class.java)
242248

243249
/**
244250
* Extension for [ReactiveMongoOperations.aggregate] leveraging reified type parameters.
245251
*
246252
* @author Wonwoo Lee
247-
* @since 3.1
253+
* @since 3.1.4
248254
*/
249-
inline fun <reified T : Any> ReactiveMongoOperations.aggregate(aggregation: Aggregation, collectionName: String): Flux<T> =
250-
this.aggregate(aggregation, collectionName, T::class.java)
255+
inline fun <reified O : Any> ReactiveMongoOperations.aggregate(
256+
aggregation: Aggregation,
257+
collectionName: String
258+
): Flux<O> =
259+
this.aggregate(aggregation, collectionName, O::class.java)
251260

252261
/**
253262
* Extension for [ReactiveMongoOperations.geoNear] leveraging reified type parameters.

spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/ReactiveMongoOperationsExtensionsTests.kt

+21-7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import reactor.core.publisher.Mono
3030
* @author Sebastien Deleuze
3131
* @author Christoph Strobl
3232
* @author Mark Paluch
33+
* @author Wonwoo Lee
3334
*/
3435
class ReactiveMongoOperationsExtensionsTests {
3536

@@ -607,10 +608,17 @@ class ReactiveMongoOperationsExtensionsTests {
607608
val query = mockk<Query>()
608609

609610
operations.findDistinct<String>(query, "field", First::class)
610-
verify { operations.findDistinct(query, "field", First::class.java, String::class.java) }
611+
verify {
612+
operations.findDistinct(
613+
query,
614+
"field",
615+
First::class.java,
616+
String::class.java
617+
)
618+
}
611619
}
612620

613-
@Test
621+
@Test // #893
614622
fun `aggregate(TypedAggregation, String, KClass) should call java counterpart`() {
615623

616624
val aggregation = mockk<TypedAggregation<String>>()
@@ -619,7 +627,7 @@ class ReactiveMongoOperationsExtensionsTests {
619627
verify { operations.aggregate(aggregation, "foo", First::class.java) }
620628
}
621629

622-
@Test
630+
@Test // #893
623631
fun `aggregate(TypedAggregation, KClass) should call java counterpart`() {
624632

625633
val aggregation = mockk<TypedAggregation<String>>()
@@ -628,16 +636,22 @@ class ReactiveMongoOperationsExtensionsTests {
628636
verify { operations.aggregate(aggregation, First::class.java) }
629637
}
630638

631-
@Test
639+
@Test // #893
632640
fun `aggregate(Aggregation, KClass) should call java counterpart`() {
633641

634642
val aggregation = mockk<Aggregation>()
635643

636-
operations.aggregate<First>(aggregation, String::class)
637-
verify { operations.aggregate(aggregation, String::class.java, First::class.java) }
644+
operations.aggregate<String, First>(aggregation)
645+
verify {
646+
operations.aggregate(
647+
aggregation,
648+
String::class.java,
649+
First::class.java
650+
)
651+
}
638652
}
639653

640-
@Test
654+
@Test // #893
641655
fun `aggregate(Aggregation, String) should call java counterpart`() {
642656

643657
val aggregation = mockk<Aggregation>()

0 commit comments

Comments
 (0)