diff --git a/build.gradle b/build.gradle index 48d73fbdbcf..4601aed847f 100644 --- a/build.gradle +++ b/build.gradle @@ -109,7 +109,7 @@ configure(scalaProjects) { testImplementation('org.scalatest:scalatest-flatspec_%%:3.2.9') testImplementation('org.scalatest:scalatest-shouldmatchers_%%:3.2.9') testImplementation('org.scalatestplus:junit-4-13_%%:3.2.9.0') - testImplementation('org.scalamock:scalamock_%%:4.4.0') + testImplementation('org.scalatestplus:mockito-3-12_%%:3.2.10.0') testImplementation('ch.qos.logback:logback-classic:1.1.3') testImplementation('org.reflections:reflections:0.9.10') } diff --git a/driver-scala/src/test/scala/org/mongodb/scala/AggregateObservableSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/AggregateObservableSpec.scala index ed092dc4d26..d18004e5aa5 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/AggregateObservableSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/AggregateObservableSpec.scala @@ -20,12 +20,13 @@ import com.mongodb.ExplainVerbosity import java.util.concurrent.TimeUnit import com.mongodb.reactivestreams.client.AggregatePublisher +import org.mockito.Mockito.{ verify, verifyNoMoreInteractions } import org.mongodb.scala.model.Collation -import org.scalamock.scalatest.proxy.MockFactory +import org.scalatestplus.mockito.MockitoSugar import scala.concurrent.duration.Duration -class AggregateObservableSpec extends BaseSpec with MockFactory { +class AggregateObservableSpec extends BaseSpec with MockitoSugar { "AggregateObservable" should "have the same methods as the wrapped AggregateObservable" in { val wrapped: Set[String] = classOf[AggregatePublisher[Document]].getMethods.map(_.getName).toSet @@ -48,17 +49,6 @@ class AggregateObservableSpec extends BaseSpec with MockFactory { val ct = classOf[Document] val verbosity = ExplainVerbosity.QUERY_PLANNER - wrapper.expects(Symbol("allowDiskUse"))(true).once() - wrapper.expects(Symbol("maxTime"))(duration.toMillis, TimeUnit.MILLISECONDS).once() - wrapper.expects(Symbol("maxAwaitTime"))(duration.toMillis, TimeUnit.MILLISECONDS).once() - wrapper.expects(Symbol("bypassDocumentValidation"))(true).once() - wrapper.expects(Symbol("collation"))(collation).once() - wrapper.expects(Symbol("comment"))("comment").once() - wrapper.expects(Symbol("hint"))(hint).once() - wrapper.expects(Symbol("batchSize"))(batchSize).once() - wrapper.expects(Symbol("explain"))(ct).once() - wrapper.expects(Symbol("explain"))(ct, verbosity).once() - observable.allowDiskUse(true) observable.maxTime(duration) observable.maxAwaitTime(duration) @@ -70,7 +60,20 @@ class AggregateObservableSpec extends BaseSpec with MockFactory { observable.explain[Document]() observable.explain[Document](verbosity) - wrapper.expects(Symbol("toCollection"))().once() + verify(wrapper).allowDiskUse(true) + verify(wrapper).maxTime(duration.toMillis, TimeUnit.MILLISECONDS) + verify(wrapper).maxAwaitTime(duration.toMillis, TimeUnit.MILLISECONDS) + verify(wrapper).bypassDocumentValidation(true) + verify(wrapper).collation(collation) + verify(wrapper).comment("comment") + verify(wrapper).hint(hint) + verify(wrapper).batchSize(batchSize) + verify(wrapper).explain(ct) + verify(wrapper).explain(ct, verbosity) + observable.toCollection() + verify(wrapper).toCollection + + verifyNoMoreInteractions(wrapper) } } diff --git a/driver-scala/src/test/scala/org/mongodb/scala/ChangeStreamObservableSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/ChangeStreamObservableSpec.scala index 11c5f4b9aa7..c8dfd50ca05 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/ChangeStreamObservableSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/ChangeStreamObservableSpec.scala @@ -19,16 +19,17 @@ package org.mongodb.scala import java.util.concurrent.TimeUnit import com.mongodb.reactivestreams.client.ChangeStreamPublisher +import org.mockito.Mockito.{ verify, verifyNoMoreInteractions } import org.mongodb.scala.bson.BsonTimestamp import org.mongodb.scala.model.Collation import org.mongodb.scala.model.changestream.FullDocument import org.reactivestreams.Publisher -import org.scalamock.scalatest.proxy.MockFactory +import org.scalatestplus.mockito.MockitoSugar import scala.concurrent.duration.Duration -import scala.util.{ Success } +import scala.util.Success -class ChangeStreamObservableSpec extends BaseSpec with MockFactory { +class ChangeStreamObservableSpec extends BaseSpec with MockitoSugar { "ChangeStreamObservable" should "have the same methods as the wrapped ChangeStreamObservable" in { val mongoPublisher: Set[String] = classOf[Publisher[Document]].getMethods.map(_.getName).toSet @@ -54,15 +55,6 @@ class ChangeStreamObservableSpec extends BaseSpec with MockFactory { val collation = Collation.builder().locale("en").build() val batchSize = 10 - wrapper.expects(Symbol("batchSize"))(batchSize).once() - wrapper.expects(Symbol("fullDocument"))(fullDocument).once() - wrapper.expects(Symbol("resumeAfter"))(resumeToken.underlying).once() - wrapper.expects(Symbol("startAfter"))(resumeToken.underlying).once() - wrapper.expects(Symbol("startAtOperationTime"))(startAtTime).once() - wrapper.expects(Symbol("maxAwaitTime"))(duration.toMillis, TimeUnit.MILLISECONDS).once() - wrapper.expects(Symbol("collation"))(collation).once() - wrapper.expects(Symbol("withDocumentClass"))(classOf[Int]).once() - observable.batchSize(batchSize) observable.fullDocument(fullDocument) observable.resumeAfter(resumeToken) @@ -71,6 +63,17 @@ class ChangeStreamObservableSpec extends BaseSpec with MockFactory { observable.maxAwaitTime(duration) observable.collation(collation) observable.withDocumentClass(classOf[Int]) + + verify(wrapper).batchSize(batchSize) + verify(wrapper).fullDocument(fullDocument) + verify(wrapper).resumeAfter(resumeToken.underlying) + verify(wrapper).startAfter(resumeToken.underlying) + verify(wrapper).startAtOperationTime(startAtTime) + verify(wrapper).maxAwaitTime(duration.toMillis, TimeUnit.MILLISECONDS) + verify(wrapper).collation(collation) + verify(wrapper).withDocumentClass(classOf[Int]) + + verifyNoMoreInteractions(wrapper) } it should "mirror FullDocument" in { diff --git a/driver-scala/src/test/scala/org/mongodb/scala/DistinctObservableSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/DistinctObservableSpec.scala index 872e51be365..e609f8ccdc8 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/DistinctObservableSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/DistinctObservableSpec.scala @@ -18,13 +18,14 @@ package org.mongodb.scala import java.util.concurrent.TimeUnit import com.mongodb.reactivestreams.client.DistinctPublisher +import org.mockito.Mockito.{ verify, verifyNoMoreInteractions } import org.mongodb.scala.model.Collation import org.reactivestreams.Publisher -import org.scalamock.scalatest.proxy.MockFactory +import org.scalatestplus.mockito.MockitoSugar import scala.concurrent.duration.Duration -class DistinctObservableSpec extends BaseSpec with MockFactory { +class DistinctObservableSpec extends BaseSpec with MockitoSugar { "DistinctObservable" should "have the same methods as the wrapped DistinctObservable" in { val mongoPublisher: Set[String] = classOf[Publisher[Document]].getMethods.map(_.getName).toSet @@ -46,14 +47,15 @@ class DistinctObservableSpec extends BaseSpec with MockFactory { val collation = Collation.builder().locale("en").build() val batchSize = 10 - wrapper.expects(Symbol("filter"))(filter).once() - wrapper.expects(Symbol("maxTime"))(duration.toMillis, TimeUnit.MILLISECONDS).once() - wrapper.expects(Symbol("collation"))(collation).once() - wrapper.expects(Symbol("batchSize"))(batchSize).once() - observable.filter(filter) observable.maxTime(duration) observable.collation(collation) observable.batchSize(batchSize) + + verify(wrapper).filter(filter) + verify(wrapper).maxTime(duration.toMillis, TimeUnit.MILLISECONDS) + verify(wrapper).collation(collation) + verify(wrapper).batchSize(batchSize) + verifyNoMoreInteractions(wrapper) } } diff --git a/driver-scala/src/test/scala/org/mongodb/scala/FindObservableSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/FindObservableSpec.scala index 88c22cb64a1..d06053b96a2 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/FindObservableSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/FindObservableSpec.scala @@ -19,14 +19,14 @@ package org.mongodb.scala import java.util.concurrent.TimeUnit import com.mongodb.{ CursorType, ExplainVerbosity } import com.mongodb.reactivestreams.client.FindPublisher +import org.mockito.Mockito.{ verify, verifyNoMoreInteractions } import org.mongodb.scala.model.Collation import org.reactivestreams.Publisher -import org.scalamock.scalatest.proxy.MockFactory +import org.scalatestplus.mockito.MockitoSugar import scala.concurrent.duration.Duration -import scala.reflect.ClassTag -class FindObservableSpec extends BaseSpec with MockFactory { +class FindObservableSpec extends BaseSpec with MockitoSugar { "FindObservable" should "have the same methods as the wrapped FindPublisher" in { val mongoPublisher: Set[String] = classOf[Publisher[Document]].getMethods.map(_.getName).toSet @@ -55,27 +55,8 @@ class FindObservableSpec extends BaseSpec with MockFactory { val ct = classOf[Document] val verbosity = ExplainVerbosity.QUERY_PLANNER - wrapper.expects(Symbol("first"))().once() observable.first() - - wrapper.expects(Symbol("collation"))(collation).once() - wrapper.expects(Symbol("cursorType"))(CursorType.NonTailable).once() - wrapper.expects(Symbol("filter"))(filter).once() - wrapper.expects(Symbol("limit"))(1).once() - wrapper.expects(Symbol("hint"))(hint).once() - wrapper.expects(Symbol("hintString"))(hintString).once() - wrapper.expects(Symbol("maxAwaitTime"))(maxDuration.toMillis, TimeUnit.MILLISECONDS).once() - wrapper.expects(Symbol("maxTime"))(duration.toMillis, TimeUnit.MILLISECONDS).once() - wrapper.expects(Symbol("noCursorTimeout"))(true).once() - wrapper.expects(Symbol("oplogReplay"))(true).once() - wrapper.expects(Symbol("partial"))(true).once() - wrapper.expects(Symbol("projection"))(projection).once() - wrapper.expects(Symbol("skip"))(1).once() - wrapper.expects(Symbol("sort"))(sort).once() - wrapper.expects(Symbol("batchSize"))(batchSize).once() - wrapper.expects(Symbol("allowDiskUse"))(true).once() - wrapper.expects(Symbol("explain"))(ct).once() - wrapper.expects(Symbol("explain"))(ct, verbosity).once() + verify(wrapper).first() observable.collation(collation) observable.cursorType(CursorType.NonTailable) @@ -95,5 +76,25 @@ class FindObservableSpec extends BaseSpec with MockFactory { observable.allowDiskUse(true) observable.explain[Document]() observable.explain[Document](verbosity) + + verify(wrapper).collation(collation) + verify(wrapper).cursorType(CursorType.NonTailable) + verify(wrapper).filter(filter) + verify(wrapper).limit(1) + verify(wrapper).hint(hint) + verify(wrapper).hintString(hintString) + verify(wrapper).maxAwaitTime(maxDuration.toMillis, TimeUnit.MILLISECONDS) + verify(wrapper).maxTime(duration.toMillis, TimeUnit.MILLISECONDS) + verify(wrapper).noCursorTimeout(true) + verify(wrapper).oplogReplay(true) + verify(wrapper).partial(true) + verify(wrapper).projection(projection) + verify(wrapper).skip(1) + verify(wrapper).sort(sort) + verify(wrapper).batchSize(batchSize) + verify(wrapper).allowDiskUse(true) + verify(wrapper).explain(ct) + verify(wrapper).explain(ct, verbosity) + verifyNoMoreInteractions(wrapper) } } diff --git a/driver-scala/src/test/scala/org/mongodb/scala/ListCollectionsObservableSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/ListCollectionsObservableSpec.scala index e33a397a8e7..54e38f4f270 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/ListCollectionsObservableSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/ListCollectionsObservableSpec.scala @@ -19,12 +19,13 @@ package org.mongodb.scala import java.util.concurrent.TimeUnit import com.mongodb.reactivestreams.client.ListCollectionsPublisher +import org.mockito.Mockito.{ verify, verifyNoMoreInteractions } import org.reactivestreams.Publisher -import org.scalamock.scalatest.proxy.MockFactory +import org.scalatestplus.mockito.MockitoSugar import scala.concurrent.duration.Duration -class ListCollectionsObservableSpec extends BaseSpec with MockFactory { +class ListCollectionsObservableSpec extends BaseSpec with MockitoSugar { "ListCollectionsObservable" should "have the same methods as the wrapped ListCollectionsObservable" in { val mongoPublisher: Set[String] = classOf[Publisher[Document]].getMethods.map(_.getName).toSet @@ -45,12 +46,13 @@ class ListCollectionsObservableSpec extends BaseSpec with MockFactory { val duration = Duration(1, TimeUnit.SECONDS) val batchSize = 10 - wrapper.expects(Symbol("filter"))(filter).once() - wrapper.expects(Symbol("maxTime"))(duration.toMillis, TimeUnit.MILLISECONDS).once() - wrapper.expects(Symbol("batchSize"))(batchSize).once() - observable.filter(filter) observable.maxTime(duration) observable.batchSize(batchSize) + + verify(wrapper).filter(filter) + verify(wrapper).maxTime(duration.toMillis, TimeUnit.MILLISECONDS) + verify(wrapper).batchSize(batchSize) + verifyNoMoreInteractions(wrapper) } } diff --git a/driver-scala/src/test/scala/org/mongodb/scala/ListDatabasesObservableSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/ListDatabasesObservableSpec.scala index d6202529403..a0d36fac78d 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/ListDatabasesObservableSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/ListDatabasesObservableSpec.scala @@ -18,12 +18,13 @@ package org.mongodb.scala import java.util.concurrent.TimeUnit import com.mongodb.reactivestreams.client.ListDatabasesPublisher +import org.mockito.Mockito.{ verify, verifyNoMoreInteractions } import org.reactivestreams.Publisher -import org.scalamock.scalatest.proxy.MockFactory +import org.scalatestplus.mockito.MockitoSugar import scala.concurrent.duration.Duration -class ListDatabasesObservableSpec extends BaseSpec with MockFactory { +class ListDatabasesObservableSpec extends BaseSpec with MockitoSugar { "ListDatabasesObservable" should "have the same methods as the wrapped ListDatabasesObservable" in { val mongoPublisher: Set[String] = classOf[Publisher[Document]].getMethods.map(_.getName).toSet @@ -43,14 +44,16 @@ class ListDatabasesObservableSpec extends BaseSpec with MockFactory { val duration = Duration(1, TimeUnit.SECONDS) val batchSize = 10 - wrapper.expects(Symbol("maxTime"))(duration.toMillis, TimeUnit.MILLISECONDS).once() - wrapper.expects(Symbol("filter"))(filter).once() - wrapper.expects(Symbol("nameOnly"))(true).once() - wrapper.expects(Symbol("batchSize"))(batchSize).once() - observable.maxTime(duration) observable.filter(filter) observable.nameOnly(true) observable.batchSize(batchSize) + + verify(wrapper).maxTime(duration.toMillis, TimeUnit.MILLISECONDS) + verify(wrapper).filter(filter) + verify(wrapper).nameOnly(true) + verify(wrapper).batchSize(batchSize) + + verifyNoMoreInteractions(wrapper) } } diff --git a/driver-scala/src/test/scala/org/mongodb/scala/ListIndexesObservableSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/ListIndexesObservableSpec.scala index 63922aa0c20..29d7fbe670d 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/ListIndexesObservableSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/ListIndexesObservableSpec.scala @@ -18,12 +18,13 @@ package org.mongodb.scala import java.util.concurrent.TimeUnit import com.mongodb.reactivestreams.client.ListIndexesPublisher +import org.mockito.Mockito.{ verify, verifyNoMoreInteractions } import org.reactivestreams.Publisher -import org.scalamock.scalatest.proxy.MockFactory +import org.scalatestplus.mockito.MockitoSugar import scala.concurrent.duration.Duration -class ListIndexesObservableSpec extends BaseSpec with MockFactory { +class ListIndexesObservableSpec extends BaseSpec with MockitoSugar { "ListIndexesObservable" should "have the same methods as the wrapped ListIndexesObservable" in { val mongoPublisher: Set[String] = classOf[Publisher[Document]].getMethods.map(_.getName).toSet @@ -42,10 +43,11 @@ class ListIndexesObservableSpec extends BaseSpec with MockFactory { val duration = Duration(1, TimeUnit.SECONDS) val batchSize = 10 - wrapper.expects(Symbol("maxTime"))(duration.toMillis, TimeUnit.MILLISECONDS).once() - wrapper.expects(Symbol("batchSize"))(batchSize).once() - observable.maxTime(duration) observable.batchSize(batchSize) + + verify(wrapper).maxTime(duration.toMillis, TimeUnit.MILLISECONDS) + verify(wrapper).batchSize(batchSize) + verifyNoMoreInteractions(wrapper) } } diff --git a/driver-scala/src/test/scala/org/mongodb/scala/MapReduceObservableSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/MapReduceObservableSpec.scala index 9ebe742b579..dbb1d8551d0 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/MapReduceObservableSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/MapReduceObservableSpec.scala @@ -20,12 +20,13 @@ import java.util.concurrent.TimeUnit import com.mongodb.client.model.MapReduceAction import com.mongodb.reactivestreams.client.MapReducePublisher +import org.mockito.Mockito.{ verify, verifyNoMoreInteractions } import org.mongodb.scala.model.Collation -import org.scalamock.scalatest.proxy.MockFactory +import org.scalatestplus.mockito.MockitoSugar import scala.concurrent.duration.Duration -class MapReduceObservableSpec extends BaseSpec with MockFactory { +class MapReduceObservableSpec extends BaseSpec with MockitoSugar { "MapReduceObservable" should "have the same methods as the wrapped MapReduceObservable" in { val wrapped = classOf[MapReducePublisher[Document]].getMethods.map(_.getName).toSet @@ -48,23 +49,6 @@ class MapReduceObservableSpec extends BaseSpec with MockFactory { val collation = Collation.builder().locale("en").build() val batchSize = 10 - wrapper.expects(Symbol("filter"))(filter).once() - wrapper.expects(Symbol("scope"))(scope).once() - wrapper.expects(Symbol("sort"))(sort).once() - wrapper.expects(Symbol("limit"))(1).once() - wrapper.expects(Symbol("maxTime"))(duration.toMillis, TimeUnit.MILLISECONDS).once() - wrapper.expects(Symbol("collectionName"))("collectionName").once() - wrapper.expects(Symbol("databaseName"))("databaseName").once() - wrapper.expects(Symbol("finalizeFunction"))("final").once() - wrapper.expects(Symbol("action"))(MapReduceAction.REPLACE).once() - wrapper.expects(Symbol("jsMode"))(true).once() - wrapper.expects(Symbol("verbose"))(true).once() - wrapper.expects(Symbol("sharded"))(true).once() - wrapper.expects(Symbol("nonAtomic"))(true).once() - wrapper.expects(Symbol("bypassDocumentValidation"))(true).once() - wrapper.expects(Symbol("collation"))(collation).once() - wrapper.expects(Symbol("batchSize"))(batchSize).once() - observable.filter(filter) observable.scope(scope) observable.sort(sort) @@ -82,7 +66,25 @@ class MapReduceObservableSpec extends BaseSpec with MockFactory { observable.collation(collation) observable.batchSize(batchSize) - wrapper.expects(Symbol("toCollection"))().once() + verify(wrapper).filter(filter) + verify(wrapper).scope(scope) + verify(wrapper).sort(sort) + verify(wrapper).limit(1) + verify(wrapper).maxTime(duration.toMillis, TimeUnit.MILLISECONDS) + verify(wrapper).collectionName("collectionName") + verify(wrapper).databaseName("databaseName") + verify(wrapper).finalizeFunction("final") + verify(wrapper).action(MapReduceAction.REPLACE) + verify(wrapper).jsMode(true) + verify(wrapper).verbose(true) + verify(wrapper).sharded(true) + verify(wrapper).nonAtomic(true) + verify(wrapper).bypassDocumentValidation(true) + verify(wrapper).collation(collation) + verify(wrapper).batchSize(batchSize) + observable.toCollection() + verify(wrapper).toCollection + verifyNoMoreInteractions(wrapper) } } diff --git a/driver-scala/src/test/scala/org/mongodb/scala/MongoClientSettingsSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/MongoClientSettingsSpec.scala index 95c2daa65ef..81eb55cfad3 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/MongoClientSettingsSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/MongoClientSettingsSpec.scala @@ -21,10 +21,9 @@ import org.bson.codecs.configuration.CodecRegistries._ import org.mongodb.scala.MongoClient.DEFAULT_CODEC_REGISTRY import org.mongodb.scala.bson.codecs.DocumentCodecProvider import org.mongodb.scala.connection.ConnectionPoolSettings.Builder -import org.scalamock.scalatest.proxy.MockFactory import org.mongodb.scala.connection._ -class MongoClientSettingsSpec extends BaseSpec with MockFactory { +class MongoClientSettingsSpec extends BaseSpec { "MongoClientSettings" should "default with the Scala Codec Registry" in { MongoClientSettings.builder().build().getCodecRegistry should equal(DEFAULT_CODEC_REGISTRY) diff --git a/driver-scala/src/test/scala/org/mongodb/scala/MongoClientSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/MongoClientSpec.scala index 806ce090074..4c721ed8774 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/MongoClientSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/MongoClientSpec.scala @@ -18,11 +18,12 @@ package org.mongodb.scala import com.mongodb.reactivestreams.client.{ MongoClient => JMongoClient } import org.bson.BsonDocument -import org.scalamock.scalatest.proxy.MockFactory +import org.mockito.Mockito.verify +import org.scalatestplus.mockito.MockitoSugar import scala.collection.JavaConverters._ -class MongoClientSpec extends BaseSpec with MockFactory { +class MongoClientSpec extends BaseSpec with MockitoSugar { val wrapped = mock[JMongoClient] val clientSession = mock[ClientSession] @@ -44,62 +45,62 @@ class MongoClientSpec extends BaseSpec with MockFactory { } it should "call the underlying getDatabase" in { - wrapped.expects(Symbol("getDatabase"))("dbName").once() - mongoClient.getDatabase("dbName") + + verify(wrapped).getDatabase("dbName") } it should "call the underlying close" in { - wrapped.expects(Symbol("close"))().once() - mongoClient.close() + + verify(wrapped).close() } it should "call the underlying startSession" in { - val clientSessionOptions = ClientSessionOptions.builder.build() - wrapped.expects(Symbol("startSession"))(clientSessionOptions).once() - + val clientSessionOptions = ClientSessionOptions.builder().build() mongoClient.startSession(clientSessionOptions) + + verify(wrapped).startSession(clientSessionOptions) } it should "call the underlying listDatabases[T]" in { - wrapped.expects(Symbol("listDatabases"))(classOf[Document]).once() - wrapped.expects(Symbol("listDatabases"))(clientSession, classOf[Document]).once() - wrapped.expects(Symbol("listDatabases"))(classOf[BsonDocument]).once() - wrapped.expects(Symbol("listDatabases"))(clientSession, classOf[BsonDocument]).once() - mongoClient.listDatabases() mongoClient.listDatabases(clientSession) mongoClient.listDatabases[BsonDocument]() mongoClient.listDatabases[BsonDocument](clientSession) + + verify(wrapped).listDatabases(classOf[Document]) + verify(wrapped).listDatabases(clientSession, classOf[Document]) + verify(wrapped).listDatabases(classOf[BsonDocument]) + verify(wrapped).listDatabases(clientSession, classOf[BsonDocument]) } it should "call the underlying listDatabaseNames" in { - wrapped.expects(Symbol("listDatabaseNames"))().once() - wrapped.expects(Symbol("listDatabaseNames"))(clientSession).once() - mongoClient.listDatabaseNames() mongoClient.listDatabaseNames(clientSession) + + verify(wrapped).listDatabaseNames() + verify(wrapped).listDatabaseNames(clientSession) } it should "call the underlying watch" in { val pipeline = List(Document("$match" -> 1)) - wrapped.expects(Symbol("watch"))(classOf[Document]).once() - wrapped.expects(Symbol("watch"))(pipeline.asJava, classOf[Document]).once() - wrapped.expects(Symbol("watch"))(pipeline.asJava, classOf[BsonDocument]).once() - wrapped.expects(Symbol("watch"))(clientSession, pipeline.asJava, classOf[Document]).once() - wrapped.expects(Symbol("watch"))(clientSession, pipeline.asJava, classOf[BsonDocument]).once() - mongoClient.watch() shouldBe a[ChangeStreamObservable[_]] mongoClient.watch(pipeline) shouldBe a[ChangeStreamObservable[_]] mongoClient.watch[BsonDocument](pipeline) shouldBe a[ChangeStreamObservable[_]] mongoClient.watch(clientSession, pipeline) shouldBe a[ChangeStreamObservable[_]] mongoClient.watch[BsonDocument](clientSession, pipeline) shouldBe a[ChangeStreamObservable[_]] + + verify(wrapped).watch(classOf[Document]) + verify(wrapped).watch(pipeline.asJava, classOf[Document]) + verify(wrapped).watch(pipeline.asJava, classOf[BsonDocument]) + verify(wrapped).watch(clientSession, pipeline.asJava, classOf[Document]) + verify(wrapped).watch(clientSession, pipeline.asJava, classOf[BsonDocument]) } it should "call the underlying getClusterDescription" in { - wrapped.expects(Symbol("getClusterDescription"))().once() mongoClient.getClusterDescription + verify(wrapped).getClusterDescription } } diff --git a/driver-scala/src/test/scala/org/mongodb/scala/MongoCollectionSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/MongoCollectionSpec.scala index dee52bef52f..1f942a418e8 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/MongoCollectionSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/MongoCollectionSpec.scala @@ -22,12 +22,13 @@ import com.mongodb.reactivestreams.client.{ MongoCollection => JMongoCollection import org.bson.BsonDocument import org.bson.codecs.BsonValueCodecProvider import org.bson.codecs.configuration.CodecRegistries.fromProviders +import org.mockito.Mockito.{ times, verify } import org.mongodb.scala.model._ -import org.scalamock.scalatest.proxy.MockFactory +import org.scalatestplus.mockito.MockitoSugar import scala.collection.JavaConverters._ -class MongoCollectionSpec extends BaseSpec with MockFactory { +class MongoCollectionSpec extends BaseSpec with MockitoSugar { val wrapped = mock[JMongoCollection[Document]] val clientSession = mock[ClientSession] @@ -48,129 +49,120 @@ class MongoCollectionSpec extends BaseSpec with MockFactory { } it should "return the underlying getNamespace" in { - wrapped.expects(Symbol("getNamespace"))().once() - mongoCollection.namespace + + verify(wrapped).getNamespace } it should "return the underlying getCodecRegistry" in { - wrapped.expects(Symbol("getCodecRegistry"))().once() - mongoCollection.codecRegistry + + verify(wrapped).getCodecRegistry } it should "return the underlying getReadPreference" in { - wrapped.expects(Symbol("getReadPreference"))().once() - mongoCollection.readPreference + + verify(wrapped).getReadPreference } it should "return the underlying getWriteConcern" in { - wrapped.expects(Symbol("getWriteConcern"))().once() - mongoCollection.writeConcern + + verify(wrapped).getWriteConcern } it should "return the underlying getReadConcern" in { - wrapped.expects(Symbol("getReadConcern"))().once() - mongoCollection.readConcern + + verify(wrapped).getReadConcern } it should "return the underlying getDocumentClass" in { - wrapped.expects(Symbol("getDocumentClass"))().once() - mongoCollection.documentClass + + verify(wrapped).getDocumentClass } it should "return the underlying withCodecRegistry" in { val codecRegistry = fromProviders(new BsonValueCodecProvider()) - wrapped.expects(Symbol("withCodecRegistry"))(codecRegistry).once() - mongoCollection.withCodecRegistry(codecRegistry) + + verify(wrapped).withCodecRegistry(codecRegistry) } it should "return the underlying withReadPreference" in { - wrapped.expects(Symbol("withReadPreference"))(readPreference).once() - mongoCollection.withReadPreference(readPreference) + + verify(wrapped).withReadPreference(readPreference) } it should "return the underlying withWriteConcern" in { val writeConcern = WriteConcern.MAJORITY - wrapped.expects(Symbol("withWriteConcern"))(writeConcern).once() - mongoCollection.withWriteConcern(writeConcern) + + verify(wrapped).withWriteConcern(writeConcern) } it should "return the underlying withReadConcern" in { val readConcern = ReadConcern.MAJORITY - wrapped.expects(Symbol("withReadConcern"))(readConcern).once() - mongoCollection.withReadConcern(readConcern) + + verify(wrapped).withReadConcern(readConcern) } it should "return the underlying withDocumentClass" in { - wrapped.expects(Symbol("withDocumentClass"))(classOf[Document]).once() - wrapped.expects(Symbol("withDocumentClass"))(classOf[Document]).once() - wrapped.expects(Symbol("withDocumentClass"))(classOf[BsonDocument]).once() - mongoCollection.withDocumentClass() mongoCollection.withDocumentClass[Document]() mongoCollection.withDocumentClass[BsonDocument]() + + verify(wrapped, times(2)).withDocumentClass(classOf[Document]) + verify(wrapped).withDocumentClass(classOf[BsonDocument]) + } it should "return the underlying countDocuments" in { val countOptions = CountOptions() - wrapped.expects(Symbol("countDocuments"))().once() - wrapped.expects(Symbol("countDocuments"))(filter).once() - wrapped.expects(Symbol("countDocuments"))(filter, countOptions).once() - wrapped.expects(Symbol("countDocuments"))(clientSession).once() - wrapped.expects(Symbol("countDocuments"))(clientSession, filter).once() - wrapped.expects(Symbol("countDocuments"))(clientSession, filter, countOptions).once() - mongoCollection.countDocuments() mongoCollection.countDocuments(filter) mongoCollection.countDocuments(filter, countOptions) mongoCollection.countDocuments(clientSession) mongoCollection.countDocuments(clientSession, filter) mongoCollection.countDocuments(clientSession, filter, countOptions) + + verify(wrapped).countDocuments() + verify(wrapped).countDocuments(filter) + verify(wrapped).countDocuments(filter, countOptions) + verify(wrapped).countDocuments(clientSession) + verify(wrapped).countDocuments(clientSession, filter) + verify(wrapped).countDocuments(clientSession, filter, countOptions) } it should "return the underlying estimatedDocumentCount" in { val options = EstimatedDocumentCountOptions().maxTime(1, TimeUnit.SECONDS) - wrapped.expects(Symbol("estimatedDocumentCount"))().once() - wrapped.expects(Symbol("estimatedDocumentCount"))(options).once() - mongoCollection.estimatedDocumentCount() mongoCollection.estimatedDocumentCount(options) + + verify(wrapped).estimatedDocumentCount() + verify(wrapped).estimatedDocumentCount(options) } it should "wrap the underlying DistinctObservable correctly" in { - wrapped.expects(Symbol("distinct"))("fieldName", classOf[String]).once() - wrapped.expects(Symbol("distinct"))("fieldName", filter, classOf[String]).once() - wrapped.expects(Symbol("distinct"))(clientSession, "fieldName", classOf[String]).once() - wrapped.expects(Symbol("distinct"))(clientSession, "fieldName", filter, classOf[String]).once() - mongoCollection.distinct[String]("fieldName") mongoCollection.distinct[String]("fieldName", filter) mongoCollection.distinct[String](clientSession, "fieldName") mongoCollection.distinct[String](clientSession, "fieldName", filter) + + verify(wrapped).distinct("fieldName", classOf[String]) + verify(wrapped).distinct("fieldName", filter, classOf[String]) + verify(wrapped).distinct(clientSession, "fieldName", classOf[String]) + verify(wrapped).distinct(clientSession, "fieldName", filter, classOf[String]) } it should "wrap the underlying FindObservable correctly" in { - wrapped.expects(Symbol("find"))(classOf[Document]).once() - wrapped.expects(Symbol("find"))(classOf[BsonDocument]).once() - wrapped.expects(Symbol("find"))(filter, classOf[Document]).once() - wrapped.expects(Symbol("find"))(filter, classOf[BsonDocument]).once() - wrapped.expects(Symbol("find"))(clientSession, classOf[Document]).once() - wrapped.expects(Symbol("find"))(clientSession, classOf[BsonDocument]).once() - wrapped.expects(Symbol("find"))(clientSession, filter, classOf[Document]).once() - wrapped.expects(Symbol("find"))(clientSession, filter, classOf[BsonDocument]).once() - mongoCollection.find() shouldBe a[FindObservable[_]] mongoCollection.find[BsonDocument]() shouldBe a[FindObservable[_]] mongoCollection.find(filter) shouldBe a[FindObservable[_]] @@ -179,32 +171,41 @@ class MongoCollectionSpec extends BaseSpec with MockFactory { mongoCollection.find[BsonDocument](clientSession) shouldBe a[FindObservable[_]] mongoCollection.find(clientSession, filter) shouldBe a[FindObservable[_]] mongoCollection.find[BsonDocument](clientSession, filter) shouldBe a[FindObservable[_]] + + verify(wrapped).find(classOf[Document]) + verify(wrapped).find(classOf[BsonDocument]) + verify(wrapped).find(filter, classOf[Document]) + verify(wrapped).find(filter, classOf[BsonDocument]) + verify(wrapped).find(clientSession, classOf[Document]) + verify(wrapped).find(clientSession, classOf[BsonDocument]) + verify(wrapped).find(clientSession, filter, classOf[Document]) + verify(wrapped).find(clientSession, filter, classOf[BsonDocument]) } it should "wrap the underlying AggregateObservable correctly" in { val pipeline = List(Document("$match" -> 1)) - wrapped.expects(Symbol("aggregate"))(pipeline.asJava, classOf[Document]).once() - wrapped.expects(Symbol("aggregate"))(pipeline.asJava, classOf[BsonDocument]).once() - wrapped.expects(Symbol("aggregate"))(clientSession, pipeline.asJava, classOf[Document]).once() - wrapped.expects(Symbol("aggregate"))(clientSession, pipeline.asJava, classOf[BsonDocument]).once() - mongoCollection.aggregate(pipeline) shouldBe a[AggregateObservable[_]] mongoCollection.aggregate[BsonDocument](pipeline) shouldBe a[AggregateObservable[_]] mongoCollection.aggregate(clientSession, pipeline) shouldBe a[AggregateObservable[_]] mongoCollection.aggregate[BsonDocument](clientSession, pipeline) shouldBe a[AggregateObservable[_]] + + verify(wrapped).aggregate(pipeline.asJava, classOf[Document]) + verify(wrapped).aggregate(pipeline.asJava, classOf[BsonDocument]) + verify(wrapped).aggregate(clientSession, pipeline.asJava, classOf[Document]) + verify(wrapped).aggregate(clientSession, pipeline.asJava, classOf[BsonDocument]) } it should "wrap the underlying MapReduceObservable correctly" in { - wrapped.expects(Symbol("mapReduce"))("map", "reduce", classOf[Document]).once() - wrapped.expects(Symbol("mapReduce"))("map", "reduce", classOf[BsonDocument]).once() - wrapped.expects(Symbol("mapReduce"))(clientSession, "map", "reduce", classOf[Document]).once() - wrapped.expects(Symbol("mapReduce"))(clientSession, "map", "reduce", classOf[BsonDocument]).once() - mongoCollection.mapReduce("map", "reduce") shouldBe a[MapReduceObservable[_]] mongoCollection.mapReduce[BsonDocument]("map", "reduce") shouldBe a[MapReduceObservable[_]] mongoCollection.mapReduce(clientSession, "map", "reduce") shouldBe a[MapReduceObservable[_]] mongoCollection.mapReduce[BsonDocument](clientSession, "map", "reduce") shouldBe a[MapReduceObservable[_]] + + verify(wrapped).mapReduce("map", "reduce", classOf[Document]) + verify(wrapped).mapReduce("map", "reduce", classOf[BsonDocument]) + verify(wrapped).mapReduce(clientSession, "map", "reduce", classOf[Document]) + verify(wrapped).mapReduce(clientSession, "map", "reduce", classOf[BsonDocument]) } it should "wrap the underlying bulkWrite correctly" in { @@ -215,85 +216,87 @@ class MongoCollectionSpec extends BaseSpec with MockFactory { ) val bulkWriteOptions = new BulkWriteOptions().ordered(true) - wrapped.expects(Symbol("bulkWrite"))(bulkRequests.asJava).once() - wrapped.expects(Symbol("bulkWrite"))(bulkRequests.asJava, bulkWriteOptions).once() - wrapped.expects(Symbol("bulkWrite"))(clientSession, bulkRequests.asJava).once() - wrapped.expects(Symbol("bulkWrite"))(clientSession, bulkRequests.asJava, bulkWriteOptions).once() - mongoCollection.bulkWrite(bulkRequests) mongoCollection.bulkWrite(bulkRequests, bulkWriteOptions) mongoCollection.bulkWrite(clientSession, bulkRequests) mongoCollection.bulkWrite(clientSession, bulkRequests, bulkWriteOptions) + + verify(wrapped).bulkWrite(bulkRequests.asJava) + verify(wrapped).bulkWrite(bulkRequests.asJava, bulkWriteOptions) + verify(wrapped).bulkWrite(clientSession, bulkRequests.asJava) + verify(wrapped).bulkWrite(clientSession, bulkRequests.asJava, bulkWriteOptions) } it should "wrap the underlying insertOne correctly" in { val insertDoc = Document("a" -> 1) val insertOptions = InsertOneOptions().bypassDocumentValidation(true) - wrapped.expects(Symbol("insertOne"))(insertDoc).once() - wrapped.expects(Symbol("insertOne"))(insertDoc, insertOptions).once() - wrapped.expects(Symbol("insertOne"))(clientSession, insertDoc).once() - wrapped.expects(Symbol("insertOne"))(clientSession, insertDoc, insertOptions).once() mongoCollection.insertOne(insertDoc) mongoCollection.insertOne(insertDoc, insertOptions) mongoCollection.insertOne(clientSession, insertDoc) mongoCollection.insertOne(clientSession, insertDoc, insertOptions) + + verify(wrapped).insertOne(insertDoc) + verify(wrapped).insertOne(insertDoc, insertOptions) + verify(wrapped).insertOne(clientSession, insertDoc) + verify(wrapped).insertOne(clientSession, insertDoc, insertOptions) } it should "wrap the underlying insertMany correctly" in { val insertDocs = List(Document("a" -> 1)) val insertOptions = new InsertManyOptions().ordered(false) - wrapped.expects(Symbol("insertMany"))(insertDocs.asJava).once() - wrapped.expects(Symbol("insertMany"))(insertDocs.asJava, insertOptions).once() - wrapped.expects(Symbol("insertMany"))(clientSession, insertDocs.asJava).once() - wrapped.expects(Symbol("insertMany"))(clientSession, insertDocs.asJava, insertOptions).once() - mongoCollection.insertMany(insertDocs) mongoCollection.insertMany(insertDocs, insertOptions) mongoCollection.insertMany(clientSession, insertDocs) mongoCollection.insertMany(clientSession, insertDocs, insertOptions) + + verify(wrapped).insertMany(insertDocs.asJava) + verify(wrapped).insertMany(insertDocs.asJava, insertOptions) + verify(wrapped).insertMany(clientSession, insertDocs.asJava) + verify(wrapped).insertMany(clientSession, insertDocs.asJava, insertOptions) } it should "wrap the underlying deleteOne correctly" in { val options = new DeleteOptions().collation(collation) - wrapped.expects(Symbol("deleteOne"))(filter).once() - wrapped.expects(Symbol("deleteOne"))(filter, options).once() - wrapped.expects(Symbol("deleteOne"))(clientSession, filter).once() - wrapped.expects(Symbol("deleteOne"))(clientSession, filter, options).once() mongoCollection.deleteOne(filter) mongoCollection.deleteOne(filter, options) mongoCollection.deleteOne(clientSession, filter) mongoCollection.deleteOne(clientSession, filter, options) + + verify(wrapped).deleteOne(filter) + verify(wrapped).deleteOne(filter, options) + verify(wrapped).deleteOne(clientSession, filter) + verify(wrapped).deleteOne(clientSession, filter, options) } it should "wrap the underlying deleteMany correctly" in { val options = new DeleteOptions().collation(collation) - wrapped.expects(Symbol("deleteMany"))(filter).once() - wrapped.expects(Symbol("deleteMany"))(filter, options).once() - wrapped.expects(Symbol("deleteMany"))(clientSession, filter).once() - wrapped.expects(Symbol("deleteMany"))(clientSession, filter, options).once() - mongoCollection.deleteMany(filter) mongoCollection.deleteMany(filter, options) mongoCollection.deleteMany(clientSession, filter) mongoCollection.deleteMany(clientSession, filter, options) + + verify(wrapped).deleteMany(filter) + verify(wrapped).deleteMany(filter, options) + verify(wrapped).deleteMany(clientSession, filter) + verify(wrapped).deleteMany(clientSession, filter, options) } it should "wrap the underlying replaceOne correctly" in { val replacement = Document("a" -> 1) val replaceOptions = new ReplaceOptions().upsert(true) - wrapped.expects(Symbol("replaceOne"))(filter, replacement).once() - wrapped.expects(Symbol("replaceOne"))(filter, replacement, replaceOptions).once() - wrapped.expects(Symbol("replaceOne"))(clientSession, filter, replacement).once() - wrapped.expects(Symbol("replaceOne"))(clientSession, filter, replacement, replaceOptions).once() - mongoCollection.replaceOne(filter, replacement) mongoCollection.replaceOne(filter, replacement, replaceOptions) mongoCollection.replaceOne(clientSession, filter, replacement) mongoCollection.replaceOne(clientSession, filter, replacement, replaceOptions) + + verify(wrapped).replaceOne(filter, replacement) + verify(wrapped).replaceOne(filter, replacement, replaceOptions) + verify(wrapped).replaceOne(clientSession, filter, replacement) + verify(wrapped).replaceOne(clientSession, filter, replacement, replaceOptions) } it should "wrap the underlying updateOne correctly" in { @@ -301,16 +304,6 @@ class MongoCollectionSpec extends BaseSpec with MockFactory { val pipeline = Seq(update) val updateOptions = new UpdateOptions().upsert(true) - wrapped.expects(Symbol("updateOne"))(filter, update).once() - wrapped.expects(Symbol("updateOne"))(filter, update, updateOptions).once() - wrapped.expects(Symbol("updateOne"))(clientSession, filter, update).once() - wrapped.expects(Symbol("updateOne"))(clientSession, filter, update, updateOptions).once() - - wrapped.expects(Symbol("updateOne"))(filter, pipeline.asJava).once() - wrapped.expects(Symbol("updateOne"))(filter, pipeline.asJava, updateOptions).once() - wrapped.expects(Symbol("updateOne"))(clientSession, filter, pipeline.asJava).once() - wrapped.expects(Symbol("updateOne"))(clientSession, filter, pipeline.asJava, updateOptions).once() - mongoCollection.updateOne(filter, update) mongoCollection.updateOne(filter, update, updateOptions) mongoCollection.updateOne(clientSession, filter, update) @@ -320,6 +313,16 @@ class MongoCollectionSpec extends BaseSpec with MockFactory { mongoCollection.updateOne(filter, pipeline, updateOptions) mongoCollection.updateOne(clientSession, filter, pipeline) mongoCollection.updateOne(clientSession, filter, pipeline, updateOptions) + + verify(wrapped).updateOne(filter, update) + verify(wrapped).updateOne(filter, update, updateOptions) + verify(wrapped).updateOne(clientSession, filter, update) + verify(wrapped).updateOne(clientSession, filter, update, updateOptions) + + verify(wrapped).updateOne(filter, pipeline.asJava) + verify(wrapped).updateOne(filter, pipeline.asJava, updateOptions) + verify(wrapped).updateOne(clientSession, filter, pipeline.asJava) + verify(wrapped).updateOne(clientSession, filter, pipeline.asJava, updateOptions) } it should "wrap the underlying updateMany correctly" in { @@ -327,16 +330,6 @@ class MongoCollectionSpec extends BaseSpec with MockFactory { val pipeline = Seq(update) val updateOptions = new UpdateOptions().upsert(true) - wrapped.expects(Symbol("updateMany"))(filter, update).once() - wrapped.expects(Symbol("updateMany"))(filter, update, updateOptions).once() - wrapped.expects(Symbol("updateMany"))(clientSession, filter, update).once() - wrapped.expects(Symbol("updateMany"))(clientSession, filter, update, updateOptions).once() - - wrapped.expects(Symbol("updateMany"))(filter, pipeline.asJava).once() - wrapped.expects(Symbol("updateMany"))(filter, pipeline.asJava, updateOptions).once() - wrapped.expects(Symbol("updateMany"))(clientSession, filter, pipeline.asJava).once() - wrapped.expects(Symbol("updateMany"))(clientSession, filter, pipeline.asJava, updateOptions).once() - mongoCollection.updateMany(filter, update) mongoCollection.updateMany(filter, update, updateOptions) mongoCollection.updateMany(clientSession, filter, update) @@ -346,35 +339,45 @@ class MongoCollectionSpec extends BaseSpec with MockFactory { mongoCollection.updateMany(filter, pipeline, updateOptions) mongoCollection.updateMany(clientSession, filter, pipeline) mongoCollection.updateMany(clientSession, filter, pipeline, updateOptions) + + verify(wrapped).updateMany(filter, update) + verify(wrapped).updateMany(filter, update, updateOptions) + verify(wrapped).updateMany(clientSession, filter, update) + verify(wrapped).updateMany(clientSession, filter, update, updateOptions) + + verify(wrapped).updateMany(filter, pipeline.asJava) + verify(wrapped).updateMany(filter, pipeline.asJava, updateOptions) + verify(wrapped).updateMany(clientSession, filter, pipeline.asJava) + verify(wrapped).updateMany(clientSession, filter, pipeline.asJava, updateOptions) } it should "wrap the underlying findOneAndDelete correctly" in { val options = new FindOneAndDeleteOptions().sort(Document("sort" -> 1)) - wrapped.expects(Symbol("findOneAndDelete"))(filter).once() - wrapped.expects(Symbol("findOneAndDelete"))(filter, options).once() - wrapped.expects(Symbol("findOneAndDelete"))(clientSession, filter).once() - wrapped.expects(Symbol("findOneAndDelete"))(clientSession, filter, options).once() - mongoCollection.findOneAndDelete(filter) mongoCollection.findOneAndDelete(filter, options) mongoCollection.findOneAndDelete(clientSession, filter) mongoCollection.findOneAndDelete(clientSession, filter, options) + + verify(wrapped).findOneAndDelete(filter) + verify(wrapped).findOneAndDelete(filter, options) + verify(wrapped).findOneAndDelete(clientSession, filter) + verify(wrapped).findOneAndDelete(clientSession, filter, options) } it should "wrap the underlying findOneAndReplace correctly" in { val replacement = Document("a" -> 2) val options = new FindOneAndReplaceOptions().sort(Document("sort" -> 1)) - wrapped.expects(Symbol("findOneAndReplace"))(filter, replacement).once() - wrapped.expects(Symbol("findOneAndReplace"))(filter, replacement, options).once() - wrapped.expects(Symbol("findOneAndReplace"))(clientSession, filter, replacement).once() - wrapped.expects(Symbol("findOneAndReplace"))(clientSession, filter, replacement, options).once() - mongoCollection.findOneAndReplace(filter, replacement) mongoCollection.findOneAndReplace(filter, replacement, options) mongoCollection.findOneAndReplace(clientSession, filter, replacement) mongoCollection.findOneAndReplace(clientSession, filter, replacement, options) + + verify(wrapped).findOneAndReplace(filter, replacement) + verify(wrapped).findOneAndReplace(filter, replacement, options) + verify(wrapped).findOneAndReplace(clientSession, filter, replacement) + verify(wrapped).findOneAndReplace(clientSession, filter, replacement, options) } it should "wrap the underlying findOneAndUpdate correctly" in { @@ -382,16 +385,6 @@ class MongoCollectionSpec extends BaseSpec with MockFactory { val pipeline = Seq(update) val options = new FindOneAndUpdateOptions().sort(Document("sort" -> 1)) - wrapped.expects(Symbol("findOneAndUpdate"))(filter, update).once() - wrapped.expects(Symbol("findOneAndUpdate"))(filter, update, options).once() - wrapped.expects(Symbol("findOneAndUpdate"))(clientSession, filter, update).once() - wrapped.expects(Symbol("findOneAndUpdate"))(clientSession, filter, update, options).once() - - wrapped.expects(Symbol("findOneAndUpdate"))(filter, pipeline.asJava).once() - wrapped.expects(Symbol("findOneAndUpdate"))(filter, pipeline.asJava, options).once() - wrapped.expects(Symbol("findOneAndUpdate"))(clientSession, filter, pipeline.asJava).once() - wrapped.expects(Symbol("findOneAndUpdate"))(clientSession, filter, pipeline.asJava, options).once() - mongoCollection.findOneAndUpdate(filter, update) mongoCollection.findOneAndUpdate(filter, update, options) mongoCollection.findOneAndUpdate(clientSession, filter, update) @@ -401,70 +394,71 @@ class MongoCollectionSpec extends BaseSpec with MockFactory { mongoCollection.findOneAndUpdate(filter, pipeline, options) mongoCollection.findOneAndUpdate(clientSession, filter, pipeline) mongoCollection.findOneAndUpdate(clientSession, filter, pipeline, options) + + verify(wrapped).findOneAndUpdate(filter, update) + verify(wrapped).findOneAndUpdate(filter, update, options) + verify(wrapped).findOneAndUpdate(clientSession, filter, update) + verify(wrapped).findOneAndUpdate(clientSession, filter, update, options) + + verify(wrapped).findOneAndUpdate(filter, pipeline.asJava) + verify(wrapped).findOneAndUpdate(filter, pipeline.asJava, options) + verify(wrapped).findOneAndUpdate(clientSession, filter, pipeline.asJava) + verify(wrapped).findOneAndUpdate(clientSession, filter, pipeline.asJava, options) } it should "wrap the underlying drop correctly" in { - wrapped.expects(Symbol("drop"))().once() - wrapped.expects(Symbol("drop"))(clientSession).once() - mongoCollection.drop() mongoCollection.drop(clientSession) + + verify(wrapped).drop() + verify(wrapped).drop(clientSession) } it should "wrap the underlying createIndex correctly" in { val index = Document("a" -> 1) val options = new IndexOptions().background(true) - wrapped.expects(Symbol("createIndex"))(index).once() - wrapped.expects(Symbol("createIndex"))(index, options).once() - wrapped.expects(Symbol("createIndex"))(clientSession, index).once() - wrapped.expects(Symbol("createIndex"))(clientSession, index, options).once() - mongoCollection.createIndex(index) mongoCollection.createIndex(index, options) mongoCollection.createIndex(clientSession, index) mongoCollection.createIndex(clientSession, index, options) + + verify(wrapped).createIndex(index) + verify(wrapped).createIndex(index, options) + verify(wrapped).createIndex(clientSession, index) + verify(wrapped).createIndex(clientSession, index, options) } it should "wrap the underlying createIndexes correctly" in { val indexes = new IndexModel(Document("a" -> 1)) val options = new CreateIndexOptions() - // https://github.com/paulbutcher/ScalaMock/issues/93 - wrapped.expects(Symbol("createIndexes"))(List(indexes).asJava).once() - wrapped.expects(Symbol("createIndexes"))(List(indexes).asJava, options).once() - wrapped.expects(Symbol("createIndexes"))(clientSession, List(indexes).asJava).once() - wrapped.expects(Symbol("createIndexes"))(clientSession, List(indexes).asJava, options).once() - mongoCollection.createIndexes(List(indexes)) mongoCollection.createIndexes(List(indexes), options) mongoCollection.createIndexes(clientSession, List(indexes)) mongoCollection.createIndexes(clientSession, List(indexes), options) + + verify(wrapped).createIndexes(List(indexes).asJava) + verify(wrapped).createIndexes(List(indexes).asJava, options) + verify(wrapped).createIndexes(clientSession, List(indexes).asJava) + verify(wrapped).createIndexes(clientSession, List(indexes).asJava, options) } it should "wrap the underlying listIndexes correctly" in { - wrapped.expects(Symbol("listIndexes"))(classOf[Document]).once() - wrapped.expects(Symbol("listIndexes"))(classOf[BsonDocument]).once() - wrapped.expects(Symbol("listIndexes"))(clientSession, classOf[Document]).once() - wrapped.expects(Symbol("listIndexes"))(clientSession, classOf[BsonDocument]).once() - mongoCollection.listIndexes() mongoCollection.listIndexes[BsonDocument]() mongoCollection.listIndexes(clientSession) mongoCollection.listIndexes[BsonDocument](clientSession) + + verify(wrapped).listIndexes(classOf[Document]) + verify(wrapped).listIndexes(classOf[BsonDocument]) + verify(wrapped).listIndexes(clientSession, classOf[Document]) + verify(wrapped).listIndexes(clientSession, classOf[BsonDocument]) } it should "wrap the underlying dropIndex correctly" in { val indexDocument = Document("""{a: 1}""") val options = new DropIndexOptions() - wrapped.expects(Symbol("dropIndex"))("indexName").once() - wrapped.expects(Symbol("dropIndex"))(indexDocument).once() - wrapped.expects(Symbol("dropIndex"))("indexName", options).once() - wrapped.expects(Symbol("dropIndex"))(indexDocument, options).once() - wrapped.expects(Symbol("dropIndex"))(clientSession, "indexName").once() - wrapped.expects(Symbol("dropIndex"))(clientSession, indexDocument).once() - wrapped.expects(Symbol("dropIndex"))(clientSession, "indexName", options).once() - wrapped.expects(Symbol("dropIndex"))(clientSession, indexDocument, options).once() mongoCollection.dropIndex("indexName") mongoCollection.dropIndex(indexDocument) @@ -474,49 +468,49 @@ class MongoCollectionSpec extends BaseSpec with MockFactory { mongoCollection.dropIndex(clientSession, indexDocument) mongoCollection.dropIndex(clientSession, "indexName", options) mongoCollection.dropIndex(clientSession, indexDocument, options) + + verify(wrapped).dropIndex("indexName") + verify(wrapped).dropIndex(indexDocument) + verify(wrapped).dropIndex("indexName", options) + verify(wrapped).dropIndex(indexDocument, options) + verify(wrapped).dropIndex(clientSession, "indexName") + verify(wrapped).dropIndex(clientSession, indexDocument) + verify(wrapped).dropIndex(clientSession, "indexName", options) + verify(wrapped).dropIndex(clientSession, indexDocument, options) } it should "wrap the underlying dropIndexes correctly" in { - val options = new DropIndexOptions() - wrapped.expects(Symbol("dropIndexes"))().once() - wrapped.expects(Symbol("dropIndexes"))(options).once() - wrapped.expects(Symbol("dropIndexes"))(clientSession).once() - wrapped.expects(Symbol("dropIndexes"))(clientSession, options).once() mongoCollection.dropIndexes() mongoCollection.dropIndexes(options) mongoCollection.dropIndexes(clientSession) mongoCollection.dropIndexes(clientSession, options) + + verify(wrapped).dropIndexes() + verify(wrapped).dropIndexes(options) + verify(wrapped).dropIndexes(clientSession) + verify(wrapped).dropIndexes(clientSession, options) } it should "wrap the underlying renameCollection correctly" in { val newNamespace = new MongoNamespace("db", "coll") val options = new RenameCollectionOptions() - wrapped.expects(Symbol("renameCollection"))(newNamespace).once() - wrapped.expects(Symbol("renameCollection"))(newNamespace, options).once() - wrapped.expects(Symbol("renameCollection"))(clientSession, newNamespace).once() - wrapped.expects(Symbol("renameCollection"))(clientSession, newNamespace, options).once() - mongoCollection.renameCollection(newNamespace) mongoCollection.renameCollection(newNamespace, options) mongoCollection.renameCollection(clientSession, newNamespace) mongoCollection.renameCollection(clientSession, newNamespace, options) + + verify(wrapped).renameCollection(newNamespace) + verify(wrapped).renameCollection(newNamespace, options) + verify(wrapped).renameCollection(clientSession, newNamespace) + verify(wrapped).renameCollection(clientSession, newNamespace, options) } it should "wrap the underlying ChangeStreamPublisher correctly" in { val pipeline = List(Document("$match" -> 1)) - wrapped.expects(Symbol("watch"))(classOf[Document]).once() - wrapped.expects(Symbol("watch"))(classOf[BsonDocument]).once() - wrapped.expects(Symbol("watch"))(pipeline.asJava, classOf[Document]).once() - wrapped.expects(Symbol("watch"))(pipeline.asJava, classOf[BsonDocument]).once() - wrapped.expects(Symbol("watch"))(clientSession, classOf[Document]).once() - wrapped.expects(Symbol("watch"))(clientSession, classOf[BsonDocument]).once() - wrapped.expects(Symbol("watch"))(clientSession, pipeline.asJava, classOf[Document]).once() - wrapped.expects(Symbol("watch"))(clientSession, pipeline.asJava, classOf[BsonDocument]).once() - mongoCollection.watch() shouldBe a[ChangeStreamObservable[_]] mongoCollection.watch[BsonDocument]() shouldBe a[ChangeStreamObservable[_]] mongoCollection.watch(pipeline) shouldBe a[ChangeStreamObservable[_]] @@ -525,6 +519,15 @@ class MongoCollectionSpec extends BaseSpec with MockFactory { mongoCollection.watch[BsonDocument](clientSession) shouldBe a[ChangeStreamObservable[_]] mongoCollection.watch(clientSession, pipeline) shouldBe a[ChangeStreamObservable[_]] mongoCollection.watch[BsonDocument](clientSession, pipeline) shouldBe a[ChangeStreamObservable[_]] + + verify(wrapped).watch(classOf[Document]) + verify(wrapped).watch(classOf[BsonDocument]) + verify(wrapped).watch(pipeline.asJava, classOf[Document]) + verify(wrapped).watch(pipeline.asJava, classOf[BsonDocument]) + verify(wrapped).watch(clientSession, classOf[Document]) + verify(wrapped).watch(clientSession, classOf[BsonDocument]) + verify(wrapped).watch(clientSession, pipeline.asJava, classOf[Document]) + verify(wrapped).watch(clientSession, pipeline.asJava, classOf[BsonDocument]) } } diff --git a/driver-scala/src/test/scala/org/mongodb/scala/MongoDatabaseSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/MongoDatabaseSpec.scala index 190d311d514..928dd354680 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/MongoDatabaseSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/MongoDatabaseSpec.scala @@ -22,12 +22,12 @@ import org.bson.BsonDocument import org.bson.codecs.BsonValueCodecProvider import org.bson.codecs.configuration.CodecRegistries.fromProviders import com.mongodb.reactivestreams.client.{ ListCollectionsPublisher, MongoDatabase => JMongoDatabase } - +import org.mockito.Mockito.{ verify, when } import org.mongodb.scala.bson.conversions.Bson import org.mongodb.scala.model._ -import org.scalamock.scalatest.proxy.MockFactory +import org.scalatestplus.mockito.MockitoSugar -class MongoDatabaseSpec extends BaseSpec with MockFactory { +class MongoDatabaseSpec extends BaseSpec with MockitoSugar { val wrapped = mock[JMongoDatabase] val clientSession = mock[ClientSession] @@ -47,125 +47,117 @@ class MongoDatabaseSpec extends BaseSpec with MockFactory { } it should "return the underlying getCollection[T]" in { - wrapped.expects(Symbol("getCollection"))("collectionName", classOf[Document]).once() - wrapped.expects(Symbol("getCollection"))("collectionName", classOf[BsonDocument]).once() - mongoDatabase.getCollection("collectionName") mongoDatabase.getCollection[BsonDocument]("collectionName") + + verify(wrapped).getCollection("collectionName", classOf[Document]) + verify(wrapped).getCollection("collectionName", classOf[BsonDocument]) } it should "return the underlying getName" in { - wrapped.expects(Symbol("getName"))().once() - mongoDatabase.name + + verify(wrapped).getName } it should "return the underlying getCodecRegistry" in { - wrapped.expects(Symbol("getCodecRegistry"))().once() - mongoDatabase.codecRegistry + + verify(wrapped).getCodecRegistry } it should "return the underlying getReadPreference" in { - wrapped.expects(Symbol("getReadPreference"))().once() - mongoDatabase.readPreference + + verify(wrapped).getReadPreference } it should "return the underlying getWriteConcern" in { - wrapped.expects(Symbol("getWriteConcern"))().once() - mongoDatabase.writeConcern + + verify(wrapped).getWriteConcern } it should "return the underlying getReadConcern" in { - wrapped.expects(Symbol("getReadConcern"))().once() - mongoDatabase.readConcern + + verify(wrapped).getReadConcern } it should "return the underlying withCodecRegistry" in { val codecRegistry = fromProviders(new BsonValueCodecProvider()) - wrapped.expects(Symbol("withCodecRegistry"))(codecRegistry).once() - mongoDatabase.withCodecRegistry(codecRegistry) + + verify(wrapped).withCodecRegistry(codecRegistry) } it should "return the underlying withReadPreference" in { - wrapped.expects(Symbol("withReadPreference"))(readPreference).once() - mongoDatabase.withReadPreference(readPreference) + + verify(wrapped).withReadPreference(readPreference) } it should "return the underlying withWriteConcern" in { val writeConcern = WriteConcern.MAJORITY - wrapped.expects(Symbol("withWriteConcern"))(writeConcern).once() - mongoDatabase.withWriteConcern(writeConcern) + + verify(wrapped).withWriteConcern(writeConcern) } it should "return the underlying withReadConcern" in { val readConcern = ReadConcern.MAJORITY - wrapped.expects(Symbol("withReadConcern"))(readConcern).once() - mongoDatabase.withReadConcern(readConcern) + + verify(wrapped).withReadConcern(readConcern) } it should "call the underlying runCommand[T] when writing" in { - wrapped.expects(Symbol("runCommand"))(command, classOf[Document]).once() - wrapped.expects(Symbol("runCommand"))(command, classOf[BsonDocument]).once() - wrapped.expects(Symbol("runCommand"))(clientSession, command, classOf[Document]).once() - wrapped.expects(Symbol("runCommand"))(clientSession, command, classOf[BsonDocument]).once() - mongoDatabase.runCommand(command) mongoDatabase.runCommand[BsonDocument](command) mongoDatabase.runCommand(clientSession, command) mongoDatabase.runCommand[BsonDocument](clientSession, command) + + verify(wrapped).runCommand(command, classOf[Document]) + verify(wrapped).runCommand(command, classOf[BsonDocument]) + verify(wrapped).runCommand(clientSession, command, classOf[Document]) + verify(wrapped).runCommand(clientSession, command, classOf[BsonDocument]) } it should "call the underlying runCommand[T] when reading" in { - wrapped.expects(Symbol("runCommand"))(command, readPreference, classOf[Document]).once() - wrapped.expects(Symbol("runCommand"))(command, readPreference, classOf[BsonDocument]).once() - wrapped.expects(Symbol("runCommand"))(clientSession, command, readPreference, classOf[Document]).once() - wrapped.expects(Symbol("runCommand"))(clientSession, command, readPreference, classOf[BsonDocument]).once() - mongoDatabase.runCommand(command, readPreference) mongoDatabase.runCommand[BsonDocument](command, readPreference) mongoDatabase.runCommand(clientSession, command, readPreference) mongoDatabase.runCommand[BsonDocument](clientSession, command, readPreference) + + verify(wrapped).runCommand(command, readPreference, classOf[Document]) + verify(wrapped).runCommand(command, readPreference, classOf[BsonDocument]) + verify(wrapped).runCommand(clientSession, command, readPreference, classOf[Document]) + verify(wrapped).runCommand(clientSession, command, readPreference, classOf[BsonDocument]) } it should "call the underlying drop()" in { - wrapped.expects(Symbol("drop"))().once() - wrapped.expects(Symbol("drop"))(clientSession).once() - mongoDatabase.drop() mongoDatabase.drop(clientSession) + + verify(wrapped).drop() + verify(wrapped).drop(clientSession) } it should "call the underlying listCollectionNames()" in { - wrapped.expects(Symbol("listCollectionNames"))().once() - wrapped.expects(Symbol("listCollectionNames"))(clientSession).once() - mongoDatabase.listCollectionNames() mongoDatabase.listCollectionNames(clientSession) + + verify(wrapped).listCollectionNames() + verify(wrapped).listCollectionNames(clientSession) } it should "call the underlying listCollections()" in { - wrapped.expects(Symbol("listCollections"))(*).returns(stub[ListCollectionsPublisher[Document]]).once() - wrapped - .expects(Symbol("listCollections"))(classOf[BsonDocument]) - .returns(stub[ListCollectionsPublisher[BsonDocument]]) - .once() - wrapped - .expects(Symbol("listCollections"))(clientSession, *) - .returns(stub[ListCollectionsPublisher[Document]]) - .once() - wrapped - .expects(Symbol("listCollections"))(clientSession, classOf[BsonDocument]) - .returns(stub[ListCollectionsPublisher[BsonDocument]]) - .once() + when(wrapped.listCollections()).thenReturn(mock[ListCollectionsPublisher[org.bson.Document]]) + when(wrapped.listCollections(classOf[BsonDocument])).thenReturn(mock[ListCollectionsPublisher[BsonDocument]]) + when(wrapped.listCollections(clientSession)).thenReturn(mock[ListCollectionsPublisher[org.bson.Document]]) + when(wrapped.listCollections(clientSession, classOf[BsonDocument])) + .thenReturn(mock[ListCollectionsPublisher[BsonDocument]]) mongoDatabase.listCollections() mongoDatabase.listCollections[BsonDocument]() @@ -185,58 +177,59 @@ class MongoDatabaseSpec extends BaseSpec with MockFactory { .indexOptionDefaults(IndexOptionDefaults().storageEngine(Document("""{storageEngine: { mmapv1: {}}}"""))) .storageEngineOptions(Document("""{ wiredTiger: {}}""")) - wrapped.expects(Symbol("createCollection"))("collectionName").once() - wrapped.expects(Symbol("createCollection"))("collectionName", options).once() - wrapped.expects(Symbol("createCollection"))(clientSession, "collectionName").once() - wrapped.expects(Symbol("createCollection"))(clientSession, "collectionName", options).once() - mongoDatabase.createCollection("collectionName") mongoDatabase.createCollection("collectionName", options) mongoDatabase.createCollection(clientSession, "collectionName") mongoDatabase.createCollection(clientSession, "collectionName", options) + + verify(wrapped).createCollection("collectionName") + verify(wrapped).createCollection("collectionName", options) + verify(wrapped).createCollection(clientSession, "collectionName") + verify(wrapped).createCollection(clientSession, "collectionName", options) } it should "call the underlying createView()" in { val options = CreateViewOptions().collation(Collation.builder().locale("en").build()) val pipeline = List.empty[Bson] - wrapped.expects(Symbol("createView"))("viewName", "collectionName", pipeline.asJava).once() - wrapped.expects(Symbol("createView"))("viewName", "collectionName", pipeline.asJava, options).once() - wrapped.expects(Symbol("createView"))(clientSession, "viewName", "collectionName", pipeline.asJava).once() - wrapped.expects(Symbol("createView"))(clientSession, "viewName", "collectionName", pipeline.asJava, options).once() - mongoDatabase.createView("viewName", "collectionName", pipeline) mongoDatabase.createView("viewName", "collectionName", pipeline, options) mongoDatabase.createView(clientSession, "viewName", "collectionName", pipeline) mongoDatabase.createView(clientSession, "viewName", "collectionName", pipeline, options) + + verify(wrapped).createView("viewName", "collectionName", pipeline.asJava) + verify(wrapped).createView("viewName", "collectionName", pipeline.asJava, options) + verify(wrapped).createView(clientSession, "viewName", "collectionName", pipeline.asJava) + verify(wrapped).createView(clientSession, "viewName", "collectionName", pipeline.asJava, options) } it should "call the underlying watch" in { val pipeline = List(Document("$match" -> 1)) - wrapped.expects(Symbol("watch"))(classOf[Document]).once() - wrapped.expects(Symbol("watch"))(pipeline.asJava, classOf[Document]).once() - wrapped.expects(Symbol("watch"))(pipeline.asJava, classOf[BsonDocument]).once() - wrapped.expects(Symbol("watch"))(clientSession, pipeline.asJava, classOf[Document]).once() - wrapped.expects(Symbol("watch"))(clientSession, pipeline.asJava, classOf[BsonDocument]).once() - mongoDatabase.watch() shouldBe a[ChangeStreamObservable[_]] mongoDatabase.watch(pipeline) shouldBe a[ChangeStreamObservable[_]] mongoDatabase.watch[BsonDocument](pipeline) shouldBe a[ChangeStreamObservable[_]] mongoDatabase.watch(clientSession, pipeline) shouldBe a[ChangeStreamObservable[_]] mongoDatabase.watch[BsonDocument](clientSession, pipeline) shouldBe a[ChangeStreamObservable[_]] + + verify(wrapped).watch(classOf[Document]) + verify(wrapped).watch(pipeline.asJava, classOf[Document]) + verify(wrapped).watch(pipeline.asJava, classOf[BsonDocument]) + verify(wrapped).watch(clientSession, pipeline.asJava, classOf[Document]) + verify(wrapped).watch(clientSession, pipeline.asJava, classOf[BsonDocument]) } it should "call the underlying aggregate" in { val pipeline = List(Document("$match" -> 1)) - wrapped.expects(Symbol("aggregate"))(pipeline.asJava, classOf[Document]).once() - wrapped.expects(Symbol("aggregate"))(pipeline.asJava, classOf[BsonDocument]).once() - wrapped.expects(Symbol("aggregate"))(clientSession, pipeline.asJava, classOf[Document]).once() - wrapped.expects(Symbol("aggregate"))(clientSession, pipeline.asJava, classOf[BsonDocument]).once() mongoDatabase.aggregate(pipeline) shouldBe a[AggregateObservable[_]] mongoDatabase.aggregate[BsonDocument](pipeline) shouldBe a[AggregateObservable[_]] mongoDatabase.aggregate(clientSession, pipeline) shouldBe a[AggregateObservable[_]] mongoDatabase.aggregate[BsonDocument](clientSession, pipeline) shouldBe a[AggregateObservable[_]] + + verify(wrapped).aggregate(pipeline.asJava, classOf[Document]) + verify(wrapped).aggregate(pipeline.asJava, classOf[BsonDocument]) + verify(wrapped).aggregate(clientSession, pipeline.asJava, classOf[Document]) + verify(wrapped).aggregate(clientSession, pipeline.asJava, classOf[BsonDocument]) } } diff --git a/driver-scala/src/test/scala/org/mongodb/scala/connection/ConnectionSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/connection/ConnectionSpec.scala index c0575dfc64e..4435b9bc08c 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/connection/ConnectionSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/connection/ConnectionSpec.scala @@ -20,11 +20,11 @@ import java.net.{ InetAddress, InetSocketAddress } import com.mongodb.{ ServerAddress => JServerAddress } import org.mongodb.scala.{ BaseSpec, ServerAddress } -import org.scalamock.scalatest.proxy.MockFactory +import org.scalatestplus.mockito.MockitoSugar import scala.collection.JavaConverters._ -class ConnectionSpec extends BaseSpec with MockFactory { +class ConnectionSpec extends BaseSpec with MockitoSugar { "The connection namespace" should "have a AsynchronousSocketChannelStreamFactoryFactory companion" in { val asynchronousSocketChannelStreamFactoryFactory = AsynchronousSocketChannelStreamFactoryFactory() diff --git a/driver-scala/src/test/scala/org/mongodb/scala/gridfs/GridFSBucketSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/gridfs/GridFSBucketSpec.scala index 50d2dfab9cf..afd28ad7dc6 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/gridfs/GridFSBucketSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/gridfs/GridFSBucketSpec.scala @@ -19,12 +19,13 @@ package org.mongodb.scala.gridfs import java.nio.ByteBuffer import com.mongodb.reactivestreams.client.gridfs.{ GridFSBucket => JGridFSBucket } +import org.mockito.Mockito.{ verify, when } import org.mongodb.scala.bson.BsonObjectId import org.mongodb.scala.bson.collection.immutable.Document import org.mongodb.scala.{ BaseSpec, ClientSession, Observable, ReadConcern, ReadPreference, WriteConcern } -import org.scalamock.scalatest.proxy.MockFactory +import org.scalatestplus.mockito.MockitoSugar -class GridFSBucketSpec extends BaseSpec with MockFactory { +class GridFSBucketSpec extends BaseSpec with MockitoSugar { val wrapper = mock[JGridFSBucket] val clientSession = mock[ClientSession] val gridFSBucket = new GridFSBucket(wrapper) @@ -40,17 +41,17 @@ class GridFSBucketSpec extends BaseSpec with MockFactory { } it should "call the underlying methods to get bucket values" in { - wrapper.expects(Symbol("getBucketName"))().once() - wrapper.expects(Symbol("getChunkSizeBytes"))().returning(1).once() - wrapper.expects(Symbol("getReadConcern"))().once() - wrapper.expects(Symbol("getReadPreference"))().once() - wrapper.expects(Symbol("getWriteConcern"))().once() - gridFSBucket.bucketName gridFSBucket.chunkSizeBytes gridFSBucket.readConcern gridFSBucket.readPreference gridFSBucket.writeConcern + + verify(wrapper).getBucketName + when(wrapper.getChunkSizeBytes).thenReturn(1) + verify(wrapper).getReadConcern + verify(wrapper).getReadPreference + verify(wrapper).getWriteConcern } it should "call the underlying methods to set bucket values" in { @@ -59,38 +60,38 @@ class GridFSBucketSpec extends BaseSpec with MockFactory { val readPreference = ReadPreference.secondaryPreferred() val writeConcern = WriteConcern.W2 - wrapper.expects(Symbol("withChunkSizeBytes"))(chunkSizeInBytes).once() - wrapper.expects(Symbol("withReadConcern"))(readConcern).once() - wrapper.expects(Symbol("withReadPreference"))(readPreference).once() - wrapper.expects(Symbol("withWriteConcern"))(writeConcern).once() - gridFSBucket.withChunkSizeBytes(chunkSizeInBytes) gridFSBucket.withReadConcern(readConcern) gridFSBucket.withReadPreference(readPreference) gridFSBucket.withWriteConcern(writeConcern) + + verify(wrapper).withChunkSizeBytes(chunkSizeInBytes) + verify(wrapper).withReadConcern(readConcern) + verify(wrapper).withReadPreference(readPreference) + verify(wrapper).withWriteConcern(writeConcern) } it should "call the underlying delete method" in { val bsonValue = BsonObjectId() val objectId = bsonValue.getValue - wrapper.expects(Symbol("delete"))(objectId).once() - wrapper.expects(Symbol("delete"))(bsonValue).once() - wrapper.expects(Symbol("delete"))(clientSession, objectId).once() - wrapper.expects(Symbol("delete"))(clientSession, bsonValue).once() - gridFSBucket.delete(objectId) gridFSBucket.delete(bsonValue) gridFSBucket.delete(clientSession, objectId) gridFSBucket.delete(clientSession, bsonValue) + + verify(wrapper).delete(objectId) + verify(wrapper).delete(bsonValue) + verify(wrapper).delete(clientSession, objectId) + verify(wrapper).delete(clientSession, bsonValue) } it should "call the underlying drop method" in { - wrapper.expects(Symbol("drop"))().once() - wrapper.expects(Symbol("drop"))(clientSession).once() - gridFSBucket.drop() gridFSBucket.drop(clientSession) + + verify(wrapper).drop() + verify(wrapper).drop(clientSession) } it should "call the underlying rename method" in { @@ -98,29 +99,29 @@ class GridFSBucketSpec extends BaseSpec with MockFactory { val objectId = bsonValue.getValue val newName = "newName" - wrapper.expects(Symbol("rename"))(objectId, newName).once() - wrapper.expects(Symbol("rename"))(bsonValue, newName).once() - wrapper.expects(Symbol("rename"))(clientSession, objectId, newName).once() - wrapper.expects(Symbol("rename"))(clientSession, bsonValue, newName).once() - gridFSBucket.rename(objectId, newName) gridFSBucket.rename(bsonValue, newName) gridFSBucket.rename(clientSession, objectId, newName) gridFSBucket.rename(clientSession, bsonValue, newName) + + verify(wrapper).rename(objectId, newName) + verify(wrapper).rename(bsonValue, newName) + verify(wrapper).rename(clientSession, objectId, newName) + verify(wrapper).rename(clientSession, bsonValue, newName) } it should "return the expected findObservable" in { val filter = Document("{a: 1}") - wrapper.expects(Symbol("find"))().once() - wrapper.expects(Symbol("find"))(filter).once() - wrapper.expects(Symbol("find"))(clientSession).once() - wrapper.expects(Symbol("find"))(clientSession, filter).once() - gridFSBucket.find() gridFSBucket.find(filter) gridFSBucket.find(clientSession) gridFSBucket.find(clientSession, filter) + + verify(wrapper).find() + verify(wrapper).find(filter) + verify(wrapper).find(clientSession) + verify(wrapper).find(clientSession, filter) } it should "return the expected GridFSDownloadObservable" in { @@ -130,26 +131,26 @@ class GridFSBucketSpec extends BaseSpec with MockFactory { val options = new GridFSDownloadOptions() val clientSession = mock[ClientSession] - wrapper.expects(Symbol("downloadToPublisher"))(objectId).once() - wrapper.expects(Symbol("downloadToPublisher"))(bsonValue).once() - wrapper.expects(Symbol("downloadToPublisher"))(fileName).once() - wrapper.expects(Symbol("downloadToPublisher"))(fileName, options).once() - gridFSBucket.downloadToObservable(objectId) gridFSBucket.downloadToObservable(bsonValue) gridFSBucket.downloadToObservable(fileName) gridFSBucket.downloadToObservable(fileName, options) - wrapper.expects(Symbol("downloadToPublisher"))(clientSession, objectId).once() - wrapper.expects(Symbol("downloadToPublisher"))(clientSession, bsonValue).once() - wrapper.expects(Symbol("downloadToPublisher"))(clientSession, fileName).once() - wrapper.expects(Symbol("downloadToPublisher"))(clientSession, fileName, options).once() + verify(wrapper).downloadToPublisher(objectId) + verify(wrapper).downloadToPublisher(bsonValue) + verify(wrapper).downloadToPublisher(fileName) + verify(wrapper).downloadToPublisher(fileName, options) gridFSBucket.downloadToObservable(clientSession, objectId) gridFSBucket.downloadToObservable(clientSession, bsonValue) gridFSBucket.downloadToObservable(clientSession, fileName) gridFSBucket.downloadToObservable(clientSession, fileName, options) + verify(wrapper).downloadToPublisher(clientSession, objectId) + verify(wrapper).downloadToPublisher(clientSession, bsonValue) + verify(wrapper).downloadToPublisher(clientSession, fileName) + verify(wrapper).downloadToPublisher(clientSession, fileName, options) + } it should "return the expected GridFSUploadObservable" in { @@ -159,25 +160,25 @@ class GridFSBucketSpec extends BaseSpec with MockFactory { val options = new GridFSUploadOptions() val clientSession = mock[ClientSession] - wrapper.expects(Symbol("uploadFromPublisher"))(fileName, publisher).once() - wrapper.expects(Symbol("uploadFromPublisher"))(fileName, publisher, options).once() - wrapper.expects(Symbol("uploadFromPublisher"))(bsonValue, fileName, publisher).once() - wrapper.expects(Symbol("uploadFromPublisher"))(bsonValue, fileName, publisher, options).once() - gridFSBucket.uploadFromObservable(fileName, publisher) gridFSBucket.uploadFromObservable(fileName, publisher, options) gridFSBucket.uploadFromObservable(bsonValue, fileName, publisher) gridFSBucket.uploadFromObservable(bsonValue, fileName, publisher, options) - wrapper.expects(Symbol("uploadFromPublisher"))(clientSession, fileName, publisher).once() - wrapper.expects(Symbol("uploadFromPublisher"))(clientSession, fileName, publisher, options).once() - wrapper.expects(Symbol("uploadFromPublisher"))(clientSession, bsonValue, fileName, publisher).once() - wrapper.expects(Symbol("uploadFromPublisher"))(clientSession, bsonValue, fileName, publisher, options).once() + verify(wrapper).uploadFromPublisher(fileName, publisher) + verify(wrapper).uploadFromPublisher(fileName, publisher, options) + verify(wrapper).uploadFromPublisher(bsonValue, fileName, publisher) + verify(wrapper).uploadFromPublisher(bsonValue, fileName, publisher, options) gridFSBucket.uploadFromObservable(clientSession, fileName, publisher) gridFSBucket.uploadFromObservable(clientSession, fileName, publisher, options) gridFSBucket.uploadFromObservable(clientSession, bsonValue, fileName, publisher) gridFSBucket.uploadFromObservable(clientSession, bsonValue, fileName, publisher, options) + + verify(wrapper).uploadFromPublisher(clientSession, fileName, publisher) + verify(wrapper).uploadFromPublisher(clientSession, fileName, publisher, options) + verify(wrapper).uploadFromPublisher(clientSession, bsonValue, fileName, publisher) + verify(wrapper).uploadFromPublisher(clientSession, bsonValue, fileName, publisher, options) } } diff --git a/driver-scala/src/test/scala/org/mongodb/scala/gridfs/GridFSDownloadObservableSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/gridfs/GridFSDownloadObservableSpec.scala index 982499dc0ca..f98e10b75d2 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/gridfs/GridFSDownloadObservableSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/gridfs/GridFSDownloadObservableSpec.scala @@ -17,10 +17,11 @@ package org.mongodb.scala.gridfs import com.mongodb.reactivestreams.client.gridfs.GridFSDownloadPublisher +import org.mockito.Mockito.verify import org.mongodb.scala.BaseSpec -import org.scalamock.scalatest.proxy.MockFactory +import org.scalatestplus.mockito.MockitoSugar -class GridFSDownloadObservableSpec extends BaseSpec with MockFactory { +class GridFSDownloadObservableSpec extends BaseSpec with MockitoSugar { val wrapper = mock[GridFSDownloadPublisher] val gridFSDownloadStream = GridFSDownloadObservable(wrapper) @@ -37,11 +38,11 @@ class GridFSDownloadObservableSpec extends BaseSpec with MockFactory { it should "call the underlying methods" in { val bufferSizeBytes = 1024 - wrapper.expects(Symbol("bufferSizeBytes"))(bufferSizeBytes).once() - wrapper.expects(Symbol("getGridFSFile"))().once() - gridFSDownloadStream.bufferSizeBytes(bufferSizeBytes) gridFSDownloadStream.gridFSFile() + + verify(wrapper).bufferSizeBytes(bufferSizeBytes) + verify(wrapper).getGridFSFile } } diff --git a/driver-scala/src/test/scala/org/mongodb/scala/gridfs/GridFSFindObservableSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/gridfs/GridFSFindObservableSpec.scala index 3ea198dc157..5388fe20178 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/gridfs/GridFSFindObservableSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/gridfs/GridFSFindObservableSpec.scala @@ -19,13 +19,14 @@ package org.mongodb.scala.gridfs import java.util.concurrent.TimeUnit import com.mongodb.reactivestreams.client.gridfs.GridFSFindPublisher +import org.mockito.Mockito.verify import org.mongodb.scala.{ BaseSpec, Document } import org.reactivestreams.Publisher -import org.scalamock.scalatest.proxy.MockFactory +import org.scalatestplus.mockito.MockitoSugar import scala.concurrent.duration.Duration -class GridFSFindObservableSpec extends BaseSpec with MockFactory { +class GridFSFindObservableSpec extends BaseSpec with MockitoSugar { val wrapper = mock[GridFSFindPublisher] val gridFSFindObservable = GridFSFindObservable(wrapper) @@ -48,14 +49,6 @@ class GridFSFindObservableSpec extends BaseSpec with MockFactory { val skip = 5 val sort = Document("{_id: 1}") - wrapper.expects(Symbol("batchSize"))(batchSize).once() - wrapper.expects(Symbol("filter"))(filter).once() - wrapper.expects(Symbol("limit"))(limit).once() - wrapper.expects(Symbol("maxTime"))(maxTime.toMillis, TimeUnit.MILLISECONDS).once() - wrapper.expects(Symbol("noCursorTimeout"))(true).once() - wrapper.expects(Symbol("skip"))(skip).once() - wrapper.expects(Symbol("sort"))(sort).once() - gridFSFindObservable.batchSize(batchSize) gridFSFindObservable.filter(filter) gridFSFindObservable.limit(limit) @@ -63,6 +56,14 @@ class GridFSFindObservableSpec extends BaseSpec with MockFactory { gridFSFindObservable.noCursorTimeout(true) gridFSFindObservable.skip(skip) gridFSFindObservable.sort(sort) + + verify(wrapper).batchSize(batchSize) + verify(wrapper).filter(filter) + verify(wrapper).limit(limit) + verify(wrapper).maxTime(maxTime.toMillis, TimeUnit.MILLISECONDS) + verify(wrapper).noCursorTimeout(true) + verify(wrapper).skip(skip) + verify(wrapper).sort(sort) } } diff --git a/driver-scala/src/test/scala/org/mongodb/scala/gridfs/GridFSUploadPublisherSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/gridfs/GridFSUploadPublisherSpec.scala index e7dd9d77d9e..728b10150bf 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/gridfs/GridFSUploadPublisherSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/gridfs/GridFSUploadPublisherSpec.scala @@ -17,10 +17,11 @@ package org.mongodb.scala.gridfs import com.mongodb.reactivestreams.client.gridfs.GridFSUploadPublisher +import org.mockito.Mockito.verify import org.mongodb.scala.BaseSpec -import org.scalamock.scalatest.proxy.MockFactory +import org.scalatestplus.mockito.MockitoSugar -class GridFSUploadPublisherSpec extends BaseSpec with MockFactory { +class GridFSUploadPublisherSpec extends BaseSpec with MockitoSugar { val wrapper = mock[GridFSUploadPublisher[Void]] val gridFSUploadObservable = GridFSUploadObservable(wrapper) @@ -36,11 +37,11 @@ class GridFSUploadPublisherSpec extends BaseSpec with MockFactory { it should "call the underlying methods" in { - wrapper.expects(Symbol("getObjectId"))().once() - wrapper.expects(Symbol("getId"))().once() - gridFSUploadObservable.objectId gridFSUploadObservable.id + + verify(wrapper).getObjectId + verify(wrapper).getId } } diff --git a/driver-scala/src/test/scala/org/mongodb/scala/model/vault/ClientEncryptionSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/model/vault/ClientEncryptionSpec.scala index 602c42e21cf..03a11618807 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/model/vault/ClientEncryptionSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/model/vault/ClientEncryptionSpec.scala @@ -19,12 +19,14 @@ package org.mongodb.scala.model.vault import java.lang.reflect.Modifier.{ isPublic, isStatic } import com.mongodb.reactivestreams.client.vault.{ ClientEncryption => JClientEncryption } +import org.mockito.ArgumentMatchers.{ any, same } +import org.mockito.Mockito.verify import org.mongodb.scala.BaseSpec import org.mongodb.scala.bson.{ BsonBinary, BsonString } import org.mongodb.scala.vault.ClientEncryption -import org.scalamock.scalatest.proxy.MockFactory +import org.scalatestplus.mockito.MockitoSugar -class ClientEncryptionSpec extends BaseSpec with MockFactory { +class ClientEncryptionSpec extends BaseSpec with MockitoSugar { val wrapped = mock[JClientEncryption] val clientEncryption = ClientEncryption(wrapped) @@ -47,26 +49,26 @@ class ClientEncryptionSpec extends BaseSpec with MockFactory { val kmsProvider = "kmsProvider" val options = DataKeyOptions() - wrapped.expects(Symbol("createDataKey"))(kmsProvider, *).once() clientEncryption.createDataKey(kmsProvider) + verify(wrapped).createDataKey(same(kmsProvider), any()) - wrapped.expects(Symbol("createDataKey"))(kmsProvider, options).once() clientEncryption.createDataKey(kmsProvider, options) + verify(wrapped).createDataKey(kmsProvider, options) } it should "call encrypt" in { val bsonValue = BsonString("") val options = EncryptOptions("algorithm") - wrapped.expects(Symbol("encrypt"))(bsonValue, options).once() - clientEncryption.encrypt(bsonValue, options) + + verify(wrapped).encrypt(bsonValue, options) } it should "call decrypt" in { val bsonBinary = BsonBinary(Array[Byte](1, 2, 3)) - wrapped.expects(Symbol("decrypt"))(bsonBinary).once() - clientEncryption.decrypt(bsonBinary) + + verify(wrapped).decrypt(bsonBinary) } }