Skip to content

Commit

Permalink
util-test: Update Scalatest + Mockito
Browse files Browse the repository at this point in the history
  • Loading branch information
felixbr committed Jun 30, 2022
1 parent 2e558ef commit 3cb1cd8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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._

Expand All @@ -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<Person> argument = ArgumentCaptor.forClass(Person.class);",
" verify(mock).doSomething(argument.capture());",
" assertEquals(\"John\", argument.getValue().getName());",
""
).mkString("\n"))
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 3cb1cd8

Please sign in to comment.