1
+ /*
2
+ * Copyright 2017-2025 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package org.springframework.data.mongodb.core
17
+
18
+ import io.mockk.mockk
19
+ import io.mockk.verify
20
+ import org.junit.Test
21
+ import org.springframework.data.mongodb.core.query.Criteria
22
+ import org.springframework.data.mongodb.core.query.Query
23
+ import org.springframework.data.mongodb.core.query.Update
24
+ import org.springframework.data.mongodb.core.query.UpdateDefinition
25
+ import org.springframework.data.util.Pair.of
26
+
27
+ /* *
28
+ * @author 2tsumo-hitori
29
+ */
30
+ class BulkOperationExtensionsTests {
31
+
32
+ private val bulkOperation = mockk<BulkOperations >(relaxed = true )
33
+
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" ))
38
+
39
+ bulkOperation.updateMulti(list)
40
+
41
+ val expected = list.map { (query, update) -> of(query, update) }
42
+ verify { bulkOperation.updateMulti(expected) }
43
+ }
44
+
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" ))
49
+
50
+ bulkOperation.upsert(list)
51
+
52
+ val expected = list.map { (query, update) -> of(query, update) }
53
+ verify { bulkOperation.upsert(expected) }
54
+ }
55
+
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" ))
60
+
61
+ bulkOperation.updateOne(list)
62
+
63
+ val expected = list.map { (query, update) -> of(query, update) }
64
+ verify { bulkOperation.updateOne(expected) }
65
+ }
66
+
67
+ private fun where (field : String , value : String ): Query {
68
+ return Query ().addCriteria(Criteria .where(field).`is `(value))
69
+ }
70
+
71
+ private fun set (field : String , value : String ): Update {
72
+ return Update ().set(field, value)
73
+ }
74
+ }
0 commit comments