Skip to content

Commit 5ee3638

Browse files
committed
Decrease usage of deprecated elements
1 parent 3c4beb0 commit 5ee3638

File tree

9 files changed

+21
-20
lines changed

9 files changed

+21
-20
lines changed

build.sbt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import scala.io.Source
21
import scala.language.postfixOps
3-
import sbt.io.Using
42

53
val currentScalaVersion = "2.13.16"
64

@@ -48,7 +46,8 @@ lazy val commonSettings =
4846
case _ =>
4947
Seq("org.scala-lang.modules" %% "scala-parallel-collections" % "1.2.0")
5048
}
51-
}
49+
},
50+
libraryDependencies += "org.scala-lang.modules" %% "scala-collection-compat" % "2.13.0"
5251
)
5352

5453
lazy val publishSettings = Seq(
@@ -154,8 +153,6 @@ lazy val core = (project in file("core"))
154153
name := "mockito-scala",
155154
libraryDependencies ++= Dependencies.commonLibraries,
156155
libraryDependencies ++= Dependencies.scalaReflection.value,
157-
// TODO remove when we remove the deprecated classes in org.mockito.integrations.Dependencies.scalatest
158-
libraryDependencies += Dependencies.scalatest % "provided",
159156
// include the macro classes and resources in the main jar
160157
Compile / packageBin / mappings ++= (macroSub / Compile / packageBin / mappings).value,
161158
// include the macro sources in the main source jar

common/src/main/scala/org/mockito/MockitoAPI.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ import org.mockito.internal.util.reflection.LenientCopyTool
2424
import org.mockito.internal.{ ValueClassExtractor, ValueClassWrapper }
2525
import org.mockito.invocation.{ Invocation, InvocationContainer, InvocationOnMock, MockHandler }
2626
import org.mockito.mock.MockCreationSettings
27+
import org.mockito.quality.Strictness
2728
import org.mockito.stubbing._
2829
import org.mockito.verification.{ VerificationAfterDelay, VerificationMode, VerificationWithTimeout }
2930
import org.scalactic.{ Equality, Prettifier }
30-
import scala.collection.JavaConverters._
31+
32+
import scala.jdk.CollectionConverters._
3133
import scala.reflect.ClassTag
3234
import scala.reflect.runtime.universe.WeakTypeTag
3335

@@ -543,7 +545,7 @@ private[mockito] trait MockitoEnhancer extends MockCreator {
543545

544546
def spy[T <: AnyRef: ClassTag: WeakTypeTag](realObj: T, lenient: Boolean = false)(implicit $pt: Prettifier): T = {
545547
def mockSettings: MockSettings = Mockito.withSettings().defaultAnswer(CALLS_REAL_METHODS).spiedInstance(realObj)
546-
val settings = if (lenient) mockSettings.lenient() else mockSettings
548+
val settings = if (lenient) mockSettings.strictness(Strictness.LENIENT) else mockSettings
547549
mock[T](settings)
548550
}
549551

@@ -645,7 +647,7 @@ object LeniencySettings {
645647
}
646648

647649
val lenientStubs: LeniencySettings = new LeniencySettings {
648-
override def apply(settings: MockSettings): MockSettings = settings.lenient()
650+
override def apply(settings: MockSettings): MockSettings = settings.strictness(Strictness.LENIENT)
649651
}
650652
}
651653

common/src/main/scala/org/mockito/ReflectionUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ object ReflectionUtils {
133133
case Failure(e) =>
134134
uTry {
135135
val getDeclaredFields0 = clazz.getDeclaredMethod("getDeclaredFields0", classOf[Boolean])
136-
val accessibleBeforeSet: Boolean = getDeclaredFields0.isAccessible
136+
val accessibleBeforeSet: Boolean = getDeclaredFields0.canAccess(null)
137137
getDeclaredFields0.setAccessible(true)
138138
val declaredFields: Array[Field] = getDeclaredFields0
139139
.invoke(classOf[Field], java.lang.Boolean.FALSE)

common/src/main/scala/org/mockito/internal/handler/ScalaMockHandler.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import org.mockito.mock.MockCreationSettings
1414
import org.scalactic.Prettifier
1515
import org.scalactic.TripleEquals._
1616

17-
import scala.collection.JavaConverters._
17+
import scala.collection.compat._
18+
import scala.jdk.CollectionConverters._
1819

1920
class ScalaMockHandler[T](mockSettings: MockCreationSettings[T], methodsToProcess: Seq[(Method, Set[Int])])(implicit $pt: Prettifier) extends MockHandlerImpl[T](mockSettings) {
2021
override def handle(invocation: Invocation): AnyRef =
@@ -43,17 +44,17 @@ class ScalaMockHandler[T](mockSettings: MockCreationSettings[T], methodsToProces
4344
.collectFirst {
4445
case (mtd, indices) if method === mtd =>
4546
val argumentMatcherStorage = mockingProgress().getArgumentMatcherStorage
46-
val matchers = argumentMatcherStorage.pullLocalizedMatchers().asScala.toIterator
47+
val matchers = argumentMatcherStorage.pullLocalizedMatchers().asScala.iterator
4748
val matchersWereUsed = matchers.nonEmpty
4849
def reportMatcher(): Unit = if (matchers.nonEmpty) argumentMatcherStorage.reportMatcher(matchers.next().getMatcher)
4950
def reportMatchers(varargs: Iterable[_]): Unit =
5051
if (matchersWereUsed && varargs.nonEmpty) {
5152
def reportAsEqTo(): Unit = varargs.map(EqTo(_)).foreach(argumentMatcherStorage.reportMatcher(_))
5253
val matcher = matchers.next().getMatcher
5354
matcher match {
54-
case EqTo(value: Array[_]) if varargs.sameElements(value) => reportAsEqTo()
55-
case EqTo(value) if varargs == value => reportAsEqTo()
56-
case other =>
55+
case EqTo(value: Array[_]) if varargs.iterator.sameElements(value.iterator) => reportAsEqTo()
56+
case EqTo(value) if varargs == value => reportAsEqTo()
57+
case other =>
5758
argumentMatcherStorage.reportMatcher(other)
5859
varargs.drop(1).foreach(_ => reportMatcher())
5960
}

common/src/main/scala/org/mockito/internal/invocation/ScalaInvocation.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import org.mockito.invocation.{ Invocation, Location, StubInfo }
1313
import org.mockito.matchers.EqTo
1414
import org.scalactic.Prettifier
1515

16-
import scala.collection.JavaConverters._
16+
import scala.jdk.CollectionConverters._
1717

1818
class ScalaInvocation(
1919
val mockRef: MockReference[AnyRef],

common/src/main/scala/org/mockito/stubbing/ReturnsSmartNulls.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.mockito.internal.exceptions.Reporter.smartNullPointerException
77
import org.mockito.internal.stubbing.defaultanswers.ReturnsMoreEmptyValues
88
import org.mockito.internal.util.ObjectMethodsGuru.isToStringMethod
99
import org.mockito.invocation.{ InvocationOnMock, Location }
10+
import org.mockito.quality.Strictness
1011

1112
object ReturnsSmartNulls extends DefaultAnswer {
1213
val delegate = new ReturnsMoreEmptyValues
@@ -16,7 +17,7 @@ object ReturnsSmartNulls extends DefaultAnswer {
1617
val returnType = invocation.returnType
1718

1819
if (!returnType.isPrimitive && !isFinal(returnType.getModifiers) && classOf[Object] != returnType)
19-
Some(mock(returnType, withSettings.defaultAnswer(ThrowsSmartNullPointer(invocation)).lenient()))
20+
Some(mock(returnType, withSettings.defaultAnswer(ThrowsSmartNullPointer(invocation)).strictness(Strictness.LENIENT)))
2021
else
2122
None
2223
}

core/src/main/scala/org/mockito/MockitoScalaSession.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.mockito.session.MockitoSessionLogger
1111
import org.scalactic.Equality
1212
import org.scalactic.TripleEquals._
1313

14-
import scala.collection.JavaConverters._
14+
import scala.jdk.CollectionConverters._
1515
import scala.collection.mutable
1616

1717
class MockitoScalaSession(name: String, strictness: Strictness, logger: MockitoSessionLogger) {

macro/src/main/scala/org/mockito/captor/Captor.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import org.mockito.{ clazz, ArgumentCaptor }
99
import org.scalactic.Equality
1010
import org.scalactic.TripleEquals._
1111

12-
import scala.collection.JavaConverters._
12+
import scala.jdk.CollectionConverters._
1313
import scala.reflect.ClassTag
1414
import scala.reflect.macros.blackbox
1515
import scala.util.{ Failure, Try }

scalatest/src/main/scala/org/mockito/scalatest/ResetMocksAfterEachTestBase.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import org.mockito.stubbing.DefaultAnswer
66
import org.mockito.{ MockCreator, MockSettings }
77
import org.scalactic.Prettifier
88

9-
import scala.collection.JavaConverters._
9+
import scala.jdk.CollectionConverters._
1010
import scala.reflect.ClassTag
1111
import scala.reflect.runtime.universe.WeakTypeTag
1212

1313
/**
14-
* It automatically resets each mock after a each test is run, useful when we need to pass the mocks to some framework once at the beginning of the test suite
14+
* It automatically resets each mock after each test is run, useful when we need to pass the mocks to some framework once at the beginning of the test suite
1515
*
1616
* Just mix-in after your favourite suite, i.e. {{{class MyTest extends PlaySpec with MockitoSugar with ResetMocksAfterEachTest}}}
1717
*/

0 commit comments

Comments
 (0)