Skip to content

Commit

Permalink
WIP ->> scala3: Move to scalatestplus-mockito
Browse files Browse the repository at this point in the history
Since `mockito-scala` seems to be non-active, lets try another mockito
wrapper.

Source: mockito/mockito-scala#364 (comment)
  • Loading branch information
jnatten committed Feb 22, 2023
1 parent 54f5107 commit 5925618
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import no.ndla.network.NdlaClient
import no.ndla.network.clients.{FeideApiClient, RedisClient}
import no.ndla.network.scalatra.{NdlaControllerBase, NdlaSwaggerSupport}
import no.ndla.search.{BaseIndexService, Elastic4sClient, NdlaE4sClient}
import org.mockito.scalatest.MockitoSugar
import org.scalatestplus.mockito.MockitoSugar

trait TestEnvironment
extends Elastic4sClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import no.ndla.oembedproxy.caching.MemoizeHelpers
import no.ndla.oembedproxy.controller.{HealthController, OEmbedProxyController}
import no.ndla.oembedproxy.model.ErrorHelpers
import no.ndla.oembedproxy.service.{OEmbedServiceComponent, ProviderService}
import org.mockito.scalatest.MockitoSugar
import org.mockito.Mockito.reset
import org.scalatestplus.mockito.MockitoSugar

trait TestEnvironment
extends OEmbedProxyController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

package no.ndla.oembedproxy

import org.mockito.scalatest.MockitoSugar
import org.scalatest._
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import org.scalatestplus.mockito.MockitoSugar

abstract class UnitSuite
extends AnyFunSuite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package no.ndla.oembedproxy.caching

import no.ndla.oembedproxy.UnitSuite
import no.ndla.oembedproxy.model.DoNotUpdateMemoizeException
import org.mockito.Mockito._

class MemoizeTest extends UnitSuite {

Expand Down Expand Up @@ -62,7 +63,7 @@ class MemoizeTest extends UnitSuite {

when(targetMock.targetMethod())
.thenReturn("Hello from mock")
.andThenThrow(new DoNotUpdateMemoizeException("Woop"))
.thenThrow(new DoNotUpdateMemoizeException("Woop"))

memoizedTarget() should equal("Hello from mock")
Thread.sleep(cacheMaxAgeInMs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ package no.ndla.oembedproxy.controller
import no.ndla.network.model.HttpRequestException
import no.ndla.oembedproxy.model.OEmbed
import no.ndla.oembedproxy.{TestEnvironment, UnitSuite}
import org.mockito.ArgumentMatchers.anyString
import org.mockito.ArgumentMatchers.{any, anyString}
import org.mockito.Mockito.when
import org.scalatra.test.scalatest.ScalatraFunSuite

import scala.util.{Failure, Success}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import no.ndla.network.model.{HttpRequestException, NdlaRequest}
import no.ndla.oembedproxy.caching.Memoize
import no.ndla.oembedproxy.model._
import no.ndla.oembedproxy.{TestEnvironment, UnitSuite}
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito._
import org.scalatest.TryValues._

import scala.util.{Failure, Success}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ package no.ndla.oembedproxy.service
import no.ndla.network.model.{HttpRequestException, NdlaRequest}
import no.ndla.oembedproxy.model._
import no.ndla.oembedproxy.{TestEnvironment, UnitSuite}
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
import sttp.client3.quick._

import scala.util.{Failure, Success}
Expand Down
16 changes: 8 additions & 8 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ object Dependencies {
hikari
)

private lazy val scalaTestAndMockitoBase: Seq[ModuleID] = Seq(
"org.scalatest" %% "scalatest" % ScalaTestV,
"org.mockito" %% "mockito-scala" % MockitoV,
"org.mockito" %% "mockito-scala-scalatest" % MockitoV
)

/** This should only be used if we want to include scalatest and mockito in the main build (not only tests).
* Otherwise use [[scalaTestAndMockito]]
*/
lazy val scalaTestAndMockitoInMain = scalaTestAndMockitoBase.map(_ cross CrossVersion.for3Use2_13)
lazy val scalaTestAndMockitoInMain = Seq(
"org.scalatest" %% "scalatest" % ScalaTestV,
"org.scalatestplus" %% "mockito-4-6" % "3.2.15.0"
)

lazy val scalaTestAndMockito = scalaTestAndMockitoInMain.map(_ % "test" cross CrossVersion.for3Use2_13)
lazy val scalaTestAndMockito = Seq(
"org.scalatest" %% "scalatest" % ScalaTestV % "test",
"org.scalatestplus" %% "mockito-4-6" % "3.2.15.0" % "test"
)

lazy val scalaTsi = "com.scalatsi" %% "scala-tsi" % ScalaTsiV

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

package no.ndla.scalatestsuite

import org.mockito.scalatest.MockitoSugar
import org.scalatest._
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import org.scalatestplus.mockito.MockitoSugar

import java.io.IOException
import java.net.ServerSocket
import scala.util.Properties.{propOrNone, setProp}
import scala.util.{Try, Success, Failure}
import scala.util.{Failure, Success, Try}

abstract class UnitTestSuite
extends AnyFunSuite
Expand Down

0 comments on commit 5925618

Please sign in to comment.