diff --git a/build.sbt b/build.sbt index 3b287357fe..556bfcbad0 100644 --- a/build.sbt +++ b/build.sbt @@ -692,10 +692,10 @@ lazy val utilTest = Project( ).settings( name := "util-test", libraryDependencies ++= Seq( - "org.mockito" % "mockito-all" % "1.10.19", - "org.scalatest" %% "scalatest" % "3.1.2", - "org.scalatestplus" %% "junit-4-12" % "3.1.2.0", - "org.scalatestplus" %% "mockito-1-10" % "3.1.0.0" + "org.mockito" % "mockito-core" % "3.4.6", + "org.scalatest" %% "scalatest" % "3.2.9", + "org.scalatestplus" %% "junit-4-13" % "3.2.9.0", + "org.scalatestplus" %% "mockito-3-4" % "3.2.9.0" ) ).dependsOn(utilCore, utilLogging, utilStats) diff --git a/util-test/src/main/scala/com/twitter/util/testing/ArgumentCapture.scala b/util-test/src/main/scala/com/twitter/util/testing/ArgumentCapture.scala index 9961cf33ba..937e2b2f48 100644 --- a/util-test/src/main/scala/com/twitter/util/testing/ArgumentCapture.scala +++ b/util-test/src/main/scala/com/twitter/util/testing/ArgumentCapture.scala @@ -1,7 +1,8 @@ package com.twitter.util.testing import org.mockito.ArgumentCaptor -import org.mockito.exceptions.Reporter +import org.mockito.exceptions.base.MockitoException + import scala.jdk.CollectionConverters._ import scala.reflect._ @@ -13,10 +14,20 @@ trait ArgumentCapture { * Enables capturingOne to be implemented over capturingAll with the same behavior as ArgumentCaptor.getValue */ private[this] def noArgWasCaptured(): Nothing = { - new Reporter().noArgumentValueWasCaptured() // this always throws an exception - throw new RuntimeException( - "this should be unreachable, but allows the method to be of type Nothing" - ) + // Inlined from mockito 1.10.x org.mockito.exceptions.Reporter. + // The Reporter was removed in later versions and I couldn't find the replacement. + throw new MockitoException(List( + "No argument value was captured!", + "You might have forgotten to use argument.capture() in verify()...", + "...or you used capture() in stubbing but stubbed method was not called.", + "Be aware that it is recommended to use capture() only with verify()", + "", + "Examples of correct argument capturing:", + " ArgumentCaptor argument = ArgumentCaptor.forClass(Person.class);", + " verify(mock).doSomething(argument.capture());", + " assertEquals(\"John\", argument.getValue().getName());", + "" + ).mkString("\n")) } /** diff --git a/util-test/src/test/scala/com/twitter/util/testing/ArgumentCaptureTest.scala b/util-test/src/test/scala/com/twitter/util/testing/ArgumentCaptureTest.scala index 502350d755..af46517a05 100644 --- a/util-test/src/test/scala/com/twitter/util/testing/ArgumentCaptureTest.scala +++ b/util-test/src/test/scala/com/twitter/util/testing/ArgumentCaptureTest.scala @@ -1,6 +1,6 @@ package com.twitter.util.testing -import org.mockito.Matchers._ +import org.mockito.ArgumentMatchers.any import org.mockito.Mockito._ import org.scalatestplus.mockito.MockitoSugar import org.scalatest.funsuite.AnyFunSuite