From 0b5b666546e6ca61e8de55d4726fdf4485722943 Mon Sep 17 00:00:00 2001 From: Eugene Platonov Date: Thu, 22 May 2025 22:52:38 -0400 Subject: [PATCH 1/2] Upgrade mockito-core to 5.18.0, add support for JDK 17 and 21, drop Scala 2.11 and JDK 8 --- .github/workflows/ci.yml | 6 +- .sbtopts | 1 - README.md | 16 +-- build.sbt | 10 +- build.sh | 2 +- .../mockito/internal/handler/package.scala | 11 -- .../mockito/stubbing/ReturnsEmptyValues.scala | 41 ------ .../scala/org/mockito/ReflectionUtils.scala | 136 +++++++++++------- .../matchers/EqMatchers_VersionSpecific.scala | 15 -- .../org/mockito/internal/ScalaVersion.scala | 4 +- .../internal/ValueClassExtractor.scala | 15 +- .../MacroMatchers_211.scala | 52 ------- .../scala/org/mockito/captor/Captor.scala | 6 +- project/Dependencies.scala | 33 ++--- .../org/mockito/MockitoSugarTest_211.scala | 23 --- .../stubbing/ReturnsEmptyValuesTest.scala | 81 ----------- .../user/org/mockito/MockitoSugarTest.scala | 2 +- .../mockito/PostfixVerificationsTest.scala | 5 +- .../org/mockito/PrefixExpectationsTest.scala | 3 +- version.properties | 2 +- 20 files changed, 119 insertions(+), 345 deletions(-) delete mode 100644 common/src/main/scala-2.11/org/mockito/internal/handler/package.scala delete mode 100644 common/src/main/scala-2.11/org/mockito/stubbing/ReturnsEmptyValues.scala delete mode 100644 core/src/main/scala-2.11/org/mockito/matchers/EqMatchers_VersionSpecific.scala delete mode 100644 macro/src/main/scala-2.11/org.mockito.matchers/MacroMatchers_211.scala delete mode 100644 scalatest/src/test/scala-2.11/user/org/mockito/MockitoSugarTest_211.scala delete mode 100644 scalatest/src/test/scala-2.11/user/org/mockito/stubbing/ReturnsEmptyValuesTest.scala diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff6d94be..64415670 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: # Definition of the build matrix strategy: matrix: - java: [8, 11, 14] + java: [11, 17, 21] # All build steps # SINGLE-MATRIX-JOB means that the step does not need to be executed on every job in the matrix @@ -65,11 +65,11 @@ jobs: with: fetch-depth: '0' # https://github.com/shipkit/shipkit-changelog#fetch-depth-on-ci - - name: Set up Java 8 + - name: Set up Java 17 uses: actions/setup-java@v2 with: distribution: 'zulu' - java-version: 8 + java-version: 17 - name: Build and publish to Bintray/MavenCentral run: ./gradlew writeActualVersion diff --git a/.sbtopts b/.sbtopts index 284c4f08..aa3779d5 100644 --- a/.sbtopts +++ b/.sbtopts @@ -1,3 +1,2 @@ -J-Xmx8G -J-XX:MaxMetaspaceSize=1G --J-XX:+CMSClassUnloadingEnabled diff --git a/README.md b/README.md index b9c86f91..e1b4d16d 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,10 @@ The library has independent developers, release cycle and versioning from core m - [Scalaz](/scalaz/src/test) ## Partial unification -If you're in Scala 2.11 or 2.12 you'll probably want to add the compiler flag `-Ypartial-unification`, if you don't you risk some compile errors when trying to stub complex types using the idiomatic syntax +If you're in Scala 2.12 you'll probably want to add the compiler flag `-Ypartial-unification`, if you don't you risk some compile errors when trying to stub complex types using the idiomatic syntax + +## Notes for 2.0.0 +We dropped support for Scala 2.11 and Java 8, as Mockito 5 dropped support for Java 8. ## Notes for 1.13.6 @@ -500,14 +503,14 @@ Of course you can override the default behaviour, for this you have 2 options DefaultAnswers are also composable, so for example if you wanted empty values first and then smart nulls you could do `implicit val defaultAnswer: DefaultAnswer = ReturnsEmptyValues orElse ReturnsSmartNulls` ## Function Answers -`org.mockito.Answer[T]` can be a bit boilerplate-ish, mostly if you're still in Scala 2.11 (in 2.12 with SAM is much nicer), +`org.mockito.Answer[T]` can be a bit boilerplate-ish, to simplify the usage for both versions is that we replaced it by standard scala functions, so instead of ```scala when(myMock.foo("bar", 42)) thenAnswer new Answer[String] { override def answer(invocation: InvocationOnMock): String = i.getArgument[String](0) + i.getArgument[Int](1) } ``` -We can now write: (this may be nothing new for users of 2.12, but at least now the API is consistent for both 2.11 and 2.12) +We can now write: ```scala when(myMock.foo("bar", 42)) thenAnswer ((i: InvocationOnMock) => i.getArgument[String](0) + i.getArgument[Int](1)) ``` @@ -797,13 +800,6 @@ your build.sbt and that warning will be ignored for your tests **only** matchers usage then you have to explicitly provide the type for the matcher, thus `any` would become `any[MyType]` and `*` would become `*[MyType]` (you can also use `anyShort`, `anyInt`, etc for the primitive types) -### Scala 2.11 -Please note that in Scala 2.11 the following features are not supported - -* Default arguments on methods defined in traits (they will behave as before, getting `null` or a default value if they -are of a primitive type) -* Any kind of `ArgumentMatcher[T]` for methods with by-name parameters (they'll throw an exception if used with `ArgumentMatcher[T]`) - ## Authors * **Bruno Bonanno** - *Initial work* - [bbonanno](https://github.com/bbonanno) diff --git a/build.sbt b/build.sbt index c8138b8e..95a026c0 100644 --- a/build.sbt +++ b/build.sbt @@ -26,7 +26,7 @@ lazy val commonSettings = Seq( organization := "org.mockito", // Load version from the file so that Gradle/Shipkit and SBT use the same version - crossScalaVersions := Seq(currentScalaVersion, "2.12.20", "2.11.12"), + crossScalaVersions := Seq(currentScalaVersion, "2.12.20"), scalafmtOnCompile := true, scalacOptions ++= Seq( "-unchecked", @@ -122,8 +122,8 @@ lazy val cats = (project in file("cats")) commonSettings, publishSettings, libraryDependencies ++= Seq( - Dependencies.cats.value, - Dependencies.catsLaws.value % "test", + Dependencies.cats, + Dependencies.catsLaws % "test", Dependencies.disciplineScalatest % "test", Dependencies.scalatest % "test" ) @@ -150,8 +150,8 @@ lazy val common = (project in file("common")) noPublishingSettings, libraryDependencies ++= Dependencies.commonLibraries ++ Dependencies.scalaReflection.value ++ Seq( - Dependencies.catsLaws.value % "test", - Dependencies.scalacheck.value % "test" + Dependencies.catsLaws % "test", + Dependencies.scalacheck % "test" ) ) diff --git a/build.sh b/build.sh index 9f5487ec..ee239ec5 100755 --- a/build.sh +++ b/build.sh @@ -1,2 +1,2 @@ #!/usr/bin/env bash -java -Xms512M -Xmx2G -Xss2M -XX:ReservedCodeCacheSize=192m -XX:+CMSClassUnloadingEnabled -Dfile.encoding=UTF-8 -jar sbt/sbt-launch.jar -Dsbt.parser.simple=true clean +test 'set every publishTo := Some(Resolver.file("local-repo", file("target/dist")))' '+ publish' \ No newline at end of file +java -Xms512M -Xmx2G -Xss2M -XX:ReservedCodeCacheSize=192m -Dfile.encoding=UTF-8 -jar sbt/sbt-launch.jar -Dsbt.parser.simple=true clean +test 'set every publishTo := Some(Resolver.file("local-repo", file("target/dist")))' '+ publish' \ No newline at end of file diff --git a/common/src/main/scala-2.11/org/mockito/internal/handler/package.scala b/common/src/main/scala-2.11/org/mockito/internal/handler/package.scala deleted file mode 100644 index 57065846..00000000 --- a/common/src/main/scala-2.11/org/mockito/internal/handler/package.scala +++ /dev/null @@ -1,11 +0,0 @@ -package org.mockito.internal - -import scala.collection.mutable - -package object handler { - def unwrapVarargs(args: Array[Any]): Array[Any] = - args.lastOption match { - case Some(arg: mutable.WrappedArray[_]) => args.init ++ arg - case _ => args - } -} diff --git a/common/src/main/scala-2.11/org/mockito/stubbing/ReturnsEmptyValues.scala b/common/src/main/scala-2.11/org/mockito/stubbing/ReturnsEmptyValues.scala deleted file mode 100644 index 59b0f4b1..00000000 --- a/common/src/main/scala-2.11/org/mockito/stubbing/ReturnsEmptyValues.scala +++ /dev/null @@ -1,41 +0,0 @@ -package org.mockito -package stubbing - -import org.mockito.exceptions.base.MockitoException -import org.mockito.internal.stubbing.defaultanswers.ReturnsMoreEmptyValues -import org.mockito.invocation.InvocationOnMock - -import scala.collection.mutable -import scala.collection.mutable.ListBuffer -import scala.concurrent.Future -import scala.util.{ Failure, Try } - -object ReturnsEmptyValues extends DefaultAnswer { - private val javaEmptyValuesAndPrimitives = new ReturnsMoreEmptyValues - - private[mockito] lazy val emptyValues: Map[Class[_], AnyRef] = Map( - classOf[Option[_]] -> Option.empty, - classOf[List[_]] -> List.empty, - classOf[Set[_]] -> Set.empty, - classOf[Seq[_]] -> Seq.empty, - classOf[Iterable[_]] -> Iterable.empty, - classOf[Traversable[_]] -> Traversable.empty, - classOf[IndexedSeq[_]] -> IndexedSeq.empty, - classOf[Iterator[_]] -> Iterator.empty, - classOf[Stream[_]] -> Stream.empty, - classOf[Vector[_]] -> Vector.empty, - classOf[Try[_]] -> Failure(new MockitoException("Auto stub provided by mockito-scala")), - classOf[Future[_]] -> Future.failed(new MockitoException("Auto stub provided by mockito-scala")), - classOf[BigDecimal] -> BigDecimal(0), - classOf[BigInt] -> BigInt(0), - classOf[StringBuilder] -> StringBuilder.newBuilder, - classOf[Map[_, _]] -> Map.empty, - classOf[ListBuffer[_]] -> ListBuffer.empty, - classOf[mutable.Seq[_]] -> ListBuffer.empty, - classOf[mutable.Set[_]] -> mutable.HashSet.empty, - classOf[Either[_, _]] -> Left("Auto stub provided by mockito-scala") - ) - - override def apply(invocation: InvocationOnMock): Option[Any] = - Option(javaEmptyValuesAndPrimitives.answer(invocation)).orElse(emptyValues.get(invocation.returnType)) -} diff --git a/common/src/main/scala/org/mockito/ReflectionUtils.scala b/common/src/main/scala/org/mockito/ReflectionUtils.scala index 8f33e11e..935f29a8 100644 --- a/common/src/main/scala/org/mockito/ReflectionUtils.scala +++ b/common/src/main/scala/org/mockito/ReflectionUtils.scala @@ -16,6 +16,12 @@ object ReflectionUtils { import scala.reflect.runtime.{ universe => ru } import ru._ + private val JavaVersion: Int = + System.getProperty("java.version").split("\\.") match { + case Array("1", v, _*) => v.toInt // Java 8 style: 1.8.x + case Array(v, _*) => v.toInt // Java 9+ style: 11.x, 17.x, etc. + } + implicit def symbolToMethodSymbol(sym: Symbol): Symbols#MethodSymbol = sym.asInstanceOf[Symbols#MethodSymbol] private val mirror = runtimeMirror(getClass.getClassLoader) @@ -51,29 +57,23 @@ object ReflectionUtils { def returnsValueClass: Boolean = findTypeSymbol.exists(_.returnType.typeSymbol.isDerivedValueClass) private def resolveWithScalaGenerics: Option[Class[_]] = - scala.util - .Try { - findTypeSymbol - .filter(_.returnType.typeSymbol.isClass) - .map(_.asMethod.returnType.typeSymbol.asClass) - .map(mirror.runtimeClass) - } - .toOption - .flatten + uTry { + findTypeSymbol + .filter(_.returnType.typeSymbol.isClass) + .map(_.asMethod.returnType.typeSymbol.asClass) + .map(mirror.runtimeClass) + }.toOption.flatten private def findTypeSymbol = - scala.util - .Try { - mirror - .classSymbol(method.getDeclaringClass) - .info - .decls - .collectFirst { - case symbol if isNonConstructorMethod(symbol) && customMirror.methodToJava(symbol) === method => symbol - } - } - .toOption - .flatten + uTry { + mirror + .classSymbol(method.getDeclaringClass) + .info + .decls + .collectFirst { + case symbol if isNonConstructorMethod(symbol) && customMirror.methodToJava(symbol) === method => symbol + } + }.toOption.flatten private def resolveWithJavaGenerics: Option[Class[_]] = try Some(GenericsResolver.resolve(invocation.getMock.getClass).`type`(method.getDeclaringClass).method(method).resolveReturnClass()) @@ -85,45 +85,47 @@ object ReflectionUtils { private def isNonConstructorMethod(d: ru.Symbol): Boolean = d.isMethod && !d.isConstructor def extraInterfaces[T](implicit $wtt: WeakTypeTag[T], $ct: ClassTag[T]): List[Class[_]] = - scala.util - .Try { - val cls = clazz($ct) - $wtt.tpe match { - case RefinedType(types, _) => - types.map($wtt.mirror.runtimeClass).collect { - case c: Class[_] if c.isInterface && c != cls => c - } - case _ => List.empty - } + uTry { + val cls = clazz($ct) + $wtt.tpe match { + case RefinedType(types, _) => + types.map($wtt.mirror.runtimeClass).collect { + case c: Class[_] if c.isInterface && c != cls => c + } + case _ => List.empty } - .toOption + }.toOption .getOrElse(List.empty) def methodsWithLazyOrVarArgs(classes: Seq[Class[_]]): Seq[(Method, Set[Int])] = classes.flatMap { clazz => - scala.util - .Try { - mirror - .classSymbol(clazz) - .info - .members - .collect { - case symbol if isNonConstructorMethod(symbol) => - symbol -> symbol.typeSignature.paramLists.flatten.zipWithIndex.collect { - case (p, idx) if p.typeSignature.toString.startsWith("=>") => idx - case (p, idx) if p.typeSignature.toString.endsWith("*") => idx - }.toSet - } - .collect { - case (symbol, indices) if indices.nonEmpty => customMirror.methodToJava(symbol) -> indices - } - .toSeq - } - .toOption + uTry { + mirror + .classSymbol(clazz) + .info + .members + .collect { + case symbol if isNonConstructorMethod(symbol) => + symbol -> symbol.typeSignature.paramLists.flatten.zipWithIndex.collect { + case (p, idx) if p.typeSignature.toString.startsWith("=>") => idx + case (p, idx) if p.typeSignature.toString.endsWith("*") => idx + }.toSet + } + .collect { + case (symbol, indices) if indices.nonEmpty => customMirror.methodToJava(symbol) -> indices + } + .toSeq + }.toOption .getOrElse(Seq.empty) } - def setFinalStatic(field: Field, newValue: Any): Unit = { + def setFinalStatic(field: Field, newValue: AnyRef): Unit = + if (JavaVersion < 17) + setFinalStatic17Minus(field, newValue) + else + setFinalStatic17Plus(field, newValue) + + private def setFinalStatic17Minus(field: Field, newValue: AnyRef): Unit = { val clazz = classOf[java.lang.Class[_]] field.setAccessible(true) val modifiersField: Field = uTry(clazz.getDeclaredField("modifiers")) match { @@ -150,4 +152,34 @@ object ReflectionUtils { field.set(null, newValue) } + private def setFinalStatic17Plus(field: Field, newValue: AnyRef): Unit = + try { + // Try to get Unsafe instance (works with both sun.misc.Unsafe and jdk.internal.misc.Unsafe) + val unsafeClass: Class[_] = + try + Class.forName("sun.misc.Unsafe") + catch { + case _: ClassNotFoundException => Class.forName("jdk.internal.misc.Unsafe") + } + + val unsafeField = unsafeClass.getDeclaredField("theUnsafe") + unsafeField.setAccessible(true) + val unsafe = unsafeField.get(null) + + // Get methods via reflection to handle both Unsafe implementations + val staticFieldBaseMethod = unsafeClass.getMethod("staticFieldBase", classOf[Field]) + val staticFieldOffsetMethod = unsafeClass.getMethod("staticFieldOffset", classOf[Field]) + val putObjectMethod = unsafeClass.getMethod("putObject", classOf[Object], classOf[Long], classOf[Object]) + + // Get base and offset for the field + val base: Object = staticFieldBaseMethod.invoke(unsafe, field) + val offset: Long = staticFieldOffsetMethod.invoke(unsafe, field).asInstanceOf[Long] + + // Set the field value directly + putObjectMethod.invoke(unsafe, base, java.lang.Long.valueOf(offset), newValue) + } catch { + case NonFatal(e) => + throw new IllegalStateException(s"Cannot modify final field ${field.getName}", e) + } + } diff --git a/core/src/main/scala-2.11/org/mockito/matchers/EqMatchers_VersionSpecific.scala b/core/src/main/scala-2.11/org/mockito/matchers/EqMatchers_VersionSpecific.scala deleted file mode 100644 index 62dc925d..00000000 --- a/core/src/main/scala-2.11/org/mockito/matchers/EqMatchers_VersionSpecific.scala +++ /dev/null @@ -1,15 +0,0 @@ -package org.mockito.matchers - -trait EqMatchers_VersionSpecific { - - /** - * Creates a matcher that delegates on {{org.scalactic.Equality}} so you can always customise how the values are compared Also works with value classes - */ - def eqTo[T](value: T): T = macro MacroMatchers_211.eqToMatcher[T] - - /** - * It was intended to be used instead of eqTo when the argument is a value class, but eqTo now supports value classes so it is not needed anymore - */ - @deprecated("Use 'eqTo' instead", since = "1.0.2") - def eqToVal[T](value: T): T = macro MacroMatchers_211.eqToValMatcher[T] -} diff --git a/macro-common/src/main/scala/org/mockito/internal/ScalaVersion.scala b/macro-common/src/main/scala/org/mockito/internal/ScalaVersion.scala index 29971630..a8342bda 100644 --- a/macro-common/src/main/scala/org/mockito/internal/ScalaVersion.scala +++ b/macro-common/src/main/scala/org/mockito/internal/ScalaVersion.scala @@ -4,14 +4,12 @@ import scala.util.Properties sealed trait ScalaVersion object ScalaVersion { - case object V2_11 extends ScalaVersion case object V2_12 extends ScalaVersion case object V2_13 extends ScalaVersion val Current: ScalaVersion = { val version = Properties.scalaPropOrElse("version.number", "unknown") - if (version.startsWith("2.11")) ScalaVersion.V2_11 - else if (version.startsWith("2.12")) ScalaVersion.V2_12 + if (version.startsWith("2.12")) ScalaVersion.V2_12 else if (version.startsWith("2.13")) ScalaVersion.V2_13 else throw new Exception(s"Unsupported scala version $version") } diff --git a/macro-common/src/main/scala/org/mockito/internal/ValueClassExtractor.scala b/macro-common/src/main/scala/org/mockito/internal/ValueClassExtractor.scala index aea066d5..42046f78 100644 --- a/macro-common/src/main/scala/org/mockito/internal/ValueClassExtractor.scala +++ b/macro-common/src/main/scala/org/mockito/internal/ValueClassExtractor.scala @@ -1,7 +1,7 @@ package org.mockito.internal import org.mockito.internal.MacroDebug.debugResult -import org.mockito.internal.ScalaVersion.{ V2_11, V2_12, V2_13 } +import org.mockito.internal.ScalaVersion.{ V2_12, V2_13 } import scala.reflect.macros.blackbox @@ -43,19 +43,6 @@ object ValueClassExtractor { ScalaVersion.Current match { case V2_12 | V2_13 => c.Expr[ValueClassExtractor[VC]](q"new _root_.org.mockito.internal.ReflectionExtractor[$tpe]") - case V2_11 => - c.Expr[ValueClassExtractor[VC]] { - val companion = typeSymbol.companion - - if (companion.info.decls.exists(_.name.toString == "unapply")) - q""" - new _root_.org.mockito.internal.ValueClassExtractor[$tpe] { - override def extract(vc: $tpe): Any = $companion.unapply(vc).get - } - """ - else - q"new _root_.org.mockito.internal.NormalClassExtractor[$tpe]" - } } } else c.Expr[ValueClassExtractor[VC]](q"new _root_.org.mockito.internal.NormalClassExtractor[$tpe]") diff --git a/macro/src/main/scala-2.11/org.mockito.matchers/MacroMatchers_211.scala b/macro/src/main/scala-2.11/org.mockito.matchers/MacroMatchers_211.scala deleted file mode 100644 index bc28d9d0..00000000 --- a/macro/src/main/scala-2.11/org.mockito.matchers/MacroMatchers_211.scala +++ /dev/null @@ -1,52 +0,0 @@ -package org.mockito.matchers - -import org.mockito.internal.MacroDebug.debugResult -import org.mockito.internal.ValueClassExtractor -import org.mockito.{ ArgumentMatchers => JavaMatchers } -import org.scalactic.{ Equality, Prettifier } - -import scala.reflect.macros.blackbox - -object MacroMatchers_211 { - def eqTo[T: Equality: ValueClassExtractor](value: T)(implicit $pt: Prettifier): T = { - JavaMatchers.argThat(new EqTo[T](value)) - value - } - - def eqToMatcher[T: c.WeakTypeTag](c: blackbox.Context)(value: c.Expr[T]): c.Expr[T] = { - import c.universe._ - - def isValueClass(tpe: Tree) = tpe.symbol.isClass && tpe.symbol.asClass.isDerivedValueClass - - val r = c.Expr[T] { - c.macroApplication match { - case q"$_.eqTo[$tpe](new $clazz($arg))" if isValueClass(tpe) => - q"new $clazz(_root_.org.mockito.matchers.MacroMatchers_211.eqTo($arg))" - - case q"$_.eqTo[$tpe](..$arg)" => - q"_root_.org.mockito.matchers.MacroMatchers_211.eqTo[$tpe](..$arg)" - - case o => throw new Exception(s"Couldn't recognize ${show(o)}") - } - } - debugResult(c)("mockito-print-matcher")(r.tree) - r - } - - def eqToValMatcher[T: c.WeakTypeTag](c: blackbox.Context)(value: c.Expr[T]): c.Expr[T] = { - import c.universe._ - - val r = c.Expr[T] { - c.macroApplication match { - case q"$_.eqToVal[$_]($clazz($arg))" => q"$clazz(_root_.org.mockito.matchers.MacroMatchers_211.eqTo($arg))" - case q"$_.eqToVal[$_](new $clazz($arg))" => q"new $clazz(_root_.org.mockito.matchers.MacroMatchers_211.eqTo($arg))" - case q"$_.eqToVal[$tpe]($arg)" => - val companion = q"$tpe".symbol.companion - q"$companion.apply(_root_.org.mockito.matchers.MacroMatchers_211.eqTo( $companion.unapply($arg).get ))" - case o => throw new Exception(s"Couldn't recognize ${show(o)}") - } - } - debugResult(c)("mockito-print-matcher")(r.tree) - r - } -} diff --git a/macro/src/main/scala/org/mockito/captor/Captor.scala b/macro/src/main/scala/org/mockito/captor/Captor.scala index d92505ab..d4eabb64 100644 --- a/macro/src/main/scala/org/mockito/captor/Captor.scala +++ b/macro/src/main/scala/org/mockito/captor/Captor.scala @@ -4,7 +4,7 @@ import org.mockito.exceptions.base.MockitoAssertionError import org.mockito.exceptions.verification.{ ArgumentsAreDifferent, TooFewActualInvocations, TooManyActualInvocations } import org.mockito.internal.MacroDebug.debugResult import org.mockito.internal.ScalaVersion -import org.mockito.internal.ScalaVersion.{ V2_11, V2_12, V2_13 } +import org.mockito.internal.ScalaVersion.{ V2_12, V2_13 } import org.mockito.{ clazz, ArgumentCaptor } import org.scalactic.Equality import org.scalactic.TripleEquals._ @@ -78,8 +78,8 @@ object Captor { val paramType = tpe.decl(param.name).typeSignature.finalResultType val collectionConverters = ScalaVersion.Current match { - case V2_11 | V2_12 => q"import _root_.scala.collection.JavaConverters._" - case V2_13 => q"import _root_.scala.jdk.CollectionConverters._" + case V2_12 => q"import _root_.scala.collection.JavaConverters._" + case V2_13 => q"import _root_.scala.jdk.CollectionConverters._" } q""" diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 72f4405c..c08bf81e 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -6,23 +6,17 @@ object Dependencies { val scalatestVersion = "3.2.19" val commonLibraries = Seq( - "org.mockito" % "mockito-core" % "4.8.1", + "org.mockito" % "mockito-core" % "5.18.0", "org.scalactic" %% "scalactic" % scalatestVersion, "ru.vyarus" % "generics-resolver" % "3.0.3" ) - val scalacheck = Def.setting( - if (scalaBinaryVersion.value == "3") { - "org.scalacheck" %% "scalacheck" % "1.15.4" - } else { - "org.scalacheck" %% "scalacheck" % "1.15.2" - } - ) + val scalacheck = "org.scalacheck" %% "scalacheck" % "1.18.1" val scalatest = "org.scalatest" %% "scalatest" % scalatestVersion val specs2 = Seq( - "org.specs2" %% "specs2-core" % "4.10.6" % "provided", + "org.specs2" %% "specs2-core" % "4.21.0" % "provided", "org.hamcrest" % "hamcrest-core" % "3.0" % "provided" ) @@ -34,21 +28,10 @@ object Dependencies { } ) - val cats = Def.setting( - if (scalaBinaryVersion.value == "3") { - "org.typelevel" %% "cats-core" % "2.7.0" % "provided" - } else { - "org.typelevel" %% "cats-core" % "2.0.0" % "provided" - } - ) - val scalaz = "org.scalaz" %% "scalaz-core" % "7.3.7" % "provided" + val cats = "org.typelevel" %% "cats-core" % "2.13.0" % "provided" + val scalaz = "org.scalaz" %% "scalaz-core" % "7.3.8" % "provided" - val catsLaws = Def.setting( - if (scalaBinaryVersion.value == "3") { - "org.typelevel" %% "cats-laws" % "2.7.0" - } else { - "org.typelevel" %% "cats-laws" % "2.0.0" - } - ) - val disciplineScalatest = "org.typelevel" %% "discipline-scalatest" % "2.1.1" + val catsLaws = "org.typelevel" %% "cats-laws" % "2.13.0" + + val disciplineScalatest = "org.typelevel" %% "discipline-scalatest" % "2.3.0" } diff --git a/scalatest/src/test/scala-2.11/user/org/mockito/MockitoSugarTest_211.scala b/scalatest/src/test/scala-2.11/user/org/mockito/MockitoSugarTest_211.scala deleted file mode 100644 index eab2e6a3..00000000 --- a/scalatest/src/test/scala-2.11/user/org/mockito/MockitoSugarTest_211.scala +++ /dev/null @@ -1,23 +0,0 @@ -package user.org.mockito - -import org.mockito.{ ArgumentMatchersSugar, MockitoSugar } -import org.scalatest.matchers.should.Matchers -import org.scalatest.wordspec.AnyWordSpec - -class MockitoSugarTest_211 extends AnyWordSpec with MockitoSugar with Matchers with ArgumentMatchersSugar { - trait Baz { - def traitMethod(defaultArg: Int = 30, anotherDefault: String = "hola"): Int = ??? - } - - "mock[T]" should { - "not fail with default arguments in traits" in { - val aMock = mock[Baz] - - when(aMock.traitMethod(any, any)) thenReturn 69 - - aMock.traitMethod() shouldBe 69 - - verify(aMock).traitMethod(0, "") - } - } -} diff --git a/scalatest/src/test/scala-2.11/user/org/mockito/stubbing/ReturnsEmptyValuesTest.scala b/scalatest/src/test/scala-2.11/user/org/mockito/stubbing/ReturnsEmptyValuesTest.scala deleted file mode 100644 index 5b301397..00000000 --- a/scalatest/src/test/scala-2.11/user/org/mockito/stubbing/ReturnsEmptyValuesTest.scala +++ /dev/null @@ -1,81 +0,0 @@ -package user.org.mockito.stubbing - -import org.mockito.exceptions.base.MockitoException -import org.mockito.{ DefaultAnswers, IdiomaticMockito } -import org.scalatest.concurrent.ScalaFutures -import org.scalatest.matchers.should.Matchers -import org.scalatest.wordspec.AnyWordSpec -import org.scalatest.{ OptionValues, TryValues } -import user.org.mockito.stubbing.DefaultAnswerTest._ - -import scala.collection.mutable -import scala.collection.mutable.ListBuffer -import scala.concurrent.Future -import scala.util.{ Success, Try } - -class ReturnsEmptyValuesTest extends AnyWordSpec with Matchers with IdiomaticMockito with TryValues with OptionValues with ScalaFutures { - class KnownTypes { - def returnsOption: Option[String] = Some("not mocked!") - def returnsList: List[String] = List("not mocked!") - def returnsSet: Set[String] = Set("not mocked!") - def returnsSeq: Seq[String] = Seq("not mocked!") - def returnsIterable: Iterable[String] = Iterable("not mocked!") - def returnsTraversable: Traversable[String] = Traversable("not mocked!") - def returnsIndexedSeq: IndexedSeq[String] = IndexedSeq("not mocked!") - def returnsIterator: Iterator[String] = Iterator("not mocked!") - def returnsStream: Stream[String] = Stream("not mocked!") - def returnsVector: Vector[String] = Vector("not mocked!") - def returnsEither: Either[Boolean, String] = Right("not mocked!") - def returnsTry: Try[String] = Success("not mocked!") - def returnsFuture: Future[String] = Future.successful("not mocked!") - def returnsBigDecimal: BigDecimal = BigDecimal(42) - def returnsBigInt: BigInt = BigInt(42) - def returnsStringBuilder: StringBuilder = StringBuilder.newBuilder.append("not mocked!") - def returnsMap: Map[String, Int] = Map("not mocked!" -> 42) - def returnsMutableSeq: mutable.Seq[String] = ListBuffer("not mocked!") - def returnsListBuffer: ListBuffer[String] = ListBuffer("not mocked!") - def returnsMutableSet: mutable.Set[String] = mutable.HashSet("not mocked!") - } - - "ReturnsEmptyValues" should { - "return a default value for primitives" in { - val primitives = mock[Primitives](DefaultAnswers.ReturnsEmptyValues) - - primitives.barByte shouldBe 0.toByte - primitives.barBoolean shouldBe false - primitives.barChar shouldBe 0 - primitives.barDouble shouldBe 0 - primitives.barInt shouldBe 0 - primitives.barFloat shouldBe 0 - primitives.barShort shouldBe 0 - primitives.barLong shouldBe 0 - } - - "return the empty values for known classes" in { - val aMock = mock[KnownTypes](DefaultAnswers.ReturnsEmptyValues) - - aMock.returnsOption shouldBe None - aMock.returnsList shouldBe List.empty - aMock.returnsSet shouldBe Set.empty - aMock.returnsSeq shouldBe Seq.empty - aMock.returnsIterable shouldBe Iterable.empty - aMock.returnsTraversable shouldBe Traversable.empty - aMock.returnsIndexedSeq shouldBe IndexedSeq.empty - aMock.returnsIterator shouldBe Iterator.empty - aMock.returnsStream shouldBe Stream.empty - aMock.returnsVector shouldBe Vector.empty - aMock.returnsTry.failure.exception shouldBe a[MockitoException] - aMock.returnsTry.failure.exception.getMessage shouldBe "Auto stub provided by mockito-scala" - aMock.returnsFuture.failed.value.value.success.value shouldBe a[MockitoException] - aMock.returnsFuture.failed.value.value.success.value.getMessage shouldBe "Auto stub provided by mockito-scala" - aMock.returnsBigDecimal shouldBe BigDecimal(0) - aMock.returnsBigInt shouldBe BigInt(0) - aMock.returnsStringBuilder shouldBe new StringBuilder - aMock.returnsEither shouldBe Left("Auto stub provided by mockito-scala") - aMock.returnsMap shouldBe Map.empty - aMock.returnsMutableSeq shouldBe ListBuffer.empty - aMock.returnsListBuffer shouldBe ListBuffer.empty - aMock.returnsMutableSet shouldBe mutable.HashSet.empty - } - } -} diff --git a/scalatest/src/test/scala/user/org/mockito/MockitoSugarTest.scala b/scalatest/src/test/scala/user/org/mockito/MockitoSugarTest.scala index d78231bb..5e98be90 100644 --- a/scalatest/src/test/scala/user/org/mockito/MockitoSugarTest.scala +++ b/scalatest/src/test/scala/user/org/mockito/MockitoSugarTest.scala @@ -300,7 +300,7 @@ class MockitoSugarTest extends AnyWordSpec with MockitoSugar with Matchers with e.getMessage should include("Argument(s) are different! Wanted:") e.getMessage should include("foo.baz(42, PrettifiedBaz(hola));") - e.getMessage should include("Actual invocations have different arguments:") + e.getMessage should include("Actual invocations have different arguments") e.getMessage should include("foo.baz(42, PrettifiedBaz(chau));") } } diff --git a/scalatest/src/test/scala/user/org/mockito/PostfixVerificationsTest.scala b/scalatest/src/test/scala/user/org/mockito/PostfixVerificationsTest.scala index 7789cc58..cd4f0bd4 100644 --- a/scalatest/src/test/scala/user/org/mockito/PostfixVerificationsTest.scala +++ b/scalatest/src/test/scala/user/org/mockito/PostfixVerificationsTest.scala @@ -83,7 +83,8 @@ class PostfixVerificationsTest extends AnyWordSpec with IdiomaticMockitoTestSetu org.bar wasCalled onlyHere - a[NoInteractionsWanted] should be thrownBy { + // https://github.com/mockito/mockito/pull/3287 changed the behavior of this + a[WantedButNotInvoked] should be thrownBy { org.baz org.baz wasCalled onlyHere @@ -509,7 +510,7 @@ class PostfixVerificationsTest extends AnyWordSpec with IdiomaticMockitoTestSetu e.getMessage should include("Argument(s) are different! Wanted:") e.getMessage should include("org.baz(42, PrettifiedBaz(hola));") - e.getMessage should include("Actual invocations have different arguments:") + e.getMessage should include("Actual invocations have different arguments") e.getMessage should include("org.baz(42, PrettifiedBaz(chau));") } diff --git a/scalatest/src/test/scala/user/org/mockito/PrefixExpectationsTest.scala b/scalatest/src/test/scala/user/org/mockito/PrefixExpectationsTest.scala index e9521a2f..9419759e 100644 --- a/scalatest/src/test/scala/user/org/mockito/PrefixExpectationsTest.scala +++ b/scalatest/src/test/scala/user/org/mockito/PrefixExpectationsTest.scala @@ -369,6 +369,7 @@ class PrefixExpectationsTest extends AnyWordSpec with Matchers with ArgumentMatc org.fooWithVarArgAndSecondParameterList("cow")(cheese) expect a call to org.fooWithVarArgAndSecondParameterList("cow")(cheese) expect a call to org.fooWithVarArgAndSecondParameterList("cow")(*) + expect a call to org.fooWithVarArgAndSecondParameterList(*)(*) expect a call to org.fooWithVarArgAndSecondParameterList(endsWith("w"))(*) expect a call to org.fooWithVarArgAndSecondParameterList(startsWith("c"))(*) @@ -533,7 +534,7 @@ class PrefixExpectationsTest extends AnyWordSpec with Matchers with ArgumentMatc e.getMessage should include("Argument(s) are different! Wanted:") e.getMessage should include("org.baz(42, PrettifiedBaz(hola));") - e.getMessage should include("Actual invocations have different arguments:") + e.getMessage should include("Actual invocations have different arguments") e.getMessage should include("org.baz(42, PrettifiedBaz(chau));") } diff --git a/version.properties b/version.properties index c1a67960..bd7ddf43 100644 --- a/version.properties +++ b/version.properties @@ -1,3 +1,3 @@ # The version is inferred by shipkit-auto-version Gradle plugin # More: https://github.com/shipkit/shipkit-auto-version -version=1.17.* \ No newline at end of file +version=2.0.* \ No newline at end of file From 5301d2870cdc48a53ceea953962210580b4990f4 Mon Sep 17 00:00:00 2001 From: Eugene Platonov Date: Fri, 23 May 2025 13:45:00 -0400 Subject: [PATCH 2/2] Drop long time deprecated methods --- .../matchers/EqMatchers_VersionSpecific.scala | 5 -- .../matchers/EqMatchers_VersionSpecific.scala | 5 -- .../scala/org/mockito/captor/ArgCaptor.scala | 5 ++ .../scala/org/mockito/captor/Captors.scala | 10 ---- .../scalatest/IdiomaticMockitoFixture.scala | 11 ----- .../scalatest/MockitoFixture.scala | 11 ----- .../scalatest/MockitoSessionFixture.scala | 17 ------- .../scalatest/ResetMocksAfterEachTest.scala | 48 ------------------- .../mockito/matchers/MacroBasedMatchers.scala | 6 --- .../mockito/PostfixVerificationsTest.scala | 33 ------------- .../org/mockito/PrefixExpectationsTest.scala | 33 ------------- .../mockito/matchers/AnyMatchersTest.scala | 12 ----- .../org/mockito/matchers/EqMatchersTest.scala | 12 ----- 13 files changed, 5 insertions(+), 203 deletions(-) create mode 100644 core/src/main/scala/org/mockito/captor/ArgCaptor.scala delete mode 100644 core/src/main/scala/org/mockito/captor/Captors.scala delete mode 100644 core/src/main/scala/org/mockito/integrations/scalatest/IdiomaticMockitoFixture.scala delete mode 100644 core/src/main/scala/org/mockito/integrations/scalatest/MockitoFixture.scala delete mode 100644 core/src/main/scala/org/mockito/integrations/scalatest/MockitoSessionFixture.scala delete mode 100644 core/src/main/scala/org/mockito/integrations/scalatest/ResetMocksAfterEachTest.scala diff --git a/core/src/main/scala-2.12/org/mockito/matchers/EqMatchers_VersionSpecific.scala b/core/src/main/scala-2.12/org/mockito/matchers/EqMatchers_VersionSpecific.scala index efd7f200..ebaf7ea8 100644 --- a/core/src/main/scala-2.12/org/mockito/matchers/EqMatchers_VersionSpecific.scala +++ b/core/src/main/scala-2.12/org/mockito/matchers/EqMatchers_VersionSpecific.scala @@ -14,9 +14,4 @@ trait EqMatchers_VersionSpecific { value } - /** - * It was intended to be used instead of eqTo when the argument is a value class, but eqTo now supports value classes so it is not needed anymore - */ - @deprecated("Use 'eqTo' instead", since = "1.0.2") - def eqToVal[T: Equality: ValueClassExtractor](value: T)(implicit $pt: Prettifier): T = eqTo(value) } diff --git a/core/src/main/scala-2.13/org/mockito/matchers/EqMatchers_VersionSpecific.scala b/core/src/main/scala-2.13/org/mockito/matchers/EqMatchers_VersionSpecific.scala index efd7f200..ebaf7ea8 100644 --- a/core/src/main/scala-2.13/org/mockito/matchers/EqMatchers_VersionSpecific.scala +++ b/core/src/main/scala-2.13/org/mockito/matchers/EqMatchers_VersionSpecific.scala @@ -14,9 +14,4 @@ trait EqMatchers_VersionSpecific { value } - /** - * It was intended to be used instead of eqTo when the argument is a value class, but eqTo now supports value classes so it is not needed anymore - */ - @deprecated("Use 'eqTo' instead", since = "1.0.2") - def eqToVal[T: Equality: ValueClassExtractor](value: T)(implicit $pt: Prettifier): T = eqTo(value) } diff --git a/core/src/main/scala/org/mockito/captor/ArgCaptor.scala b/core/src/main/scala/org/mockito/captor/ArgCaptor.scala new file mode 100644 index 00000000..f4bac784 --- /dev/null +++ b/core/src/main/scala/org/mockito/captor/ArgCaptor.scala @@ -0,0 +1,5 @@ +package org.mockito.captor + +object ArgCaptor { + def apply[T](implicit c: Captor[T]): Captor[T] = c +} diff --git a/core/src/main/scala/org/mockito/captor/Captors.scala b/core/src/main/scala/org/mockito/captor/Captors.scala deleted file mode 100644 index f9e69fa2..00000000 --- a/core/src/main/scala/org/mockito/captor/Captors.scala +++ /dev/null @@ -1,10 +0,0 @@ -package org.mockito.captor - -object ArgCaptor { - def apply[T](implicit c: Captor[T]): Captor[T] = c -} - -object ValCaptor { - @deprecated("use 'ArgCaptor' instead", since = "1.0.2") - def apply[T](implicit c: Captor[T]): Captor[T] = c -} diff --git a/core/src/main/scala/org/mockito/integrations/scalatest/IdiomaticMockitoFixture.scala b/core/src/main/scala/org/mockito/integrations/scalatest/IdiomaticMockitoFixture.scala deleted file mode 100644 index 64df5681..00000000 --- a/core/src/main/scala/org/mockito/integrations/scalatest/IdiomaticMockitoFixture.scala +++ /dev/null @@ -1,11 +0,0 @@ -package org.mockito.integrations.scalatest - -import org.mockito._ - -/** - * It automatically wraps each test in a MockitoScalaSession so the implicit verifications are applied - * - * Just mix-in after your favourite suite, i.e. {{{class MyTest extends WordSpec with IdiomaticMockitoFixture}}} - */ -@deprecated("Please use org.mockito.scalatest.IdiomaticMockito or org.mockito.scalatest.AsyncIdiomaticMockito from the mockito-scala-scalatest module", "1.3.0") -trait IdiomaticMockitoFixture extends MockitoSessionFixture with IdiomaticMockito with ArgumentMatchersSugar diff --git a/core/src/main/scala/org/mockito/integrations/scalatest/MockitoFixture.scala b/core/src/main/scala/org/mockito/integrations/scalatest/MockitoFixture.scala deleted file mode 100644 index 09229629..00000000 --- a/core/src/main/scala/org/mockito/integrations/scalatest/MockitoFixture.scala +++ /dev/null @@ -1,11 +0,0 @@ -package org.mockito.integrations.scalatest - -import org.mockito._ - -/** - * It automatically wraps each test in a MockitoScalaSession so the implicit verifications are applied - * - * Just mix-in after your favourite suite, i.e. {{{class MyTest extends WordSpec with MockitoFixture}}} - */ -@deprecated("Please use org.mockito.scalatest.MockitoSugar or org.mockito.scalatest.AsyncMockitoSugar from the mockito-scala-scalatest module", "1.3.0") -trait MockitoFixture extends MockitoSessionFixture with MockitoSugar with ArgumentMatchersSugar diff --git a/core/src/main/scala/org/mockito/integrations/scalatest/MockitoSessionFixture.scala b/core/src/main/scala/org/mockito/integrations/scalatest/MockitoSessionFixture.scala deleted file mode 100644 index ab6494c1..00000000 --- a/core/src/main/scala/org/mockito/integrations/scalatest/MockitoSessionFixture.scala +++ /dev/null @@ -1,17 +0,0 @@ -package org.mockito.integrations.scalatest - -import org.mockito._ -import org.scalatest.{ Outcome, Suite, TestSuite } - -@deprecated("Please use org.mockito.scalatest.MockitoSessionFixture from the mockito-scala-scalatest module", "1.3.0") -private[mockito] trait MockitoSessionFixture extends TestSuite { this: Suite => - - abstract override def withFixture(test: NoArgTest): Outcome = { - val session = MockitoScalaSession(name = s"${test.name} - session") - val result = super.withFixture(test) - // if the test has thrown an exception, the session will check first if the exception could be related to a mis-use - // of mockito, if not, it will throw nothing so the real test failure can be reported by the ScalaTest - session.finishMocking(result.toOption) - result - } -} diff --git a/core/src/main/scala/org/mockito/integrations/scalatest/ResetMocksAfterEachTest.scala b/core/src/main/scala/org/mockito/integrations/scalatest/ResetMocksAfterEachTest.scala deleted file mode 100644 index 63459b6d..00000000 --- a/core/src/main/scala/org/mockito/integrations/scalatest/ResetMocksAfterEachTest.scala +++ /dev/null @@ -1,48 +0,0 @@ -package org.mockito.integrations.scalatest - -import java.util.concurrent.ConcurrentHashMap - -import org.mockito.{ MockCreator, MockSettings, MockitoSugar } -import org.mockito.stubbing.DefaultAnswer -import org.scalactic.Prettifier -import org.scalatest.{ Outcome, TestSuite } - -import scala.collection.JavaConverters._ -import scala.reflect.ClassTag -import scala.reflect.runtime.universe.WeakTypeTag - -/** - * 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 - * - * Just mix-in after your favourite suite, i.e. {{{class MyTest extends PlaySpec with MockitoSugar with ResetMocksAfterEachTest}}} - */ -@deprecated("Please use org.mockito.scalatest.ResetMocksAfterEachTest from the mockito-scala-scalatest module", "1.3.0") -trait ResetMocksAfterEachTest extends TestSuite with MockCreator { self: MockCreator => - - private val mocksToReset = ConcurrentHashMap.newKeySet[AnyRef]().asScala - - private def resetAll(): Unit = mocksToReset.foreach(MockitoSugar.reset(_)) - - override protected def withFixture(test: NoArgTest): Outcome = { - val outcome = super.withFixture(test) - resetAll() - outcome - } - - private def addMock[T <: AnyRef](mock: T) = { - mocksToReset.add(mock) - mock - } - - abstract override def mock[T <: AnyRef: ClassTag: WeakTypeTag](implicit defaultAnswer: DefaultAnswer, $pt: Prettifier): T = - addMock(super.mock[T]) - - abstract override def mock[T <: AnyRef: ClassTag: WeakTypeTag](defaultAnswer: DefaultAnswer)(implicit $pt: Prettifier): T = - addMock(super.mock[T](defaultAnswer)) - - abstract override def mock[T <: AnyRef: ClassTag: WeakTypeTag](mockSettings: MockSettings)(implicit $pt: Prettifier): T = - addMock(super.mock[T](mockSettings)) - - abstract override def mock[T <: AnyRef: ClassTag: WeakTypeTag](name: String)(implicit defaultAnswer: DefaultAnswer, $pt: Prettifier): T = - addMock(super.mock[T](name)) -} diff --git a/core/src/main/scala/org/mockito/matchers/MacroBasedMatchers.scala b/core/src/main/scala/org/mockito/matchers/MacroBasedMatchers.scala index 2346ca91..87e3b18f 100644 --- a/core/src/main/scala/org/mockito/matchers/MacroBasedMatchers.scala +++ b/core/src/main/scala/org/mockito/matchers/MacroBasedMatchers.scala @@ -4,12 +4,6 @@ import org.mockito.{ ArgumentMatchers => JavaMatchers } trait MacroBasedMatchers { - /** - * It was intended to be used instead of any when the argument is a value class, but any now supports value classes so it is not needed anymore - */ - @deprecated("Use 'any[T]' or '*[T]' instead", since = "1.0.2") - def anyVal[T](implicit default: DefaultValueProvider[T]): T = any[T] - /** * Delegates to ArgumentMatchers.any(), it's main purpose is to remove the () out of the method call, if you try to do that directly on the test you get this error * diff --git a/scalatest/src/test/scala/user/org/mockito/PostfixVerificationsTest.scala b/scalatest/src/test/scala/user/org/mockito/PostfixVerificationsTest.scala index cd4f0bd4..864488a3 100644 --- a/scalatest/src/test/scala/user/org/mockito/PostfixVerificationsTest.scala +++ b/scalatest/src/test/scala/user/org/mockito/PostfixVerificationsTest.scala @@ -403,27 +403,6 @@ class PostfixVerificationsTest extends AnyWordSpec with IdiomaticMockitoTestSetu org.valueClassWithVarArgAndSecondParameterList(Bread("Chipa"), Bread("Tortilla"))(cheese) was called } - "eqToVal works with new syntax" in { - val org = orgDouble() - - org.valueClass(1, eqToVal(new ValueClass("meh"))) returns "mocked!" - org.valueClass(1, new ValueClass("meh")) shouldBe "mocked!" - org.valueClass(1, eqToVal(new ValueClass("meh"))) was called - - org.valueCaseClass(2, eqToVal(ValueCaseClassInt(100))) returns "mocked!" - org.valueCaseClass(2, ValueCaseClassInt(100)) shouldBe "mocked!" - org.valueCaseClass(2, eqToVal(ValueCaseClassInt(100))) was called - - val caseClassValue = ValueCaseClassInt(100) - org.valueCaseClass(3, eqToVal(caseClassValue)) returns "mocked!" - org.valueCaseClass(3, ValueCaseClassInt(100)) shouldBe "mocked!" - org.valueCaseClass(3, eqToVal(caseClassValue)) was called - - org.valueCaseClass(*, ValueCaseClassInt(200)) returns "mocked!" - org.valueCaseClass(4, ValueCaseClassInt(200)) shouldBe "mocked!" - org.valueCaseClass(*, ValueCaseClassInt(200)) was called - } - "eqTo macro works with new syntax" in { val org = orgDouble() @@ -457,18 +436,6 @@ class PostfixVerificationsTest extends AnyWordSpec with IdiomaticMockitoTestSetu } } - "anyVal works with new syntax" in { - val org = orgDouble() - - org.valueClass(1, anyVal[ValueClass]) returns "mocked!" - org.valueClass(1, new ValueClass("meh")) shouldBe "mocked!" - org.valueClass(1, anyVal[ValueClass]) was called - - org.valueCaseClass(2, anyVal[ValueCaseClassInt]) returns "mocked!" - org.valueCaseClass(2, ValueCaseClassInt(100)) shouldBe "mocked!" - org.valueCaseClass(2, anyVal[ValueCaseClassInt]) was called - } - "any works with new syntax" in { val org = orgDouble() diff --git a/scalatest/src/test/scala/user/org/mockito/PrefixExpectationsTest.scala b/scalatest/src/test/scala/user/org/mockito/PrefixExpectationsTest.scala index 9419759e..9f25ea3c 100644 --- a/scalatest/src/test/scala/user/org/mockito/PrefixExpectationsTest.scala +++ b/scalatest/src/test/scala/user/org/mockito/PrefixExpectationsTest.scala @@ -427,27 +427,6 @@ class PrefixExpectationsTest extends AnyWordSpec with Matchers with ArgumentMatc expect a call to org.valueClassWithVarArgAndSecondParameterList(Bread("Chipa"), Bread("Tortilla"))(cheese) } - "eqToVal works with new syntax" in { - val org = orgDouble() - - org.valueClass(1, eqToVal(new ValueClass("meh"))) returns "mocked!" - org.valueClass(1, new ValueClass("meh")) shouldBe "mocked!" - expect a call to org.valueClass(1, eqToVal(new ValueClass("meh"))) - - org.valueCaseClass(2, eqToVal(ValueCaseClassInt(100))) returns "mocked!" - org.valueCaseClass(2, ValueCaseClassInt(100)) shouldBe "mocked!" - expect a call to org.valueCaseClass(2, eqToVal(ValueCaseClassInt(100))) - - val caseClassValue = ValueCaseClassInt(100) - org.valueCaseClass(3, eqToVal(caseClassValue)) returns "mocked!" - org.valueCaseClass(3, ValueCaseClassInt(100)) shouldBe "mocked!" - expect a call to org.valueCaseClass(3, eqToVal(caseClassValue)) - - org.valueCaseClass(*, ValueCaseClassInt(200)) returns "mocked!" - org.valueCaseClass(4, ValueCaseClassInt(200)) shouldBe "mocked!" - expect a call to org.valueCaseClass(*, ValueCaseClassInt(200)) - } - "eqTo macro works with new syntax" in { val org = orgDouble() @@ -481,18 +460,6 @@ class PrefixExpectationsTest extends AnyWordSpec with Matchers with ArgumentMatc } } - "anyVal works with new syntax" in { - val org = orgDouble() - - org.valueClass(1, anyVal[ValueClass]) returns "mocked!" - org.valueClass(1, new ValueClass("meh")) shouldBe "mocked!" - expect a call to org.valueClass(1, anyVal[ValueClass]) - - org.valueCaseClass(2, anyVal[ValueCaseClassInt]) returns "mocked!" - org.valueCaseClass(2, ValueCaseClassInt(100)) shouldBe "mocked!" - expect a call to org.valueCaseClass(2, anyVal[ValueCaseClassInt]) - } - "any works with new syntax" in { val org = orgDouble() diff --git a/scalatest/src/test/scala/user/org/mockito/matchers/AnyMatchersTest.scala b/scalatest/src/test/scala/user/org/mockito/matchers/AnyMatchersTest.scala index 1ea138b3..fb9b258c 100644 --- a/scalatest/src/test/scala/user/org/mockito/matchers/AnyMatchersTest.scala +++ b/scalatest/src/test/scala/user/org/mockito/matchers/AnyMatchersTest.scala @@ -43,18 +43,6 @@ class AnyMatchersTest extends AnyFlatSpec with MockitoSugar with Matchers with A verify(aMock).barTyped("meh") } - "anyVal" should "work with a value class" in { - val aMock = mock[Foo] - - when(aMock.valueClass(anyVal[ValueClass])) thenReturn "mocked!" - aMock.valueClass(new ValueClass("meh")) shouldBe "mocked!" - verify(aMock).valueClass(anyVal[ValueClass]) - - when(aMock.valueCaseClass(anyVal[ValueCaseClassInt])) thenReturn 100 - aMock.valueCaseClass(ValueCaseClassInt(1)) shouldBe 100 - verify(aMock).valueCaseClass(anyVal[ValueCaseClassInt]) - } - "any" should "work with a value class" in { val aMock = mock[Foo] diff --git a/scalatest/src/test/scala/user/org/mockito/matchers/EqMatchersTest.scala b/scalatest/src/test/scala/user/org/mockito/matchers/EqMatchersTest.scala index 31fe917a..bbee9808 100644 --- a/scalatest/src/test/scala/user/org/mockito/matchers/EqMatchersTest.scala +++ b/scalatest/src/test/scala/user/org/mockito/matchers/EqMatchersTest.scala @@ -18,18 +18,6 @@ class EqMatchersTest extends AnyFlatSpec with MockitoSugar with Matchers with Ar verify(aMock).valueCaseClass(eqTo(expected)) } - "eqToVal[T]" should "work with value classes" in { - val aMock = mock[Foo] - - aMock.valueClass(new ValueClass("meh")) - verify(aMock).valueClass(eqToVal(new ValueClass("meh"))) - - aMock.valueCaseClass(ValueCaseClassInt(100)) - verify(aMock).valueCaseClass(eqToVal(ValueCaseClassInt(100))) - val expected = ValueCaseClassInt(100) - verify(aMock).valueCaseClass(eqToVal(expected)) - } - "eqTo[T]" should "work with AnyRef" in { val aMock = mock[Foo]