带有 Specs2 的 Mockito 中的 NoSuchMethodError

NoSuchMethodError in Mockito with Specs2

我将 Play 2.6 项目升级到 Play 2.7。该项目编译,但我在测试中得到 NoSuchMethodError

Exception in thread "specs2-8" java.lang.NoSuchMethodError: org.mockito.internal.progress.ThreadSafeMockingProgress.mockingProgress()Lorg/mockito/internal/progress/MockingProgress;
at org.mockito.ArgumentMatchers.reportMatcher(ArgumentMatchers.java:1329)
at org.mockito.ArgumentMatchers.anyObject(ArgumentMatchers.java:165)
at org.mockito.ArgumentMatchers.any(ArgumentMatchers.java:145)
at org.specs2.mock.mockito.MockitoMatchers.anyObject(MockitoMatchers.scala:49)
at org.specs2.mock.mockito.MockitoMatchers.anyObject$(MockitoMatchers.scala:49)
at workflow.ProcessAG2WorkflowSpec.anyObject(ProcessAG2WorkflowSpec.scala:25)
at workflow.ProcessAG2WorkflowSpec$$anon.delayedEndpoint$workflow$ProcessAG2WorkflowSpec$$anon(ProcessAG2WorkflowSpec.scala:36)
at workflow.ProcessAG2WorkflowSpec$$anon$delayedInit$body.apply(ProcessAG2WorkflowSpec.scala:31)
at scala.Function0.apply$mcV$sp(Function0.scala:34)
at scala.Function0.apply$mcV$sp$(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at org.specs2.mutable.Around.$anonfun$delayedInit(Around.scala:16)
at org.specs2.execute.ResultExecution.execute(ResultExecution.scala:22)
at org.specs2.execute.ResultExecution.execute$(ResultExecution.scala:21)
at org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:123)
at org.specs2.execute.Result$$anon.asResult(Result.scala:246)
at org.specs2.execute.AsResult$.apply(AsResult.scala:32)
at org.specs2.execute.AsResult$.$anonfun$effectively(AsResult.scala:36)
at org.specs2.execute.ResultExecution.effectively(ResultExecution.scala:42)
at org.specs2.execute.ResultExecution.effectively$(ResultExecution.scala:40)
at org.specs2.execute.ResultExecution$.effectively(ResultExecution.scala:123)
at org.specs2.execute.AsResult$.effectively(AsResult.scala:36)
at play.api.test.WithApplicationLoader.$anonfun$around(Specs.scala:30)
at play.api.test.PlayRunners.$anonfun$running(Helpers.scala:75)
at play.api.test.PlayRunners.runSynchronized(Helpers.scala:52)
at play.api.test.PlayRunners.runSynchronized$(Helpers.scala:48)
at play.api.test.Helpers$.runSynchronized(Helpers.scala:617)
at play.api.test.PlayRunners.running(Helpers.scala:73)
at play.api.test.PlayRunners.running$(Helpers.scala:71)
at play.api.test.Helpers$.running(Helpers.scala:617)
at play.api.test.WithApplicationLoader.around(Specs.scala:30)
at de.mycompany.commons.play.specs2.BaseSpecs2$WithTestApplication.around(BaseSpecs2.scala:74)
at org.specs2.mutable.Around.$anonfun$delayedInit(Around.scala:16)
at org.specs2.execute.ResultExecution.effectively(ResultExecution.scala:42)
at org.specs2.execute.ResultExecution.effectively$(ResultExecution.scala:40)
at org.specs2.execute.ResultExecution$.effectively(ResultExecution.scala:123)
at org.specs2.mutable.Around.delayedInit(Around.scala:16)
at org.specs2.mutable.Around.delayedInit$(Around.scala:15)
at play.api.test.WithApplicationLoader.delayedInit(Specs.scala:27)
at workflow.ProcessAG2WorkflowSpec$$anon.<init>(ProcessAG2WorkflowSpec.scala:31)
at workflow.ProcessAG2WorkflowSpec.$anonfun$new(ProcessAG2WorkflowSpec.scala:31)
at org.specs2.matcher.Scope$$anon.$anonfun$asResult(ThrownExpectations.scala:152)
at org.specs2.execute.ResultExecution.execute(ResultExecution.scala:22)
at org.specs2.execute.ResultExecution.execute$(ResultExecution.scala:21)
at org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:123)
at org.specs2.execute.Result$$anon.asResult(Result.scala:246)
at org.specs2.execute.AsResult$.apply(AsResult.scala:32)
at org.specs2.execute.AsResult$.$anonfun$safely(AsResult.scala:40)
at org.specs2.execute.ResultExecution.execute(ResultExecution.scala:22)
at org.specs2.execute.ResultExecution.execute$(ResultExecution.scala:21)
at org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:123)
at org.specs2.execute.AsResult$.safely(AsResult.scala:40)
at org.specs2.matcher.Scope$$anon.asResult(ThrownExpectations.scala:152)
at org.specs2.execute.AsResult$.apply(AsResult.scala:32)
at org.specs2.specification.core.AsExecution$$anon.$anonfun$execute(AsExecution.scala:17)
at org.specs2.execute.ResultExecution.execute(ResultExecution.scala:22)
at org.specs2.execute.ResultExecution.execute$(ResultExecution.scala:21)
at org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:123)
at org.specs2.execute.Result$$anon.asResult(Result.scala:246)
at org.specs2.execute.AsResult$.apply(AsResult.scala:32)
at org.specs2.execute.AsResult$.$anonfun$safely(AsResult.scala:40)
at org.specs2.execute.ResultExecution.execute(ResultExecution.scala:22)
at org.specs2.execute.ResultExecution.execute$(ResultExecution.scala:21)
at org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:123)
at org.specs2.execute.AsResult$.safely(AsResult.scala:40)
at org.specs2.specification.core.Execution$.$anonfun$result(Execution.scala:310)
at org.specs2.specification.core.Execution$.$anonfun$withEnvSync(Execution.scala:328)
at org.specs2.execute.ResultExecution.execute(ResultExecution.scala:22)
at org.specs2.execute.ResultExecution.execute$(ResultExecution.scala:21)
at org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:123)
at org.specs2.execute.Result$$anon.asResult(Result.scala:246)
at org.specs2.execute.AsResult$.apply(AsResult.scala:32)
at org.specs2.execute.AsResult$.$anonfun$safely(AsResult.scala:40)
at org.specs2.execute.ResultExecution.execute(ResultExecution.scala:22)
at org.specs2.execute.ResultExecution.execute$(ResultExecution.scala:21)
at org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:123)
at org.specs2.execute.AsResult$.safely(AsResult.scala:40)
at org.specs2.specification.core.Execution$.$anonfun$withEnvSync(Execution.scala:328)
at org.specs2.execute.ResultExecution.execute(ResultExecution.scala:22)
at org.specs2.execute.ResultExecution.execute$(ResultExecution.scala:21)
at org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:123)
at org.specs2.execute.Result$$anon.asResult(Result.scala:246)
at org.specs2.execute.AsResult$.apply(AsResult.scala:32)
at org.specs2.specification.Before.$anonfun$apply(Context.scala:43)
at org.specs2.execute.ResultExecution.executeEither(ResultExecution.scala:92)
at org.specs2.execute.ResultExecution.executeEither$(ResultExecution.scala:81)
at org.specs2.execute.ResultExecution$.executeEither(ResultExecution.scala:123)
at org.specs2.execute.ResultExecution.execute(ResultExecution.scala:73)
at org.specs2.execute.ResultExecution.execute$(ResultExecution.scala:73)
at org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:123)
at org.specs2.specification.Before.apply(Context.scala:43)
at org.specs2.specification.Before.apply$(Context.scala:42)
at org.specs2.specification.BeforeAfter.result$lzycompute(Context.scala:102)
at org.specs2.specification.BeforeAfter.result(Context.scala:102)
at org.specs2.specification.BeforeAfter.$anonfun$apply(Context.scala:103)
at org.specs2.execute.ResultExecution.execute(ResultExecution.scala:22)
at org.specs2.execute.ResultExecution.execute$(ResultExecution.scala:21)
at org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:123)
at org.specs2.execute.Result$$anon.asResult(Result.scala:246)
at org.specs2.execute.AsResult$.apply(AsResult.scala:32)
at org.specs2.specification.After.apply(Context.scala:78)
at org.specs2.specification.After.apply$(Context.scala:77)
at org.specs2.specification.BeforeAfter.apply(Context.scala:103)
at org.specs2.specification.BeforeAfter.apply$(Context.scala:101)
at org.specs2.specification.BeforeAfterEach$$anon.apply(EachContext.scala:52)
at org.specs2.specification.create.ContextualFragmentFactory.$anonfun$example(FragmentFactory.scala:106)
at org.specs2.specification.core.Execution.$anonfun$startExecution(Execution.scala:136)
at scala.util.Success.$anonfun$map(Try.scala:251)
at scala.util.Success.map(Try.scala:209)
at scala.concurrent.Future.$anonfun$map(Future.scala:288)
at scala.concurrent.impl.Promise.liftedTree1(Promise.scala:29)
at scala.concurrent.impl.Promise.$anonfun$transform(Promise.scala:29)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

