Skip to content

Commit 833601d

Browse files
committed
Polishing.
Tweak documentation, add since tags. Reformat code, change space indents to tab indents. See #4911 Original pull request: #4912
1 parent 673d33a commit 833601d

File tree

2 files changed

+51
-44
lines changed

2 files changed

+51
-44
lines changed

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

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2025 the original author or authors.
2+
* Copyright 2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,30 +21,32 @@ import org.springframework.data.mongodb.core.query.UpdateDefinition
2121
import org.springframework.data.util.Pair.of
2222

2323
/**
24-
* Extension for [BulkOperations.updateMulti] that converts a [kotlin.Pair] to [org.springframework.data.util.Pair].
24+
* Extension for [BulkOperations.updateMulti] that converts a list of [kotlin.Pair] to list of [org.springframework.data.util.Pair].
2525
*
2626
* @author 2tsumo-hitori
27+
* @since 4.5
2728
*/
2829
fun BulkOperations.updateMulti(kotlinPairs: List<Pair<Query, UpdateDefinition>>): BulkOperations =
29-
updateMulti(kotlinPairs.toSpringPairs())
30+
updateMulti(kotlinPairs.toSpringPairs())
3031

3132
/**
32-
* Extension for [BulkOperations.upsert] that converts a [kotlin.Pair] to [org.springframework.data.util.Pair].
33+
* Extension for [BulkOperations.upsert] that converts a list of [kotlin.Pair] to list of [org.springframework.data.util.Pair].
3334
*
3435
* @author 2tsumo-hitori
36+
* @since 4.5
3537
*/
36-
fun BulkOperations.upsert(kotlinPairs: List<Pair<Query, Update>>) : BulkOperations =
37-
upsert(kotlinPairs.toSpringPairs())
38+
fun BulkOperations.upsert(kotlinPairs: List<Pair<Query, Update>>): BulkOperations =
39+
upsert(kotlinPairs.toSpringPairs())
3840

3941
/**
4042
* Extension for [BulkOperations.updateOne] that converts a [kotlin.Pair] to [org.springframework.data.util.Pair].
4143
*
4244
* @author 2tsumo-hitori
45+
* @since 4.5
4346
*/
4447
fun BulkOperations.updateOne(kotlinPairs: List<Pair<Query, UpdateDefinition>>): BulkOperations =
45-
updateOne(kotlinPairs.toSpringPairs())
48+
updateOne(kotlinPairs.toSpringPairs())
4649

4750
private fun <A : Query, B : UpdateDefinition> List<Pair<A, B>>.toSpringPairs(): List<org.springframework.data.util.Pair<A, B>> {
48-
49-
return map { (first, second) -> of(first, second) }
50-
}
51+
return map { (first, second) -> of(first, second) }
52+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2025 the original author or authors.
2+
* Copyright 2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,58 +17,63 @@ package org.springframework.data.mongodb.core
1717

1818
import io.mockk.mockk
1919
import io.mockk.verify
20-
import org.junit.Test
20+
import org.junit.jupiter.api.Test
2121
import org.springframework.data.mongodb.core.query.Criteria
2222
import org.springframework.data.mongodb.core.query.Query
2323
import org.springframework.data.mongodb.core.query.Update
2424
import org.springframework.data.mongodb.core.query.UpdateDefinition
2525
import org.springframework.data.util.Pair.of
2626

2727
/**
28+
* Unit tests for BulkOperationExtensions.
2829
* @author 2tsumo-hitori
2930
*/
3031
class BulkOperationExtensionsTests {
3132

32-
private val bulkOperation = mockk<BulkOperations>(relaxed = true)
33+
private val bulkOperation = mockk<BulkOperations>(relaxed = true)
3334

34-
@Test // GH-4911
35-
fun `BulkOperation#updateMulti#updates() using kotlin#Pair should call its Java counterpart`() {
36-
val list : MutableList<Pair<Query, UpdateDefinition>> = mutableListOf()
37-
list.add(where("value", "v2") to set("value", "v3"))
35+
@Test // GH-4911
36+
fun `BulkOperation#updateMulti using kotlin#Pair should call its Java counterpart`() {
3837

39-
bulkOperation.updateMulti(list)
38+
val list: MutableList<Pair<Query, UpdateDefinition>> = mutableListOf()
39+
list.add(where("value", "v2") to set("value", "v3"))
4040

41-
val expected = list.map { (query, update) -> of(query, update) }
42-
verify { bulkOperation.updateMulti(expected) }
43-
}
41+
bulkOperation.updateMulti(list)
4442

45-
@Test // GH-4911
46-
fun `BulkOperation#upsert#updates() using kotlin#Pair should call its Java counterpart`() {
47-
val list : MutableList<Pair<Query, Update>> = mutableListOf()
48-
list.add(where("value", "v2") to set("value", "v3"))
43+
val expected = list.map { (query, update) -> of(query, update) }
44+
verify { bulkOperation.updateMulti(expected) }
45+
}
4946

50-
bulkOperation.upsert(list)
47+
@Test // GH-4911
48+
fun `BulkOperation#upsert using kotlin#Pair should call its Java counterpart`() {
5149

52-
val expected = list.map { (query, update) -> of(query, update) }
53-
verify { bulkOperation.upsert(expected) }
54-
}
50+
val list: MutableList<Pair<Query, Update>> = mutableListOf()
51+
list.add(where("value", "v2") to set("value", "v3"))
5552

56-
@Test // GH-4911
57-
fun `BulkOperation#updateOne#updates() using kotlin#Pair should call its Java counterpart`() {
58-
val list : MutableList<Pair<Query, UpdateDefinition>> = mutableListOf()
59-
list.add(where("value", "v2") to set("value", "v3"))
53+
bulkOperation.upsert(list)
6054

61-
bulkOperation.updateOne(list)
55+
val expected = list.map { (query, update) -> of(query, update) }
56+
verify { bulkOperation.upsert(expected) }
57+
}
6258

63-
val expected = list.map { (query, update) -> of(query, update) }
64-
verify { bulkOperation.updateOne(expected) }
65-
}
59+
@Test // GH-4911
60+
fun `BulkOperation#updateOne using kotlin#Pair should call its Java counterpart`() {
6661

67-
private fun where(field: String, value: String): Query {
68-
return Query().addCriteria(Criteria.where(field).`is`(value))
69-
}
62+
val list: MutableList<Pair<Query, UpdateDefinition>> = mutableListOf()
63+
list.add(where("value", "v2") to set("value", "v3"))
7064

71-
private fun set(field: String, value: String): Update {
72-
return Update().set(field, value)
73-
}
74-
}
65+
bulkOperation.updateOne(list)
66+
67+
val expected = list.map { (query, update) -> of(query, update) }
68+
verify { bulkOperation.updateOne(expected) }
69+
}
70+
71+
private fun where(field: String, value: String): Query {
72+
return Query().addCriteria(Criteria.where(field).`is`(value))
73+
}
74+
75+
private fun set(field: String, value: String): Update {
76+
return Update().set(field, value)
77+
}
78+
79+
}

0 commit comments

Comments
 (0)