diff --git a/spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/BulkOperationsExtensions.kt b/spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/BulkOperationsExtensions.kt index 2ee018b59..4c8545ee8 100644 --- a/spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/BulkOperationsExtensions.kt +++ b/spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/BulkOperationsExtensions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2017-2025 the original author or authors. + * Copyright 2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,30 +21,32 @@ import org.springframework.data.mongodb.core.query.UpdateDefinition import org.springframework.data.util.Pair.of /** - * Extension for [BulkOperations.updateMulti] that converts a [kotlin.Pair] to [org.springframework.data.util.Pair]. + * Extension for [BulkOperations.updateMulti] that converts a list of [kotlin.Pair] to list of [org.springframework.data.util.Pair]. * * @author 2tsumo-hitori + * @since 4.5 */ fun BulkOperations.updateMulti(kotlinPairs: List>): BulkOperations = - updateMulti(kotlinPairs.toSpringPairs()) + updateMulti(kotlinPairs.toSpringPairs()) /** - * Extension for [BulkOperations.upsert] that converts a [kotlin.Pair] to [org.springframework.data.util.Pair]. + * Extension for [BulkOperations.upsert] that converts a list of [kotlin.Pair] to list of [org.springframework.data.util.Pair]. * * @author 2tsumo-hitori + * @since 4.5 */ -fun BulkOperations.upsert(kotlinPairs: List>) : BulkOperations = - upsert(kotlinPairs.toSpringPairs()) +fun BulkOperations.upsert(kotlinPairs: List>): BulkOperations = + upsert(kotlinPairs.toSpringPairs()) /** * Extension for [BulkOperations.updateOne] that converts a [kotlin.Pair] to [org.springframework.data.util.Pair]. * * @author 2tsumo-hitori + * @since 4.5 */ fun BulkOperations.updateOne(kotlinPairs: List>): BulkOperations = - updateOne(kotlinPairs.toSpringPairs()) + updateOne(kotlinPairs.toSpringPairs()) private fun List>.toSpringPairs(): List> { - - return map { (first, second) -> of(first, second) } -} \ No newline at end of file + return map { (first, second) -> of(first, second) } +} diff --git a/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/BulkOperationExtensionsTests.kt b/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/BulkOperationExtensionsTests.kt index 3e48685e7..e5c08c74d 100644 --- a/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/BulkOperationExtensionsTests.kt +++ b/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/BulkOperationExtensionsTests.kt @@ -1,5 +1,5 @@ /* - * Copyright 2017-2025 the original author or authors. + * Copyright 2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ package org.springframework.data.mongodb.core import io.mockk.mockk import io.mockk.verify -import org.junit.Test +import org.junit.jupiter.api.Test import org.springframework.data.mongodb.core.query.Criteria import org.springframework.data.mongodb.core.query.Query import org.springframework.data.mongodb.core.query.Update @@ -25,50 +25,55 @@ import org.springframework.data.mongodb.core.query.UpdateDefinition import org.springframework.data.util.Pair.of /** + * Unit tests for BulkOperationExtensions. * @author 2tsumo-hitori */ class BulkOperationExtensionsTests { - private val bulkOperation = mockk(relaxed = true) + private val bulkOperation = mockk(relaxed = true) - @Test // GH-4911 - fun `BulkOperation#updateMulti#updates() using kotlin#Pair should call its Java counterpart`() { - val list : MutableList> = mutableListOf() - list.add(where("value", "v2") to set("value", "v3")) + @Test // GH-4911 + fun `BulkOperation#updateMulti using kotlin#Pair should call its Java counterpart`() { - bulkOperation.updateMulti(list) + val list: MutableList> = mutableListOf() + list.add(where("value", "v2") to set("value", "v3")) - val expected = list.map { (query, update) -> of(query, update) } - verify { bulkOperation.updateMulti(expected) } - } + bulkOperation.updateMulti(list) - @Test // GH-4911 - fun `BulkOperation#upsert#updates() using kotlin#Pair should call its Java counterpart`() { - val list : MutableList> = mutableListOf() - list.add(where("value", "v2") to set("value", "v3")) + val expected = list.map { (query, update) -> of(query, update) } + verify { bulkOperation.updateMulti(expected) } + } - bulkOperation.upsert(list) + @Test // GH-4911 + fun `BulkOperation#upsert using kotlin#Pair should call its Java counterpart`() { - val expected = list.map { (query, update) -> of(query, update) } - verify { bulkOperation.upsert(expected) } - } + val list: MutableList> = mutableListOf() + list.add(where("value", "v2") to set("value", "v3")) - @Test // GH-4911 - fun `BulkOperation#updateOne#updates() using kotlin#Pair should call its Java counterpart`() { - val list : MutableList> = mutableListOf() - list.add(where("value", "v2") to set("value", "v3")) + bulkOperation.upsert(list) - bulkOperation.updateOne(list) + val expected = list.map { (query, update) -> of(query, update) } + verify { bulkOperation.upsert(expected) } + } - val expected = list.map { (query, update) -> of(query, update) } - verify { bulkOperation.updateOne(expected) } - } + @Test // GH-4911 + fun `BulkOperation#updateOne using kotlin#Pair should call its Java counterpart`() { - private fun where(field: String, value: String): Query { - return Query().addCriteria(Criteria.where(field).`is`(value)) - } + val list: MutableList> = mutableListOf() + list.add(where("value", "v2") to set("value", "v3")) - private fun set(field: String, value: String): Update { - return Update().set(field, value) - } -} \ No newline at end of file + bulkOperation.updateOne(list) + + val expected = list.map { (query, update) -> of(query, update) } + verify { bulkOperation.updateOne(expected) } + } + + private fun where(field: String, value: String): Query { + return Query().addCriteria(Criteria.where(field).`is`(value)) + } + + private fun set(field: String, value: String): Update { + return Update().set(field, value) + } + +}