Skip to content

Commit

Permalink
Scala use mockito instead of scalamock
Browse files Browse the repository at this point in the history
scalamock does not support scala3 paulbutcher/ScalaMock#429

JAVA-4181
  • Loading branch information
jtjeferreira authored and rozza committed Apr 12, 2022
1 parent 8977afa commit 7a0b575
Show file tree
Hide file tree
Showing 19 changed files with 467 additions and 447 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
Loading

0 comments on commit 7a0b575

Please sign in to comment.