项目设置如下:有一个基础项目作为specs2和其他播放功能的依赖。基础项目是 libraryDependency 到带有 NoSuchMethodError 的项目。

相同的设置适用于使用 specs2 但不使用 Mockito 的其他项目。 Specs2 和 Mockito(所有和核心)都存在。

非工作项目中的依赖项:

sbt: org.mockito:mockito-all:1.10.8:jar
sbt: org.mockito:mockito-core:2.23.4:jar
sbt: org.specs2:specs2-common_2.12:4.3.6:jar
sbt: org.specs2:specs2-core_2.12:4.3.6:jar
sbt: org.specs2:specs2-fp_2.12:4.3.6:jar
sbt: org.specs2:specs2-junit_2.12:4.3.6:jar
sbt: org.specs2:specs2-matcher_2.12:4.3.6:jar
sbt: org.specs2:specs2-mock_2.12:4.3.6:jar
sbt: com.typesafe.play:play-specs2_2.12:2.7.0

specs2 所需的唯一 mockito 依赖项是 mockito-core。您应该删除必须通过另一个依赖项将其引入项目的 mockito-all 。您可以使用 sbt-dependency-graph 插件进行调查。

我遇到这个错误是因为我项目的 pom.xml 文件引用的是 Mockito v1 而不是 Mockito v2。