Skip to content

Commit

Permalink
resolves #34 Documentation contradicts return type
Browse files Browse the repository at this point in the history
  • Loading branch information
zigzago committed Aug 28, 2017
1 parent 2bd3458 commit 764b597
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kmongo/src/main/kotlin/org/litote/kmongo/extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ fun <T> MongoCollection<T>.findOneAndDelete(filter: String, options: FindOneAndD
* document as it was before the update or as it is after the update. If no documents matched the query filter, then null will be
* returned
*/
fun <T> MongoCollection<T>.findOneAndReplace(filter: String, replacement: T, options: FindOneAndReplaceOptions = FindOneAndReplaceOptions()): T
fun <T> MongoCollection<T>.findOneAndReplace(filter: String, replacement: T, options: FindOneAndReplaceOptions = FindOneAndReplaceOptions()): T?
= findOneAndReplace(toBson(filter), replacement, options)

/**
Expand All @@ -484,7 +484,7 @@ fun <T> MongoCollection<T>.findOneAndReplace(filter: String, replacement: T, opt
* document as it was before the update or as it is after the update. If no documents matched the query filter, then null will be
* returned
*/
fun <T> MongoCollection<T>.findOneAndUpdate(filter: String, update: String, options: FindOneAndUpdateOptions = FindOneAndUpdateOptions()): T
fun <T> MongoCollection<T>.findOneAndUpdate(filter: String, update: String, options: FindOneAndUpdateOptions = FindOneAndUpdateOptions()): T?
= findOneAndUpdate(toBson(filter), toBson(update), options)

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.litote.kmongo.issues

import org.junit.Test
import org.litote.kmongo.KMongoBaseTest
import org.litote.kmongo.MongoOperator.set
import org.litote.kmongo.findOneAndReplace
import org.litote.kmongo.findOneAndUpdate
import org.litote.kmongo.model.Friend
import kotlin.test.assertNull

/**
*
*/
class Issue34FindOneAndUpdateOrReplaceCouldReturnNull : KMongoBaseTest<Friend>() {

@Test
fun findOneAndReplaceCouldReturnsNull() {
assertNull(col.findOneAndReplace("{}", Friend("test")))
}

@Test
fun findOneAndUpdateCouldReturnsNull() {
assertNull(col.findOneAndUpdate("{}", "{$set:{name:'John'}}"))
}

}

0 comments on commit 764b597

Please sign in to comment.