From bb5d373d6b0543bf4258f0b3690ce08fc6a665eb Mon Sep 17 00:00:00 2001 From: Gosha Kovalyov <134854076+goshacodes@users.noreply.github.com> Date: Tue, 13 Feb 2024 12:37:09 +0600 Subject: [PATCH] Scala 3 (#490) * prepare build for scala 3 * resolve warnings for scala 3 * changed 2.13.8 to 2.13.11 * remove 2.11 and move scala-2 macro to scala-2 directory * fix crossScalaVersions and tests * tests prepared for scala 3 * mocks reimplemented with scala 3 * restricted vars support * java workaround * fix path dependent types in type constructors * add scala 3 to workflow; remove scala_2.11 * Update build.sbt Co-authored-by: Seth Tisue * Update .github/workflows/scala.yml Co-authored-by: Seth Tisue * add comment about scala 3.3.0 * review fixes * return java 11 in pipeline * review fixes --------- Co-authored-by: Seth Tisue --- .github/workflows/scala.yml | 28 +-- README.md | 50 ++++- build.sbt | 52 +++-- .../scala/com/example/ControllerTest.scala | 6 +- .../example/HigherOrderFunctionsTest.scala | 14 +- .../com/example/OrderSpecification.scala | 6 +- .../test/scala/com/example/OrderTest.scala | 4 +- .../com/example/ReallySimpleExampleTest.scala | 6 +- .../example/mockitostyle/ControllerTest.scala | 6 +- .../HigherOrderFunctionsTest.scala | 20 +- .../com/example/mockitostyle/OrderTest.scala | 2 +- .../clazz/MockFunctionFinderImpl.scala | 0 .../clazz/MockFunctionFinderImpl.scala | 0 .../test/mock/ByNameParametersTest.scala | 31 +++ .../scala-3/mock/ByNameParametersTest.scala | 34 +++ .../mock/JavaMocksTest.scala | 104 +++++----- .../proxy/ProxyMockManyParamsTest.scala | 44 ++-- .../proxy/ProxyMockTest.scala | 89 ++++---- .../test/scalatest/MixedMockFactoryTest.scala | 4 +- .../scalatest/SuiteScopeProxyMockTest.scala | 6 +- project/plugins.sbt | 2 +- .../org/scalamock/clazz/Mock.scala | 0 .../scalamock/clazz/MockFunctionFinder.scala | 2 +- .../org/scalamock/clazz/MockImpl.scala | 0 .../org/scalamock/clazz/MockMaker.scala | 3 +- .../scalamock/proxy/ProxyMockFactory.scala | 0 .../org/scalamock/util/MacroAdapter.scala | 0 .../org/scalamock/util/MacroUtils.scala | 2 +- .../scala-3/org/scalamock/clazz/Mock.scala | 85 ++++++++ .../scalamock/clazz/MockFunctionFinder.scala | 68 ++++++ .../org/scalamock/clazz/MockImpl.scala | 184 +++++++++++++++++ .../org/scalamock/clazz/MockMaker.scala | 193 ++++++++++++++++++ .../org/scalamock/clazz/MockType.scala | 4 + .../scala-3/org/scalamock/clazz/Utils.scala | 143 +++++++++++++ .../scalamock/proxy/ProxyMockFactory.scala | 46 +++++ .../scala/org/scalamock/MockFactoryBase.scala | 2 +- .../org/scalamock/function/MockFunction.scala | 92 ++++----- .../scalamock/function/MockFunctions.scala | 4 +- .../org/scalamock/function/StubFunction.scala | 92 ++++----- .../org/scalamock/handlers/Handlers.scala | 2 +- .../org/scalamock/matchers/ArgAssert.scala | 2 +- .../org/scalamock/matchers/Matchers.scala | 16 +- .../scalamock/matchers/MockParameter.scala | 4 +- .../org/scalamock/proxy/FakeFunction.scala | 3 +- .../proxy/InvocationHandlerBase.scala | 6 +- .../proxy/MockInvocationHandler.scala | 2 +- .../org/scalamock/proxy/StubFunction.scala | 2 +- .../proxy/StubInvocationHandler.scala | 4 +- .../scalatest/AsyncMockFactoryBase.scala | 2 +- .../org/scalamock/util/Defaultable.scala | 2 +- .../PolymorphicTrait.scala | 0 .../com.paulbutcher.test/VarSpec.scala | 26 +++ .../paulbutcher/test/PolymorphicTrait.scala | 37 ++++ .../com/paulbutcher/test/Scala3Spec.scala | 42 ++++ .../com/paulbutcher/test/VarSpec.scala | 19 ++ .../paulbutcher/test/SpecializedClass.scala | 2 +- .../paulbutcher/test/SpecializedClass2.scala | 2 +- .../com/paulbutcher/test/TestTrait.scala | 7 +- .../test/features/CallCountTest.scala | 21 +- .../test/features/OrderingTest.scala | 22 +- .../test/features/ReturnTest.scala | 14 +- .../paulbutcher/test/features/ThrowTest.scala | 2 +- .../test/matchers/MatchEpsilonTest.scala | 16 +- .../test/matchers/MatchersTest.scala | 26 +-- .../test/matchers/MockParameterTest.scala | 6 +- .../test/mock/MockNamingTest.scala | 6 +- .../com/paulbutcher/test/mock/MockTest.scala | 76 +++---- .../test/mock/OverloadedMethodsTest.scala | 4 +- .../test/stub/StubFunctionTest.scala | 38 ++-- .../test/stub/StubNamingTest.scala | 4 +- .../com/paulbutcher/test/stub/StubTest.scala | 6 +- .../jstests/matchers/MatchEpsilonTest.scala | 16 +- .../test/scalatest/AsyncSyncMixinTest.scala | 12 +- .../test/scalatest/StackableSuitesTest.scala | 2 +- 74 files changed, 1426 insertions(+), 453 deletions(-) rename js/src/main/{scala => scala-2}/org/scalamock/clazz/MockFunctionFinderImpl.scala (100%) rename jvm/src/main/{scala => scala-2}/org/scalamock/clazz/MockFunctionFinderImpl.scala (100%) create mode 100644 jvm/src/test/scala-2/com/paulbutcher/test/mock/ByNameParametersTest.scala create mode 100644 jvm/src/test/scala-3/mock/ByNameParametersTest.scala rename shared/src/main/{scala => scala-2}/org/scalamock/clazz/Mock.scala (100%) rename shared/src/main/{scala => scala-2}/org/scalamock/clazz/MockFunctionFinder.scala (100%) rename shared/src/main/{scala => scala-2}/org/scalamock/clazz/MockImpl.scala (100%) rename shared/src/main/{scala => scala-2}/org/scalamock/clazz/MockMaker.scala (99%) rename shared/src/main/{scala => scala-2}/org/scalamock/proxy/ProxyMockFactory.scala (100%) rename shared/src/main/{scala => scala-2}/org/scalamock/util/MacroAdapter.scala (100%) rename shared/src/main/{scala => scala-2}/org/scalamock/util/MacroUtils.scala (98%) create mode 100644 shared/src/main/scala-3/org/scalamock/clazz/Mock.scala create mode 100644 shared/src/main/scala-3/org/scalamock/clazz/MockFunctionFinder.scala create mode 100644 shared/src/main/scala-3/org/scalamock/clazz/MockImpl.scala create mode 100644 shared/src/main/scala-3/org/scalamock/clazz/MockMaker.scala create mode 100644 shared/src/main/scala-3/org/scalamock/clazz/MockType.scala create mode 100644 shared/src/main/scala-3/org/scalamock/clazz/Utils.scala create mode 100644 shared/src/main/scala-3/org/scalamock/proxy/ProxyMockFactory.scala rename shared/src/test/{scala/com/paulbutcher/test => scala-2/com.paulbutcher.test}/PolymorphicTrait.scala (100%) create mode 100644 shared/src/test/scala-2/com.paulbutcher.test/VarSpec.scala create mode 100644 shared/src/test/scala-3/com/paulbutcher/test/PolymorphicTrait.scala create mode 100644 shared/src/test/scala-3/com/paulbutcher/test/Scala3Spec.scala create mode 100644 shared/src/test/scala-3/com/paulbutcher/test/VarSpec.scala diff --git a/.github/workflows/scala.yml b/.github/workflows/scala.yml index dd9099fb..a4ba01f5 100644 --- a/.github/workflows/scala.yml +++ b/.github/workflows/scala.yml @@ -7,20 +7,6 @@ on: branches: [ master ] jobs: - scala_2_11: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK - uses: actions/setup-java@v3 - with: - java-version: 11 - distribution: 'adopt' - - name: Run tests - run: sbt ++2.11.12 test - scala_2_12: runs-on: ubuntu-latest @@ -48,3 +34,17 @@ jobs: distribution: 'adopt' - name: Run tests run: sbt ++2.13.12 test + + scala_3: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK + uses: actions/setup-java@v3 + with: + java-version: 11 + distribution: 'adopt' + - name: Run tests + run: sbt ++3.3.0 test diff --git a/README.md b/README.md index 013583a3..a55b3ee7 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,9 @@ A more complete example is on our [Quickstart](http://scalamock.org/quick-start/ * Mock and Stub support * Macro Mocks and JVM Proxy Mocks * Scala.js support -* built for Scala 2.11, 2.12, 2.13 +* built for Scala 2.12, 2.13, 3 * Scala 2.10 support was included up to ScalaMock 4.2.0 +* Scala 2.11 support was included up to ScalaMock 5.2.0 ## Using ScalaMock @@ -70,6 +71,53 @@ libraryDependencies += Seq("org.scalamock" %% "scalamock" % "5.2.0" % Test, "org.scalatest" %% "scalatest" % "3.2.0" % Test) ``` +## Scala 3 Migration Notes + +1. Type should be specified for methods with by-name parameters +```scala 3 +trait TestTrait: + def byNameParam(x: => Int): String + +val t = mock[TestTrait] + +// this one no longer compiles +(t.byNameParam _).expects(*).returns("") + +// this one should be used instead +(t.byNameParam(_: Int)).expects(*).returns("") +``` + +2. +* Not initialized vars are not supported anymore, use `scala.compiletime.uninitialized` instead +* Vars are **not mockable** anymore + +```scala 3 +trait X: + var y: Int // No longer compiles + + var y: Int = scala.compile.uninitialized // Should be used instead +``` + + + Mocking of non-abstract java classes is not available without workaround + +```java +public class JavaClass { + public int simpleMethod(String b) { return 4; } +} + +``` + +```scala 3 +val m = mock[JavaClass] // No longer compiles + +class JavaClassExtended extends JavaClass + +val mm = mock[JavaClassExtended] // should be used instead +``` + + + ## Documentation For usage in Maven or Gradle, integration with Specs2, and more example examples see the [User Guide](http://scalamock.org/user-guide/) diff --git a/build.sbt b/build.sbt index a2b856ec..14a511e0 100644 --- a/build.sbt +++ b/build.sbt @@ -1,26 +1,20 @@ import sbtcrossproject.CrossPlugin.autoImport.crossProject -ThisBuild / scalaVersion := "2.11.12" -ThisBuild / crossScalaVersions := Seq("2.11.12", "2.12.18", "2.13.12") -//ThisBuild / scalaJSUseRhino := true - lazy val scalatest = Def.setting("org.scalatest" %%% "scalatest" % "3.2.17") -lazy val specs2 = Def.setting("org.specs2" %%% "specs2-core" % "4.10.6") +lazy val specs2 = Def.setting("org.specs2" %%% "specs2-core" % "4.20.2") val commonSettings = Defaults.coreDefaultSettings ++ Seq( - Compile / unmanagedSourceDirectories ++= { - CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2L, minor)) => - Some(baseDirectory.value.getParentFile / s"shared/src/main/scala-2.$minor") - case _ => - None - } - }, - scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-Xcheckinit", "-target:jvm-1.8") + /** + * Symbol.newClass is marked experimental, so we should use @experimental annotation in every test suite. + * 3.3.0 has a bug so we can omit this annotation + */ + scalaVersion := "3.3.0", + scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-release:8") ) lazy val scalamock = crossProject(JSPlatform, JVMPlatform) in file(".") settings( commonSettings, + crossScalaSettings, name := "scalamock", Compile / packageBin / publishArtifact := true, Compile / packageDoc / publishArtifact := true, @@ -29,17 +23,14 @@ lazy val scalamock = crossProject(JSPlatform, JVMPlatform) in file(".") settings Compile / doc / scalacOptions ++= Opts.doc.title("ScalaMock") ++ Opts.doc.version(version.value) ++ Seq("-doc-root-content", "rootdoc.txt", "-version"), libraryDependencies ++= Seq( - "org.scala-lang" % "scala-reflect" % scalaVersion.value, scalatest.value % Optional, specs2.value % Optional ) ) -lazy val `scalamock-js` = scalamock.js -lazy val `scalamock-jvm` = scalamock.jvm - lazy val examples = project in file("examples") settings( commonSettings, + crossScalaSettings, name := "ScalaMock Examples", publish / skip := true, libraryDependencies ++= Seq( @@ -47,3 +38,28 @@ lazy val examples = project in file("examples") settings( specs2.value % Test ) ) dependsOn scalamock.jvm + +def crossScalaSettings = { + def addDirsByScalaVersion(path: String): Def.Initialize[Seq[sbt.File]] = + scalaVersion.zip(baseDirectory) { case (v, base) => + CrossVersion.partialVersion(v) match { + case Some((v, _)) if Set(2L, 3L).contains(v) => + Seq(base / path / s"scala-$v") + case _ => + Seq.empty + } + } + Seq( + crossScalaVersions := Seq("2.12.18", "2.13.12", scalaVersion.value), + Compile / unmanagedSourceDirectories ++= addDirsByScalaVersion("src/main").value, + Test / unmanagedSourceDirectories ++= addDirsByScalaVersion("src/test").value, + libraryDependencies ++= { + CrossVersion.partialVersion(scalaVersion.value) match { + case Some((2, _)) => + Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value) + case _ => + Seq.empty + } + } + ) +} \ No newline at end of file diff --git a/examples/src/test/scala/com/example/ControllerTest.scala b/examples/src/test/scala/com/example/ControllerTest.scala index 9f31f69c..b6af5cff 100644 --- a/examples/src/test/scala/com/example/ControllerTest.scala +++ b/examples/src/test/scala/com/example/ControllerTest.scala @@ -34,12 +34,12 @@ class ControllerTest extends AnyFunSuite with MockFactory { inSequence { inAnyOrder { (() => mockTurtle.penUp()).expects() - (mockTurtle.getPosition _).expects().returning(0.0, 0.0) - (mockTurtle.getAngle _).expects().returning(0.0) + (() => mockTurtle.getPosition).expects().returning(0.0, 0.0) + (() => mockTurtle.getAngle).expects().returning(0.0) } (mockTurtle.turn _).expects(~(Pi / 4)) (mockTurtle.forward _).expects(~sqrt(2.0)) - (mockTurtle.getAngle _).expects().returning(Pi / 4) + (() => mockTurtle.getAngle).expects().returning(Pi / 4) (mockTurtle.turn _).expects(~(-Pi / 4)) (() => mockTurtle.penDown()).expects() (mockTurtle.forward _).expects(1.0) diff --git a/examples/src/test/scala/com/example/HigherOrderFunctionsTest.scala b/examples/src/test/scala/com/example/HigherOrderFunctionsTest.scala index ca43628c..20e74ed3 100644 --- a/examples/src/test/scala/com/example/HigherOrderFunctionsTest.scala +++ b/examples/src/test/scala/com/example/HigherOrderFunctionsTest.scala @@ -33,9 +33,9 @@ class HigherOrderFunctionsTest extends AnyFreeSpec with MockFactory { val f = mockFunction[Int, String] inSequence { - f expects (1) returning "one" once; - f expects (2) returning "two" once; - f expects (3) returning "three" once; + f.expects(1).returning("one").once(); + f.expects(2).returning("two").once(); + f.expects(3).returning("three").once(); } assertResult(Seq("one", "two", "three")) { @@ -61,10 +61,10 @@ class HigherOrderFunctionsTest extends AnyFreeSpec with MockFactory { val f = mockFunction[String, Int, String] inSequence { - f expects("initial", 0) returning "intermediate one" once; - f expects("intermediate one", 1) returning "intermediate two" once; - f expects("intermediate two", 2) returning "intermediate three" once; - f expects("intermediate three", 3) returning "final" once; + f.expects("initial", 0).returning("intermediate one").once(); + f.expects("intermediate one", 1).returning("intermediate two"). once(); + f.expects("intermediate two", 2).returning("intermediate three").once(); + f.expects("intermediate three", 3).returning("final").once(); } assertResult("final") { diff --git a/examples/src/test/scala/com/example/OrderSpecification.scala b/examples/src/test/scala/com/example/OrderSpecification.scala index fa9e9629..73174945 100644 --- a/examples/src/test/scala/com/example/OrderSpecification.scala +++ b/examples/src/test/scala/com/example/OrderSpecification.scala @@ -33,8 +33,8 @@ class OrderSpecification extends Specification { "remove inventory when in stock" in new MockContext { val mockWarehouse = mock[Warehouse] inSequence { - (mockWarehouse.hasInventory _).expects("Talisker", 50).returning(true).once - (mockWarehouse.remove _).expects("Talisker", 50).once + (mockWarehouse.hasInventory _).expects("Talisker", 50).returning(true).once() + (mockWarehouse.remove _).expects("Talisker", 50).once() } val order = new Order("Talisker", 50) order.fill(mockWarehouse) @@ -43,7 +43,7 @@ class OrderSpecification extends Specification { "remove nothing when out of stock" in new MockContext { val mockWarehouse = mock[Warehouse] - (mockWarehouse.hasInventory _).expects(*, *).returns(false).once + (mockWarehouse.hasInventory _).expects(*, *).returns(false).once() val order = new Order("Talisker", 50) order.fill(mockWarehouse) order.isFilled must beFalse diff --git a/examples/src/test/scala/com/example/OrderTest.scala b/examples/src/test/scala/com/example/OrderTest.scala index 35be621a..60789228 100644 --- a/examples/src/test/scala/com/example/OrderTest.scala +++ b/examples/src/test/scala/com/example/OrderTest.scala @@ -33,8 +33,8 @@ class OrderTest extends AnyWordSpec with MockFactory { "remove inventory" in { val mockWarehouse = mock[Warehouse] inSequence { - (mockWarehouse.hasInventory _) expects ("Talisker", 50) returning true - (mockWarehouse.remove _) expects ("Talisker", 50) once + (mockWarehouse.hasInventory _).expects ("Talisker", 50).returning(true) + (mockWarehouse.remove _).expects("Talisker", 50).once() } val order = new Order("Talisker", 50) diff --git a/examples/src/test/scala/com/example/ReallySimpleExampleTest.scala b/examples/src/test/scala/com/example/ReallySimpleExampleTest.scala index 5c84f16d..6063bfab 100644 --- a/examples/src/test/scala/com/example/ReallySimpleExampleTest.scala +++ b/examples/src/test/scala/com/example/ReallySimpleExampleTest.scala @@ -47,7 +47,7 @@ class ReallySimpleExampleTest extends AnyFunSuite with MockFactory { test("WithVariableParameters") { val australianFormat = mock[Formatter] - (australianFormat.format _).expects(*).onCall { s: String => s"G'day $s" }.twice() + (australianFormat.format _).expects(*).onCall { (s: String) => s"G'day $s" }.twice() Greetings.sayHello("Wendy", australianFormat) Greetings.sayHello("Gray", australianFormat) @@ -62,10 +62,10 @@ class ReallySimpleExampleTest extends AnyFunSuite with MockFactory { } // argAssert fails early - (formatter.format _).expects(argAssert(assertTeamNatsu _)).onCall { s: String => s"Yo $s" }.once() + (formatter.format _).expects(argAssert(assertTeamNatsu _)).onCall { (s: String) => s"Yo $s" }.once() // 'where' verifies at the end of the test - (formatter.format _).expects(where { s: String => teamNatsu contains(s) }).onCall { s: String => s"Yo $s" }.twice() + (formatter.format _).expects(where { (s: String) => teamNatsu contains(s) }).onCall { (s: String) => s"Yo $s" }.twice() Greetings.sayHello("Carla", formatter) Greetings.sayHello("Happy", formatter) diff --git a/examples/src/test/scala/com/example/mockitostyle/ControllerTest.scala b/examples/src/test/scala/com/example/mockitostyle/ControllerTest.scala index 93c81024..9579a7a5 100644 --- a/examples/src/test/scala/com/example/mockitostyle/ControllerTest.scala +++ b/examples/src/test/scala/com/example/mockitostyle/ControllerTest.scala @@ -35,10 +35,10 @@ class ControllerTest extends AnyFunSuite with MockFactory { inSequence { inAnyOrder { - (mockTurtle.getPosition _).when().returns(0.0, 0.0) - (mockTurtle.getAngle _).when().returns(0.0).once() + (() => mockTurtle.getPosition).when().returns(0.0, 0.0) + (() => mockTurtle.getAngle).when().returns(0.0).once() } - (mockTurtle.getAngle _).when().returns(Pi / 4) + (() => mockTurtle.getAngle).when().returns(Pi / 4) } controller.drawLine((1.0, 1.0), (2.0, 1.0)) diff --git a/examples/src/test/scala/com/example/mockitostyle/HigherOrderFunctionsTest.scala b/examples/src/test/scala/com/example/mockitostyle/HigherOrderFunctionsTest.scala index ccf1e1e0..cfdfdd96 100644 --- a/examples/src/test/scala/com/example/mockitostyle/HigherOrderFunctionsTest.scala +++ b/examples/src/test/scala/com/example/mockitostyle/HigherOrderFunctionsTest.scala @@ -31,18 +31,18 @@ class HigherOrderFunctionsTest extends AnyFreeSpec with MockFactory { "testMap" in { val f = stubFunction[Int, String] - f when (1) returns "one" - f when (2) returns "two" - f when (3) returns "three" + f.when(1).returns("one") + f.when(2).returns("two") + f.when(3).returns("three") assertResult(Seq("one", "two", "three")) { Seq(1, 2, 3) map f } inSequence { - f verify (1) once; - f verify (2) once; - f verify (3) once; + f.verify(1).once(); + f.verify(2).once(); + f.verify(3).once(); } } @@ -74,10 +74,10 @@ class HigherOrderFunctionsTest extends AnyFreeSpec with MockFactory { } inSequence { - f verify("initial", 0) once; - f verify("intermediate one", 1) once; - f verify("intermediate two", 2) once; - f verify("intermediate three", 3) once; + f.verify("initial", 0).once(); + f.verify("intermediate one", 1).once(); + f.verify("intermediate two", 2).once(); + f.verify("intermediate three", 3).once(); } } } diff --git a/examples/src/test/scala/com/example/mockitostyle/OrderTest.scala b/examples/src/test/scala/com/example/mockitostyle/OrderTest.scala index 8da7cb72..eefe9432 100644 --- a/examples/src/test/scala/com/example/mockitostyle/OrderTest.scala +++ b/examples/src/test/scala/com/example/mockitostyle/OrderTest.scala @@ -40,7 +40,7 @@ class OrderTest extends AnyWordSpec with MockFactory { order.fill(mockWarehouse) assert(order.isFilled) - (mockWarehouse.remove _) verify ("Talisker", 50) once + (mockWarehouse.remove _).verify("Talisker", 50).once() } } diff --git a/js/src/main/scala/org/scalamock/clazz/MockFunctionFinderImpl.scala b/js/src/main/scala-2/org/scalamock/clazz/MockFunctionFinderImpl.scala similarity index 100% rename from js/src/main/scala/org/scalamock/clazz/MockFunctionFinderImpl.scala rename to js/src/main/scala-2/org/scalamock/clazz/MockFunctionFinderImpl.scala diff --git a/jvm/src/main/scala/org/scalamock/clazz/MockFunctionFinderImpl.scala b/jvm/src/main/scala-2/org/scalamock/clazz/MockFunctionFinderImpl.scala similarity index 100% rename from jvm/src/main/scala/org/scalamock/clazz/MockFunctionFinderImpl.scala rename to jvm/src/main/scala-2/org/scalamock/clazz/MockFunctionFinderImpl.scala diff --git a/jvm/src/test/scala-2/com/paulbutcher/test/mock/ByNameParametersTest.scala b/jvm/src/test/scala-2/com/paulbutcher/test/mock/ByNameParametersTest.scala new file mode 100644 index 00000000..fbed5ef1 --- /dev/null +++ b/jvm/src/test/scala-2/com/paulbutcher/test/mock/ByNameParametersTest.scala @@ -0,0 +1,31 @@ +package com.paulbutcher.test.mock + +import com.paulbutcher.test.TestTrait +import org.scalamock.function.FunctionAdapter1 +import org.scalatest.matchers.should.Matchers +import org.scalamock.scalatest.MockFactory +import org.scalatest.freespec.AnyFreeSpec + +class ByNameParametersTest extends AnyFreeSpec with MockFactory with Matchers { + + autoVerify = false + + "cope with methods with by name parameters" in { + withExpectations { + val m = mock[TestTrait] + (m.byNameParam _).expects(*).returning("it worked") + assertResult("it worked") { m.byNameParam(42) } + } + } + + //! TODO - find a way to make this less ugly + "match methods with by name parameters" in { + withExpectations { + val m = mock[TestTrait] + val f: (=> Int) => Boolean = { x => x == 1 && x == 2 } + ((m.byNameParam _): (=> Int) => String).expects(new FunctionAdapter1(f)).returning("it works") + var y = 0 + assertResult("it works") { m.byNameParam { y += 1; y } } + } + } +} diff --git a/jvm/src/test/scala-3/mock/ByNameParametersTest.scala b/jvm/src/test/scala-3/mock/ByNameParametersTest.scala new file mode 100644 index 00000000..75ca482f --- /dev/null +++ b/jvm/src/test/scala-3/mock/ByNameParametersTest.scala @@ -0,0 +1,34 @@ +package mock + +import com.paulbutcher.test.TestTrait +import org.scalamock.scalatest.MockFactory +import org.scalatest.funspec.AnyFunSpec +import org.scalatest.matchers.should.Matchers + +class ByNameParametersTest extends AnyFunSpec with MockFactory with Matchers { + + autoVerify = false + + it("cope with methods with by name parameters") { + withExpectations { + val m = mock[TestTrait] + (m.byNameParam(_: Int)).expects(*).returning("it worked") + assertResult("it worked") { + m.byNameParam(42) + } + } + } + + it("match methods with by name parameters") { + withExpectations { + val m = mock[TestTrait] + (m.byNameParam(_: Int)).expects(where[Int](Set(1, 2))).returning("it works") + var y = 0 + assertResult("it works") { + m.byNameParam { + y += 1; y + } + } + } + } +} diff --git a/jvm/src/test/scala/com.paulbutcher.test/mock/JavaMocksTest.scala b/jvm/src/test/scala/com.paulbutcher.test/mock/JavaMocksTest.scala index 3ab3bbeb..a4a6dd6f 100644 --- a/jvm/src/test/scala/com.paulbutcher.test/mock/JavaMocksTest.scala +++ b/jvm/src/test/scala/com.paulbutcher.test/mock/JavaMocksTest.scala @@ -32,20 +32,21 @@ class JavaMocksTest extends IsolatedSpec { m.simpleMethod("two") shouldBe 42 } - it should "mock classes with bridged methods" in { - val m = mock[JavaClassWithBridgeMethod] - - (m.compare _).expects(Integer.valueOf(5)).returning(1) - (m.compare _).expects(Integer.valueOf(6)).returning(2) - - def useBridgeMethod[T](gen: JavaGenericInterface[T], x: T) = { - gen.compare(x) + it should "mock classes with bridged methods" in { + class JavaClassWithBridgeMethodExtended extends JavaClassWithBridgeMethod + val m = mock[JavaClassWithBridgeMethodExtended] + + (m.compare _).expects(Integer.valueOf(5)).returning(1) + (m.compare _).expects(Integer.valueOf(6)).returning(2) + + def useBridgeMethod[T](gen: JavaGenericInterface[T], x: T) = { + gen.compare(x) + } + + assertResult(1) { m.compare(Integer.valueOf(5)) } // calls: int compare(Integer) + assertResult(2) { useBridgeMethod(m, Integer.valueOf(6)) } // calls: int compare(Object) } - assertResult(1) { m.compare(Integer.valueOf(5)) } // calls: int compare(Integer) - assertResult(2) { useBridgeMethod(m, Integer.valueOf(6)) } // calls: int compare(Object) - } - //! TODO - this is going to have to wait for macro types for a proper solution // "cope with Java methods with repeated parameters" in { // withExpectations { @@ -61,11 +62,11 @@ class JavaMocksTest extends IsolatedSpec { assertResult("a return value") { m.m(42, "foo") } } - it should "mock a Polymorhpic Java interface" in { // test for issue #24 - val m = mock[PolymorphicJavaInterface] - (m.simplePolymorphicMethod _).expects("foo").returning(44) - assertResult(44) { m.simplePolymorphicMethod("foo") } - } + it should "mock a Polymorhpic Java interface" in { // test for issue #24 + val m = mock[PolymorphicJavaInterface] + (m.simplePolymorphicMethod _).expects("foo").returning(44) + assertResult(44) { m.simplePolymorphicMethod[Int]("foo") } + } it should "mock a Polymorhpic Java interface (type parametrized method parameter)" in { val m = mock[PolymorphicJavaInterface] @@ -75,41 +76,52 @@ class JavaMocksTest extends IsolatedSpec { m.polymorphicMethod(arg) shouldBe "foo" } - it should "mock a Java class with an overloaded method (different param count)" in { // test for issue #34 - val m = mock[JavaClassWithOverloadedMethod] - (m.overloadedMethod(_: String)).expects("a").returning("first") - (m.overloadedMethod(_: String, _: String)).expects("a", "b").returning("second") + it should "mock a Java class with an overloaded method (different param count)" in { // test for issue #34 + class JavaClassWithOverloadedMethodExtended extends JavaClassWithOverloadedMethod - m.overloadedMethod("a") shouldBe "first" - m.overloadedMethod("a", "b") shouldBe "second" - } + val m = mock[JavaClassWithOverloadedMethodExtended] + (m.overloadedMethod(_: String)).expects("a").returning("first") + (m.overloadedMethod(_: String, _: String)).expects("a", "b").returning("second") + + m.overloadedMethod("a") shouldBe "first" + m.overloadedMethod("a", "b") shouldBe "second" + } + + it should "mock a Java class with an overloaded method (the same param count)" in { // test for issue #73 + class JavaClassWithOverloadedMethodExtended extends JavaClassWithOverloadedMethod + + val m = mock[JavaClassWithOverloadedMethodExtended] + (m.overloadedSameParamCount(_: String)).expects("one").returning("first") + (m.overloadedSameParamCount(_: Integer)).expects(Integer.valueOf(2)).returning(2) + + m.overloadedSameParamCount("one") shouldBe "first" + m.overloadedSameParamCount(2) shouldBe 2 + } - it should "mock a Java class with an overloaded method (the same param count)" in { // test for issue #73 - val m = mock[JavaClassWithOverloadedMethod] - (m.overloadedSameParamCount(_: String)).expects("one").returning("first") - (m.overloadedSameParamCount(_: Integer)).expects(Integer.valueOf(2)).returning(2) - m.overloadedSameParamCount("one") shouldBe "first" - m.overloadedSameParamCount(2) shouldBe 2 - } + it should "mock a Java class with an overloaded method (with primitive param)" in { // test for issue #73 + class JavaClassWithOverloadedMethodExtended extends JavaClassWithOverloadedMethod - it should "mock a Java class with an overloaded method (with primitive param)" in { // test for issue #73 - val m = mock[JavaClassWithOverloadedMethod] - (m.overloadedWithPrimitiveParam(_: String)).expects("one").returning("first") - (m.overloadedWithPrimitiveParam(_: Int)).expects(2).returning("second") + val m = mock[JavaClassWithOverloadedMethodExtended] - m.overloadedWithPrimitiveParam("one") shouldBe "first" - m.overloadedWithPrimitiveParam(2) shouldBe "second" - } + (m.overloadedWithPrimitiveParam(_: String)).expects("one").returning("first") + (m.overloadedWithPrimitiveParam(_: Int)).expects(2).returning("second") + + m.overloadedWithPrimitiveParam("one") shouldBe "first" + m.overloadedWithPrimitiveParam(2) shouldBe "second" + } - it should "mock a Java class with an overloaded method (with type params)" in { - val m = mock[JavaClassWithOverloadedMethod] - (m.overloadedGeneric(_: String)).expects("one").returning("first") - (m.overloadedGeneric(_: Int)).expects(2).returning("second") - m.overloadedGeneric("one") shouldBe "first" - m.overloadedGeneric(2) shouldBe "second" - } + it should "mock a Java class with an overloaded method (with type params)" in { + class JavaClassWithOverloadedMethodExtended extends JavaClassWithOverloadedMethod + + val m = mock[JavaClassWithOverloadedMethodExtended] + (m.overloadedGeneric(_: String)).expects("one").returning("first") + (m.overloadedGeneric(_: Integer)).expects(Integer.valueOf(2)).returning("second") + + m.overloadedGeneric("one") shouldBe "first" + m.overloadedGeneric(2) shouldBe "second" + } override def newInstance = new JavaMocksTest -} +} \ No newline at end of file diff --git a/jvm/src/test/scala/com.paulbutcher.test/proxy/ProxyMockManyParamsTest.scala b/jvm/src/test/scala/com.paulbutcher.test/proxy/ProxyMockManyParamsTest.scala index c14c7510..3b6149ea 100644 --- a/jvm/src/test/scala/com.paulbutcher.test/proxy/ProxyMockManyParamsTest.scala +++ b/jvm/src/test/scala/com.paulbutcher.test/proxy/ProxyMockManyParamsTest.scala @@ -32,70 +32,70 @@ class ProxyMockManyParamsTest extends AnyFreeSpec with MockFactory { "allow expectations to be set on methods with many parameters" in withExpectations { val m = mock[ManyParamsTrait] - m.expects('methodWith1Ints)(1).returning(99) + m.expects(Symbol("methodWith1Ints"))(1).returning(99) assertResult(99) { m.methodWith1Ints(1) } - m.expects('methodWith2Ints)(1,1).returning(98) + m.expects(Symbol("methodWith2Ints"))(1,1).returning(98) assertResult(98) { m.methodWith2Ints(1,1) } - m.expects('methodWith3Ints)(1,1,1).returning(97) + m.expects(Symbol("methodWith3Ints"))(1,1,1).returning(97) assertResult(97) { m.methodWith3Ints(1,1,1) } - m.expects('methodWith4Ints)(1,1,1,1).returning(96) + m.expects(Symbol("methodWith4Ints"))(1,1,1,1).returning(96) assertResult(96) { m.methodWith4Ints(1,1,1,1) } - m.expects('methodWith5Ints)(1,1,1,1,1).returning(95) + m.expects(Symbol("methodWith5Ints"))(1,1,1,1,1).returning(95) assertResult(95) { m.methodWith5Ints(1,1,1,1,1) } - m.expects('methodWith6Ints)(1,1,1,1,1,1).returning(94) + m.expects(Symbol("methodWith6Ints"))(1,1,1,1,1,1).returning(94) assertResult(94) { m.methodWith6Ints(1,1,1,1,1,1) } - m.expects('methodWith7Ints)(1,1,1,1,1,1,1).returning(93) + m.expects(Symbol("methodWith7Ints"))(1,1,1,1,1,1,1).returning(93) assertResult(93) { m.methodWith7Ints(1,1,1,1,1,1,1) } - m.expects('methodWith8Ints)(1,1,1,1,1,1,1,1).returning(92) + m.expects(Symbol("methodWith8Ints"))(1,1,1,1,1,1,1,1).returning(92) assertResult(92) { m.methodWith8Ints(1,1,1,1,1,1,1,1) } - m.expects('methodWith9Ints)(1,1,1,1,1,1,1,1,1).returning(91) + m.expects(Symbol("methodWith9Ints"))(1,1,1,1,1,1,1,1,1).returning(91) assertResult(91) { m.methodWith9Ints(1,1,1,1,1,1,1,1,1) } - m.expects('methodWith10Ints)(1,1,1,1,1,1,1,1,1,1).returning(90) + m.expects(Symbol("methodWith10Ints"))(1,1,1,1,1,1,1,1,1,1).returning(90) assertResult(90) { m.methodWith10Ints(1,1,1,1,1,1,1,1,1,1) } - m.expects('methodWith11Ints)(1,1,1,1,1,1,1,1,1,1,1).returning(89) + m.expects(Symbol("methodWith11Ints"))(1,1,1,1,1,1,1,1,1,1,1).returning(89) assertResult(89) { m.methodWith11Ints(1,1,1,1,1,1,1,1,1,1,1) } - m.expects('methodWith12Ints)(1,1,1,1,1,1,1,1,1,1,1,1).returning(88) + m.expects(Symbol("methodWith12Ints"))(1,1,1,1,1,1,1,1,1,1,1,1).returning(88) assertResult(88) { m.methodWith12Ints(1,1,1,1,1,1,1,1,1,1,1,1) } - m.expects('methodWith13Ints)(1,1,1,1,1,1,1,1,1,1,1,1,1).returning(87) + m.expects(Symbol("methodWith13Ints"))(1,1,1,1,1,1,1,1,1,1,1,1,1).returning(87) assertResult(87) { m.methodWith13Ints(1,1,1,1,1,1,1,1,1,1,1,1,1) } - m.expects('methodWith14Ints)(1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(86) + m.expects(Symbol("methodWith14Ints"))(1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(86) assertResult(86) { m.methodWith14Ints(1,1,1,1,1,1,1,1,1,1,1,1,1,1) } - m.expects('methodWith15Ints)(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(85) + m.expects(Symbol("methodWith15Ints"))(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(85) assertResult(85) { m.methodWith15Ints(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) } - m.expects('methodWith16Ints)(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(84) + m.expects(Symbol("methodWith16Ints"))(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(84) assertResult(84) { m.methodWith16Ints(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) } - m.expects('methodWith17Ints)(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(83) + m.expects(Symbol("methodWith17Ints"))(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(83) assertResult(83) { m.methodWith17Ints(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) } - m.expects('methodWith18Ints)(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(82) + m.expects(Symbol("methodWith18Ints"))(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(82) assertResult(82) { m.methodWith18Ints(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) } - m.expects('methodWith19Ints)(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(81) + m.expects(Symbol("methodWith19Ints"))(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(81) assertResult(81) { m.methodWith19Ints(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) } - m.expects('methodWith20Ints)(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(80) + m.expects(Symbol("methodWith20Ints"))(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(80) assertResult(80) { m.methodWith20Ints(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) } - m.expects('methodWith21Ints)(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(79) + m.expects(Symbol("methodWith21Ints"))(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(79) assertResult(79) { m.methodWith21Ints(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) } - m.expects('methodWith22Ints)(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(78) + m.expects(Symbol("methodWith22Ints"))(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1).returning(78) assertResult(78) { m.methodWith22Ints(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) } } } diff --git a/jvm/src/test/scala/com.paulbutcher.test/proxy/ProxyMockTest.scala b/jvm/src/test/scala/com.paulbutcher.test/proxy/ProxyMockTest.scala index 54cddc9f..076c775e 100644 --- a/jvm/src/test/scala/com.paulbutcher.test/proxy/ProxyMockTest.scala +++ b/jvm/src/test/scala/com.paulbutcher.test/proxy/ProxyMockTest.scala @@ -39,7 +39,7 @@ class ProxyMockTest extends AnyFreeSpec with MockFactory { "allow expectations to be set" in { withExpectations { val m = mock[TestTrait] - m.expects('twoParams)(42, 1.23).returning("a return value") + m.expects(Symbol("twoParams"))(42, 1.23).returning("a return value") assertResult("a return value") { m.twoParams(42, 1.23) } } } @@ -47,7 +47,7 @@ class ProxyMockTest extends AnyFreeSpec with MockFactory { "fail if a non-matching method call is made" in { withExpectations { val m = mock[TestTrait] - m.expects('twoParams)(42, 1.23) + m.expects(Symbol("twoParams"))(42, 1.23) intercept[ExpectationException] { m.twoParams(1, 1.0) } m.twoParams(42, 1.23) } @@ -56,7 +56,7 @@ class ProxyMockTest extends AnyFreeSpec with MockFactory { "cope with nullary methods" in { withExpectations { val m = mock[TestTrait] - m.expects('nullary)().returning("a return value") + m.expects(Symbol("nullary"))().returning("a return value") assertResult("a return value") { m.nullary } } } @@ -64,8 +64,8 @@ class ProxyMockTest extends AnyFreeSpec with MockFactory { "cope with overloaded methods" in { withExpectations { val m = mock[TestTrait] - m.expects('overloaded)(10).returning("got an integer") - m.expects('overloaded)(10, 1.23).returning("got two parameters") + m.expects(Symbol("overloaded"))(10).returning("got an integer") + m.expects(Symbol("overloaded"))(10, 1.23).returning("got two parameters") assertResult("got an integer") { m.overloaded(10) } assertResult("got two parameters") { m.overloaded(10, 1.23) } } @@ -74,7 +74,7 @@ class ProxyMockTest extends AnyFreeSpec with MockFactory { "cope with polymorphic overloaded methods" in { withExpectations { val m = mock[TestTrait] - m.expects('overloaded)(1.23).returning("polymorphic method called") + m.expects(Symbol("overloaded"))(1.23).returning("polymorphic method called") assertResult("polymorphic method called") { m.overloaded(1.23) } } } @@ -92,7 +92,7 @@ class ProxyMockTest extends AnyFreeSpec with MockFactory { "cope with curried methods" in { withExpectations { val m = mock[TestTrait] - m.expects('curried)(10, 1.23).returning("curried method called") + m.expects(Symbol("curried"))(10, 1.23).returning("curried method called") val partial = m.curried(10) _ assertResult("curried method called") { partial(1.23) } } @@ -101,8 +101,8 @@ class ProxyMockTest extends AnyFreeSpec with MockFactory { "cope with polymorphic methods" in { withExpectations { val m = mock[TestTrait] - m.expects('polymorphic)(List(1, 2)).returning("called with integers") - m.expects('polymorphic)(List("foo", "bar")).returning("called with strings") + m.expects(Symbol("polymorphic"))(List(1, 2)).returning("called with integers") + m.expects(Symbol("polymorphic"))(List("foo", "bar")).returning("called with strings") assertResult("called with integers") { m.polymorphic(List(1, 2)) } assertResult("called with strings") { m.polymorphic(List("foo", "bar")) } } @@ -111,7 +111,7 @@ class ProxyMockTest extends AnyFreeSpec with MockFactory { "cope with parameters of polymorphic type" in { withExpectations { val m = mock[TestTrait] - m.expects('polymorphicParam)((42, 1.23)).returning("it works") + m.expects(Symbol("polymorphicParam"))((42, 1.23)).returning("it works") assertResult("it works") { m.polymorphicParam((42, 1.23)) } } } @@ -119,7 +119,7 @@ class ProxyMockTest extends AnyFreeSpec with MockFactory { "cope with methods with repeated parameters" in { withExpectations { val m = mock[TestTrait] - m.expects('repeatedParam)(42, Seq("foo", "bar")) + m.expects(Symbol("repeatedParam"))(42, Seq("foo", "bar")) m.repeatedParam(42, "foo", "bar") } } @@ -127,35 +127,40 @@ class ProxyMockTest extends AnyFreeSpec with MockFactory { "cope with methods with by name parameters" in { withExpectations { val m = mock[TestTrait] - m.expects('byNameParam)(*).returning("it worked") + m.expects(Symbol("byNameParam"))(*).returning("it worked") assertResult("it worked") { m.byNameParam(42) } } } +/* + + //! TODO - in scala 3 we can't distinguish abstract var setters with non abstract vars setters + // TODO and override modifier is not allowed when overriding abstract vars + "cope with a var" in { withExpectations { val m = mock[TestTrait] m.expects(Symbol("aVar_$eq"))("foo") - m.expects('aVar)().returning("bar") + m.expects(Symbol("aVar"))().returning("bar") m.aVar = "foo" assertResult("bar") { m.aVar } } - } - + }*/ + /* "cope with a non-abstract var" in { withExpectations { val m = mock[TestTrait] m.expects(Symbol("concreteVar_$eq"))("foo") - m.expects('concreteVar)().returning("bar") + m.expects(Symbol("concreteVar"))().returning("bar") m.concreteVar = "foo" assertResult("bar") { m.concreteVar } } - } + }*/ "cope with a val" in { withExpectations { val m = mock[TestTrait] - m.expects('aVal)().returning("it works") + m.expects(Symbol("aVal"))().returning("it works") assertResult("it works") { m.aVal } } } @@ -163,7 +168,7 @@ class ProxyMockTest extends AnyFreeSpec with MockFactory { "cope with a non-abstract val" in { withExpectations { val m = mock[TestTrait] - m.expects('concreteVal)().returning("it works") + m.expects(Symbol("concreteVal"))().returning("it works") assertResult("it works") { m.concreteVal } } } @@ -171,51 +176,51 @@ class ProxyMockTest extends AnyFreeSpec with MockFactory { "cope with non-abstract methods" in { withExpectations { val m = mock[TestTrait] - m.expects('withImplementation)(42).returning(1234) + m.expects(Symbol("withImplementation"))(42).returning(1234) assertResult(1234) { m.withImplementation(42) } } } - + "mock an embeddded trait" in { withExpectations { val m = mock[TestTrait] val e = mock[m.Embedded] - m.expects('referencesEmbedded)().returning(e) - assertResult(e) { m.referencesEmbedded } + m.expects(Symbol("referencesEmbedded"))().returning(e) + assertResult(e) { m.referencesEmbedded() } } } - + "handle projected types correctly" in { withExpectations { val m = mock[TestTrait] val e = mock[m.Embedded] val o = mock[m.ATrait] val i = mock[e.ATrait] - e.expects('innerTraitProjected)().returning(i) - e.expects('outerTraitProjected)().returning(o) - assertResult(o) { e.outerTraitProjected } - assertResult(i) { e.innerTraitProjected } + e.expects(Symbol("innerTraitProjected"))().returning(i) + e.expects(Symbol("outerTraitProjected"))().returning(o) + assertResult(o) { e.outerTraitProjected() } + assertResult(i) { e.innerTraitProjected() } } } - + "handle path-dependent types correctly" in { withExpectations { val m = mock[TestTrait] val e = mock[m.Embedded] val o = mock[m.ATrait] val i = mock[e.ATrait] - e.expects('innerTrait)().returning(i) - e.expects('outerTrait)().returning(o) - assertResult(o) { e.outerTrait } - assertResult(i) { e.innerTrait } + e.expects(Symbol("innerTrait"))().returning(i) + e.expects(Symbol("outerTrait"))().returning(o) + assertResult(o) { e.outerTrait() } + assertResult(i) { e.innerTrait() } } } "match arguments" in { withExpectations { val m = mock[TestTrait] - m.expects('twoParams)(where { (x: Int, y: Double) => x < y }).returning("less than") - m.expects('twoParams)(where { (x: Int, y: Double) => x > y }).returning("greater than") + m.expects(Symbol("twoParams"))(where { (x: Int, y: Double) => x < y }).returning("less than") + m.expects(Symbol("twoParams"))(where { (x: Int, y: Double) => x > y }).returning("greater than") assertResult("less than") { m.twoParams(1, 2.0) } assertResult("greater than") { m.twoParams(2, 1.0) } } @@ -233,7 +238,7 @@ class ProxyMockTest extends AnyFreeSpec with MockFactory { "return what they're told to" in { withExpectations { val m = stub[TestTrait] - m.when('twoParams)(42, 1.23).returns("a return value") + m.when(Symbol("twoParams"))(42, 1.23).returns("a return value") assertResult("a return value") { m.twoParams(42, 1.23) } } } @@ -243,7 +248,7 @@ class ProxyMockTest extends AnyFreeSpec with MockFactory { val m = stub[TestTrait] m.twoParams(42, 1.23) m.twoParams(42, 1.23) - m.verify('twoParams)(42, 1.23).twice + m.verify(Symbol("twoParams"))(42, 1.23).twice() } } @@ -251,19 +256,19 @@ class ProxyMockTest extends AnyFreeSpec with MockFactory { intercept[ExpectationException](withExpectations { val m = stub[TestTrait] m.twoParams(42, 1.00) - m.verify('twoParams)(42, 1.23).once + m.verify(Symbol("twoParams"))(42, 1.23).once() }) } "match arguments" in { withExpectations { val m = stub[TestTrait] - m.when('twoParams)(where { (x: Int, y: Double) => x < y }).returns("less than") - m.when('twoParams)(where { (x: Int, y: Double) => x > y }).returns("greater than") + m.when(Symbol("twoParams"))(where { (x: Int, y: Double) => x < y }).returns("less than") + m.when(Symbol("twoParams"))(where { (x: Int, y: Double) => x > y }).returns("greater than") assertResult("less than") { m.twoParams(1, 2.0) } assertResult("greater than") { m.twoParams(2, 1.0) } - m.verify('twoParams)(where { (x: Int, y: Double) => x < y }).once - m.verify('twoParams)(where { (x: Int, y: Double) => x > y }).once + m.verify(Symbol("twoParams"))(where { (x: Int, y: Double) => x < y }).once() + m.verify(Symbol("twoParams"))(where { (x: Int, y: Double) => x > y }).once() } } } diff --git a/jvm/src/test/scala/org/scalamock/test/scalatest/MixedMockFactoryTest.scala b/jvm/src/test/scala/org/scalamock/test/scalatest/MixedMockFactoryTest.scala index 2ae78bd1..2ad826dc 100644 --- a/jvm/src/test/scala/org/scalamock/test/scalatest/MixedMockFactoryTest.scala +++ b/jvm/src/test/scala/org/scalamock/test/scalatest/MixedMockFactoryTest.scala @@ -12,8 +12,8 @@ class MixedMockFactoryTest extends AnyFlatSpec with MixedMockFactory with Matche val m = mock[Foo] val p = Proxy.mock[Foo] - p.expects('getI)().returning(5).once() - (m.getI _).expects().returns(42).anyNumberOfTimes() + p.expects(Symbol("getI"))().returning(5).once() + (() => m.getI).expects().returns(42).anyNumberOfTimes() m.getI should be(42) p.getI should be(5) diff --git a/jvm/src/test/scala/org/scalamock/test/scalatest/SuiteScopeProxyMockTest.scala b/jvm/src/test/scala/org/scalamock/test/scalatest/SuiteScopeProxyMockTest.scala index f930a20e..9a6e6305 100644 --- a/jvm/src/test/scala/org/scalamock/test/scalatest/SuiteScopeProxyMockTest.scala +++ b/jvm/src/test/scala/org/scalamock/test/scalatest/SuiteScopeProxyMockTest.scala @@ -39,15 +39,15 @@ class SuiteScopeProxyMockTest extends AnyFlatSpec with Matchers with OneInstance val mockWithoutExpectationsPredefined = mock[TestTrait] "ScalaTest suite" should "allow to use mock defined suite scope" in { - mockWithoutExpectationsPredefined.expects('oneParamMethod)(1).returning("one") - mockWithoutExpectationsPredefined.expects('oneParamMethod)(2).returning("two") + mockWithoutExpectationsPredefined.expects(Symbol("oneParamMethod"))(1).returning("one") + mockWithoutExpectationsPredefined.expects(Symbol("oneParamMethod"))(2).returning("two") mockWithoutExpectationsPredefined.oneParamMethod(1) shouldBe "one" mockWithoutExpectationsPredefined.oneParamMethod(2) shouldBe "two" } it should "allow to use mock defined suite scope in more than one test case" in { - mockWithoutExpectationsPredefined.expects('oneParamMethod)(3).returning("three") + mockWithoutExpectationsPredefined.expects(Symbol("oneParamMethod"))(3).returning("three") mockWithoutExpectationsPredefined.oneParamMethod(3) shouldBe "three" } diff --git a/project/plugins.sbt b/project/plugins.sbt index 03d7052d..c589be2b 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -3,5 +3,5 @@ addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.10.0") //addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.0-M2") addSbtPlugin("com.github.sbt" % "sbt-git" % "2.0.1") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.10.1") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.2") addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.3.2") diff --git a/shared/src/main/scala/org/scalamock/clazz/Mock.scala b/shared/src/main/scala-2/org/scalamock/clazz/Mock.scala similarity index 100% rename from shared/src/main/scala/org/scalamock/clazz/Mock.scala rename to shared/src/main/scala-2/org/scalamock/clazz/Mock.scala diff --git a/shared/src/main/scala/org/scalamock/clazz/MockFunctionFinder.scala b/shared/src/main/scala-2/org/scalamock/clazz/MockFunctionFinder.scala similarity index 100% rename from shared/src/main/scala/org/scalamock/clazz/MockFunctionFinder.scala rename to shared/src/main/scala-2/org/scalamock/clazz/MockFunctionFinder.scala index a63680af..d8d8552a 100644 --- a/shared/src/main/scala/org/scalamock/clazz/MockFunctionFinder.scala +++ b/shared/src/main/scala-2/org/scalamock/clazz/MockFunctionFinder.scala @@ -67,8 +67,8 @@ object MockFunctionFinder { //! TODO - replace with official resolveOverloaded if/when it's reinstated def resolveOverloaded(c: Context)(method: c.universe.TermSymbol, targs: List[c.universe.Type], actuals: List[c.universe.Type]): c.universe.Symbol = { val utils = new MacroUtils[c.type](c) - import utils._ import c.universe._ + import utils._ def sameTypes(types1: List[Type], types2: List[Type]) = { // see issue #34 diff --git a/shared/src/main/scala/org/scalamock/clazz/MockImpl.scala b/shared/src/main/scala-2/org/scalamock/clazz/MockImpl.scala similarity index 100% rename from shared/src/main/scala/org/scalamock/clazz/MockImpl.scala rename to shared/src/main/scala-2/org/scalamock/clazz/MockImpl.scala diff --git a/shared/src/main/scala/org/scalamock/clazz/MockMaker.scala b/shared/src/main/scala-2/org/scalamock/clazz/MockMaker.scala similarity index 99% rename from shared/src/main/scala/org/scalamock/clazz/MockMaker.scala rename to shared/src/main/scala-2/org/scalamock/clazz/MockMaker.scala index dcd6f390..da1b65e0 100644 --- a/shared/src/main/scala/org/scalamock/clazz/MockMaker.scala +++ b/shared/src/main/scala-2/org/scalamock/clazz/MockMaker.scala @@ -22,8 +22,8 @@ package org.scalamock.clazz import org.scalamock.context.MockContext import org.scalamock.function._ +import org.scalamock.util.MacroAdapter.Context import org.scalamock.util.{MacroAdapter, MacroUtils} -import MacroAdapter.Context //! TODO - get rid of this nasty two-stage construction when https://issues.scala-lang.org/browse/SI-5521 is fixed @@ -33,6 +33,7 @@ class MockMaker[C <: Context](val ctx: C) { import ctx.universe._ import Flag._ import definitions._ + import scala.language.reflectiveCalls val utils = new MacroUtils[ctx.type](ctx) diff --git a/shared/src/main/scala/org/scalamock/proxy/ProxyMockFactory.scala b/shared/src/main/scala-2/org/scalamock/proxy/ProxyMockFactory.scala similarity index 100% rename from shared/src/main/scala/org/scalamock/proxy/ProxyMockFactory.scala rename to shared/src/main/scala-2/org/scalamock/proxy/ProxyMockFactory.scala diff --git a/shared/src/main/scala/org/scalamock/util/MacroAdapter.scala b/shared/src/main/scala-2/org/scalamock/util/MacroAdapter.scala similarity index 100% rename from shared/src/main/scala/org/scalamock/util/MacroAdapter.scala rename to shared/src/main/scala-2/org/scalamock/util/MacroAdapter.scala diff --git a/shared/src/main/scala/org/scalamock/util/MacroUtils.scala b/shared/src/main/scala-2/org/scalamock/util/MacroUtils.scala similarity index 98% rename from shared/src/main/scala/org/scalamock/util/MacroUtils.scala rename to shared/src/main/scala-2/org/scalamock/util/MacroUtils.scala index 11d4a24f..05a59d5b 100644 --- a/shared/src/main/scala/org/scalamock/util/MacroUtils.scala +++ b/shared/src/main/scala-2/org/scalamock/util/MacroUtils.scala @@ -20,7 +20,7 @@ package org.scalamock.util -import MacroAdapter.Context +import org.scalamock.util.MacroAdapter.Context /** * Helper functions to work with Scala macros and to create scala.reflect Trees. diff --git a/shared/src/main/scala-3/org/scalamock/clazz/Mock.scala b/shared/src/main/scala-3/org/scalamock/clazz/Mock.scala new file mode 100644 index 00000000..c8806cf3 --- /dev/null +++ b/shared/src/main/scala-3/org/scalamock/clazz/Mock.scala @@ -0,0 +1,85 @@ +// Copyright (c) ScalaMock Contributors (https://github.com/paulbutcher/ScalaMock/graphs/contributors) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package org.scalamock.clazz + +import org.scalamock.context.MockContext +import org.scalamock.function.* +import org.scalamock.util.Defaultable + +import scala.reflect.Selectable + +trait Mock: + import scala.language.implicitConversions + + inline def mock[T](implicit mockContext: MockContext): T & Selectable = ${MockImpl.mock[T]('{mockContext})} + inline def stub[T](implicit mockContext: MockContext): T & Selectable = ${MockImpl.stub[T]('{mockContext})} + + inline def mock[T](mockName: String)(implicit mockContext: MockContext) : T & Selectable = ${MockImpl.mockWithName[T]('{mockName})('{mockContext})} + inline def stub[T](mockName: String)(implicit mockContext: MockContext): T & Selectable = ${MockImpl.stubWithName[T]('{mockName})('{mockContext})} + + inline implicit def toMockFunction0[R: Defaultable](inline f: () => R): MockFunction0[R] = ${MockImpl.toMockFunction0[R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction1[T1, R: Defaultable](inline f: T1 => R): MockFunction1[T1, R] = ${MockImpl.toMockFunction1[T1, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction2[T1, T2, R: Defaultable](inline f: (T1, T2) => R): MockFunction2[T1, T2, R] = ${MockImpl.toMockFunction2[T1, T2, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction3[T1, T2, T3, R: Defaultable](inline f: (T1, T2, T3) => R): MockFunction3[T1, T2, T3, R] = ${MockImpl.toMockFunction3[T1, T2, T3, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction4[T1, T2, T3, T4, R: Defaultable](inline f: (T1, T2, T3, T4) => R): MockFunction4[T1, T2, T3, T4, R] = ${MockImpl.toMockFunction4[T1, T2, T3, T4, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction5[T1, T2, T3, T4, T5, R: Defaultable](inline f: (T1, T2, T3, T4, T5) => R): MockFunction5[T1, T2, T3, T4, T5, R] = ${MockImpl.toMockFunction5[T1, T2, T3, T4, T5, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction6[T1, T2, T3, T4, T5, T6, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6) => R): MockFunction6[T1, T2, T3, T4, T5, T6, R] = ${MockImpl.toMockFunction6[T1, T2, T3, T4, T5, T6, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction7[T1, T2, T3, T4, T5, T6, T7, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7) => R): MockFunction7[T1, T2, T3, T4, T5, T6, T7, R] = ${MockImpl.toMockFunction7[T1, T2, T3, T4, T5, T6, T7, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction8[T1, T2, T3, T4, T5, T6, T7, T8, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8) => R): MockFunction8[T1, T2, T3, T4, T5, T6, T7, T8, R] = ${MockImpl.toMockFunction8[T1, T2, T3, T4, T5, T6, T7, T8, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9) => R): MockFunction9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R] = ${MockImpl.toMockFunction9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => R): MockFunction10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R] = ${MockImpl.toMockFunction10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => R): MockFunction11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R] = ${MockImpl.toMockFunction11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => R): MockFunction12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R] = ${MockImpl.toMockFunction12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => R): MockFunction13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R] = ${MockImpl.toMockFunction13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => R): MockFunction14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R] = ${MockImpl.toMockFunction14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => R): MockFunction15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R] = ${MockImpl.toMockFunction15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => R): MockFunction16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R] = ${MockImpl.toMockFunction16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => R): MockFunction17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R] = ${MockImpl.toMockFunction17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => R): MockFunction18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R] = ${MockImpl.toMockFunction18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => R): MockFunction19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R] = ${MockImpl.toMockFunction19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => R): MockFunction20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R] = ${MockImpl.toMockFunction20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => R): MockFunction21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R] = ${MockImpl.toMockFunction21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toMockFunction22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => R): MockFunction22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R] = ${MockImpl.toMockFunction22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R]('{f})('{summon[Defaultable[R]]})} + + inline implicit def toStubFunction0[R: Defaultable](inline f: () => R): StubFunction0[R] = ${MockImpl.toStubFunction0[R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction1[T1, R: Defaultable](inline f: T1 => R): StubFunction1[T1, R] = ${MockImpl.toStubFunction1[T1, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction2[T1, T2, R: Defaultable](inline f: (T1, T2) => R): StubFunction2[T1, T2, R] = ${MockImpl.toStubFunction2[T1, T2, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction3[T1, T2, T3, R: Defaultable](inline f: (T1, T2, T3) => R): StubFunction3[T1, T2, T3, R] = ${MockImpl.toStubFunction3[T1, T2, T3, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction4[T1, T2, T3, T4, R: Defaultable](inline f: (T1, T2, T3, T4) => R): StubFunction4[T1, T2, T3, T4, R] = ${MockImpl.toStubFunction4[T1, T2, T3, T4, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction5[T1, T2, T3, T4, T5, R: Defaultable](inline f: (T1, T2, T3, T4, T5) => R): StubFunction5[T1, T2, T3, T4, T5, R] = ${MockImpl.toStubFunction5[T1, T2, T3, T4, T5, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction6[T1, T2, T3, T4, T5, T6, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6) => R): StubFunction6[T1, T2, T3, T4, T5, T6, R] = ${MockImpl.toStubFunction6[T1, T2, T3, T4, T5, T6, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction7[T1, T2, T3, T4, T5, T6, T7, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7) => R): StubFunction7[T1, T2, T3, T4, T5, T6, T7, R] = ${MockImpl.toStubFunction7[T1, T2, T3, T4, T5, T6, T7, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction8[T1, T2, T3, T4, T5, T6, T7, T8, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8) => R): StubFunction8[T1, T2, T3, T4, T5, T6, T7, T8, R] = ${MockImpl.toStubFunction8[T1, T2, T3, T4, T5, T6, T7, T8, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9) => R): StubFunction9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R] = ${MockImpl.toStubFunction9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => R): StubFunction10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R] = ${MockImpl.toStubFunction10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => R): StubFunction11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R] = ${MockImpl.toStubFunction11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => R): StubFunction12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R] = ${MockImpl.toStubFunction12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => R): StubFunction13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R] = ${MockImpl.toStubFunction13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => R): StubFunction14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R] = ${MockImpl.toStubFunction14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => R): StubFunction15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R] = ${MockImpl.toStubFunction15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => R): StubFunction16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R] = ${MockImpl.toStubFunction16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => R): StubFunction17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R] = ${MockImpl.toStubFunction17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => R): StubFunction18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R] = ${MockImpl.toStubFunction18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => R): StubFunction19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R] = ${MockImpl.toStubFunction19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => R): StubFunction20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R] = ${MockImpl.toStubFunction20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => R): StubFunction21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R] = ${MockImpl.toStubFunction21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R]('{f})('{summon[Defaultable[R]]})} + inline implicit def toStubFunction22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R: Defaultable](inline f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => R): StubFunction22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R] = ${MockImpl.toStubFunction22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R]('{f})('{summon[Defaultable[R]]})} + diff --git a/shared/src/main/scala-3/org/scalamock/clazz/MockFunctionFinder.scala b/shared/src/main/scala-3/org/scalamock/clazz/MockFunctionFinder.scala new file mode 100644 index 00000000..81db2a7c --- /dev/null +++ b/shared/src/main/scala-3/org/scalamock/clazz/MockFunctionFinder.scala @@ -0,0 +1,68 @@ +// Copyright (c) ScalaMock Contributors (https://github.com/paulbutcher/ScalaMock/graphs/contributors) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package org.scalamock.clazz + +import scala.quoted.* + +object MockFunctionFinder: + def ticketMessage = "Please open a ticket at https://github.com/paulbutcher/ScalaMock/issues" + /** + * Given something of the structure <|o.m _|> where o is a mock object + * and m is a method, find the corresponding MockFunction instance + */ + @scala.annotation.experimental + def findMockFunction[M: Type](f: Expr[Any])(using quotes: Quotes): Expr[M] = + val utils = Utils(using quotes) + import utils.quotes.reflect.* + + def transcribeTree(term: Term, types: List[TypeTree] = Nil): Expr[M] = + term match + case Select(mock, methodName) => + val mockTpe = mock.tpe.widenTermRefByName match + case AndType(tpe, _) => tpe + case tpe => tpe + + val name = utils.MockableDefinitions.find(mockTpe, methodName, TypeRepr.of[M].typeArgs.init, types.map(_.tpe)) + // looks like `selectDynamic` should work with raw names, but it doesn't + // https://github.com/lampepfl/dotty/issues/18612 + '{ + ${mock.asExpr} + .asInstanceOf[scala.reflect.Selectable] + .selectDynamic(${Expr(scala.reflect.NameTransformer.encode(name))}) + .asInstanceOf[M] + } + + case Inlined(_, _, term) => transcribeTree(term) + case Block(stats @ List(_: ValDef), term) => Block(stats, transcribeTree(term).asTerm).asExprOf[M] // var m = mock[T] + case Block(List(DefDef(_, _, _, Some(term))), _) => transcribeTree(term) + case Typed(term, teps) => transcribeTree(term) + case Lambda(_, term) => transcribeTree(term) + case Apply(term, _) => transcribeTree(term) + case TypeApply(term, types) => transcribeTree(term, types) + case Ident(fun) => + report.errorAndAbort( + s"please declare '$fun' as MockFunctionX or StubFunctionX (e.g val $fun: MockFunction1[X, R] = ... if it has 1 parameter)" + ) + case _ => + report.errorAndAbort( + s"ScalaMock: unrecognised structure ${term.show(using Printer.TreeStructure)}. " + ticketMessage + ) + transcribeTree(f.asTerm) diff --git a/shared/src/main/scala-3/org/scalamock/clazz/MockImpl.scala b/shared/src/main/scala-3/org/scalamock/clazz/MockImpl.scala new file mode 100644 index 00000000..8daba8bc --- /dev/null +++ b/shared/src/main/scala-3/org/scalamock/clazz/MockImpl.scala @@ -0,0 +1,184 @@ +// Copyright (c) ScalaMock Contributors (https://github.com/paulbutcher/ScalaMock/graphs/contributors) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package org.scalamock.clazz + +import org.scalamock.function.* +import org.scalamock.context.MockContext + +import scala.quoted.* +import org.scalamock.util.Defaultable +import MockFunctionFinder.findMockFunction + +import scala.reflect.Selectable + +@scala.annotation.experimental +private[clazz] object MockImpl: + def mock[T: Type](mockContext: Expr[MockContext])(using quotes: Quotes): Expr[T & Selectable] = + MockMaker.instance[T](MockType.Mock, mockContext, name = None) + + def stub[T: Type](mockContext: Expr[MockContext])(using quotes: Quotes): Expr[T & Selectable] = + MockMaker.instance[T](MockType.Stub, mockContext, name = None) + + def mockWithName[T: Type](mockName: Expr[String])(mockContext: Expr[MockContext])(using quotes: Quotes): Expr[T & Selectable] = + MockMaker.instance[T](MockType.Mock, mockContext, Some(mockName)) + + def stubWithName[T: Type](mockName: Expr[String])(mockContext: Expr[MockContext])(using quotes: Quotes): Expr[T & Selectable] = + MockMaker.instance[T](MockType.Stub, mockContext, Some(mockName)) + + + def toMockFunction0[R: Type](f: Expr[() => R])(evidence$1: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction0[R]](f) + + def toMockFunction1[T1: Type, R: Type](f: Expr[T1 => R])(evidence$2: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction1[T1, R]](f) + + def toMockFunction2[T1: Type, T2: Type, R: Type](f: Expr[(T1, T2) => R])(evidence$3: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction2[T1, T2, R]](f) + + def toMockFunction3[T1: Type, T2: Type, T3: Type, R: Type](f: Expr[(T1, T2, T3) => R])(evidence$4: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction3[T1, T2, T3, R]](f) + + def toMockFunction4[T1: Type, T2: Type, T3: Type, T4: Type, R: Type](f: Expr[(T1, T2, T3, T4) => R])(evidence$5: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction4[T1, T2, T3, T4, R]](f) + + def toMockFunction5[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5) => R])(evidence$6: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction5[T1, T2, T3, T4, T5, R]](f) + + def toMockFunction6[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6) => R])(evidence$7: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction6[T1, T2, T3, T4, T5, T6, R]](f) + + def toMockFunction7[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7) => R])(evidence$8: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction7[T1, T2, T3, T4, T5, T6, T7, R]](f) + + def toMockFunction8[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8) => R])(evidence$9: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction8[T1, T2, T3, T4, T5, T6, T7, T8, R]](f) + + def toMockFunction9[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9) => R])(evidence$10: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R]](f) + + def toMockFunction10[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => R])(evidence$10: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R]](f) + + def toMockFunction11[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => R])(evidence$11: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R]](f) + + def toMockFunction12[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => R])(evidence$12: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R]](f) + + def toMockFunction13[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => R])(evidence$13: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R]](f) + + def toMockFunction14[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => R])(evidence$14: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R]](f) + + def toMockFunction15[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, T15: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => R])(evidence$15: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R]](f) + + def toMockFunction16[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, T15: Type, T16: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => R])(evidence$16: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R]](f) + + def toMockFunction17[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, T15: Type, T16: Type, T17: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => R])(evidence$17: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R]](f) + + def toMockFunction18[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, T15: Type, T16: Type, T17: Type, T18: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => R])(evidence$18: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R]](f) + + def toMockFunction19[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, T15: Type, T16: Type, T17: Type, T18: Type, T19: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => R])(evidence$19: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R]](f) + + def toMockFunction20[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, T15: Type, T16: Type, T17: Type, T18: Type, T19: Type, T20: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => R])(evidence$20: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R]](f) + + def toMockFunction21[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, T15: Type, T16: Type, T17: Type, T18: Type, T19: Type, T20: Type, T21: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => R])(evidence$21: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R]](f) + + def toMockFunction22[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, T15: Type, T16: Type, T17: Type, T18: Type, T19: Type, T20: Type, T21: Type, T22: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => R])(evidence$22: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[MockFunction22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R]](f) + + def toStubFunction0[R: Type](f: Expr[() => R])(evidence$20: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction0[R]](f) + + def toStubFunction1[T1: Type, R: Type](f: Expr[T1 => R])(evidence$21: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction1[T1, R]](f) + + def toStubFunction2[T1: Type, T2: Type, R: Type](f: Expr[(T1, T2) => R])(evidence$22: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction2[T1, T2, R]](f) + + def toStubFunction3[T1: Type, T2: Type, T3: Type, R: Type](f: Expr[(T1, T2, T3) => R])(evidence$23: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction3[T1, T2, T3, R]](f) + + def toStubFunction4[T1: Type, T2: Type, T3: Type, T4: Type, R: Type](f: Expr[(T1, T2, T3, T4) => R])(evidence$24: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction4[T1, T2, T3, T4, R]](f) + + def toStubFunction5[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5) => R])(evidence$25: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction5[T1, T2, T3, T4, T5, R]](f) + + def toStubFunction6[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6) => R])(evidence$26: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction6[T1, T2, T3, T4, T5, T6, R]](f) + + def toStubFunction7[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7) => R])(evidence$27: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction7[T1, T2, T3, T4, T5, T6, T7, R]](f) + + def toStubFunction8[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8) => R])(evidence$28: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction8[T1, T2, T3, T4, T5, T6, T7, T8, R]](f) + + def toStubFunction9[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9) => R])(evidence$29: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R]](f) + + def toStubFunction10[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => R])(evidence$210: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R]](f) + + def toStubFunction11[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => R])(evidence$211: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R]](f) + + def toStubFunction12[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => R])(evidence$212: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R]](f) + + def toStubFunction13[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => R])(evidence$213: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R]](f) + + def toStubFunction14[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => R])(evidence$214: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R]](f) + + def toStubFunction15[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, T15: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => R])(evidence$215: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R]](f) + + def toStubFunction16[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, T15: Type, T16: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => R])(evidence$216: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R]](f) + + def toStubFunction17[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, T15: Type, T16: Type, T17: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => R])(evidence$217: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R]](f) + + def toStubFunction18[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, T15: Type, T16: Type, T17: Type, T18: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => R])(evidence$218: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R]](f) + + def toStubFunction19[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, T15: Type, T16: Type, T17: Type, T18: Type, T19: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => R])(evidence$219: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R]](f) + + def toStubFunction20[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, T15: Type, T16: Type, T17: Type, T18: Type, T19: Type, T20: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => R])(evidence$220: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R]](f) + + def toStubFunction21[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, T15: Type, T16: Type, T17: Type, T18: Type, T19: Type, T20: Type, T21: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => R])(evidence$221: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R]](f) + + def toStubFunction22[T1: Type, T2: Type, T3: Type, T4: Type, T5: Type, T6: Type, T7: Type, T8: Type, T9: Type, T10: Type, T11: Type, T12: Type, T13: Type, T14: Type, T15: Type, T16: Type, T17: Type, T18: Type, T19: Type, T20: Type, T21: Type, T22: Type, R: Type](f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => R])(evidence$222: Expr[Defaultable[R]])(using quotes: Quotes) = + findMockFunction[StubFunction22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R]](f) + diff --git a/shared/src/main/scala-3/org/scalamock/clazz/MockMaker.scala b/shared/src/main/scala-3/org/scalamock/clazz/MockMaker.scala new file mode 100644 index 00000000..e7514c28 --- /dev/null +++ b/shared/src/main/scala-3/org/scalamock/clazz/MockMaker.scala @@ -0,0 +1,193 @@ +// Copyright (c) ScalaMock Contributors (https://github.com/paulbutcher/ScalaMock/graphs/contributors) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package org.scalamock.clazz + +import org.scalamock.context.MockContext + +import scala.quoted.* +import scala.reflect.Selectable + +@scala.annotation.experimental +private[clazz] object MockMaker: + val MockDefaultNameValName = "mock$special$mockName" + + def instance[T: Type](mockType: MockType, ctx: Expr[MockContext], name: Option[Expr[String]])(using quotes: Quotes): Expr[T & Selectable] = + val utils = Utils(using quotes) + import utils.quotes.reflect.* + val tpe = TypeRepr.of[T] + val isTrait = tpe.dealias.typeSymbol.flags.is(Flags.Trait) + val isJavaClass = tpe.classSymbol.exists(sym => sym.flags.is(Flags.JavaDefined) && !sym.flags.is(Flags.Trait) && !sym.flags.is(Flags.Abstract)) + + if (isJavaClass) + report.errorAndAbort("Can't mock a java class due to https://github.com/lampepfl/dotty/issues/18694. Extend it manually with scala and then mock") + + def asParent(tree: TypeTree): TypeTree | Term = + val constructorFieldsFilledWithNulls: List[List[Term]] = + tree.tpe.dealias.typeSymbol.primaryConstructor.paramSymss + .filter(_.exists(!_.isType)) + .map(_.map(_.typeRef.asType match { case '[t] => '{ null.asInstanceOf[t] }.asTerm })) + + if constructorFieldsFilledWithNulls.forall(_.isEmpty) then + tree + else + Select( + New(TypeIdent(tree.tpe.typeSymbol)), + tree.tpe.typeSymbol.primaryConstructor + ).appliedToArgss(constructorFieldsFilledWithNulls) + + + val parents = + if isTrait then + List(TypeTree.of[Object], asParent(TypeTree.of[T]), TypeTree.of[Selectable]) + else + List(asParent(TypeTree.of[T]), TypeTree.of[Selectable]) + + + val mockableDefinitions = utils.MockableDefinitions(tpe) + + def createDefaultMockNameSymbol(classSymbol: Symbol) = + Symbol.newVal(classSymbol, MockDefaultNameValName, TypeRepr.of[String], Flags.EmptyFlags, Symbol.noSymbol) + + val classSymbol: Symbol = Symbol.newClass( + parent = Symbol.spliceOwner, + name = "$anon", + parents = parents.map { + case term: Term => term.tpe + case tree: TypeTree => tree.tpe + }, + decls = classSymbol => createDefaultMockNameSymbol(classSymbol) :: mockableDefinitions.flatMap { definition => + val mockFunctionClassSym = + Symbol.classSymbol(s"org.scalamock.function.${mockType}Function${definition.parameterTypes.length}") + + val mockFunctionSym = + Symbol.newVal( + parent = classSymbol, + name = definition.mockValName, + tpe = TypeTree.ref(mockFunctionClassSym).tpe.appliedTo(definition.prepareTypesFor(classSymbol).map(_.tpe)), + flags = Flags.EmptyFlags, + privateWithin = Symbol.noSymbol + ) + + val overrideSym = + if definition.symbol.isValDef then + Symbol.newVal( + parent = classSymbol, + name = definition.symbol.name, + tpe = definition.tpeWithSubstitutedPathDependentFor(classSymbol), + flags = Flags.Override, + privateWithin = Symbol.noSymbol + ) + else + Symbol.newMethod( + parent = classSymbol, + name = definition.symbol.name, + tpe = definition.tpeWithSubstitutedPathDependentFor(classSymbol), + flags = Flags.Override, + privateWithin = Symbol.noSymbol + ) + + List(mockFunctionSym, overrideSym) + }, + selfType = None + ) + val defaultMockNameSymbol = classSymbol.declaredField(MockDefaultNameValName) + + val defaultMockName = ValDef( + defaultMockNameSymbol, + Some( + name + .getOrElse('{ ${ctx}.generateMockDefaultName(${ Expr(mockType.toString.toLowerCase) }).name }) + .asTerm + ) + ) + + val classDef: ClassDef = + ClassDef( + cls = classSymbol, + parents = parents, + body = defaultMockName :: mockableDefinitions.flatMap { definition => + val mockFunctionValDef: ValDef = + val valSym = classSymbol.declaredField(definition.mockValName) + val mockFunctionClassSymbol = valSym.typeRef.classSymbol.get + val mockFunctionUniqueName = '{ + scala.Symbol( + Predef.augmentString("<%s> %s%s.%s%s") + .format( + ${ Ref(defaultMockNameSymbol).asExpr }, + ${ Expr(tpe.typeSymbol.name) }, + ${ Expr(if (tpe.typeArgs.isEmpty) "" else "[%s]".format(tpe.typeArgs.map(_.show(using Printer.TypeReprShortCode)).mkString(","))) }, + ${ Expr(definition.symbol.name) }, + ${ Expr { + definition.tpe match + case PolyType(params, _, _) => params.mkString("[", ",", "]") + case _ => "" + } + } + ) + ) + } + ValDef( + symbol = valSym, + rhs = Some( + Apply( + TypeApply( + Select( + New(TypeIdent(mockFunctionClassSymbol)), + mockFunctionClassSymbol.primaryConstructor + ), + definition.prepareTypesFor(classSymbol) + ), + List(ctx.asTerm, mockFunctionUniqueName.asTerm) + ) + ) + ) + + val definitionOverride = + if (definition.symbol.isValDef) + ValDef(definition.symbol.overridingSymbol(classSymbol), Some('{ null }.asTerm)) + else + DefDef( + definition.symbol.overridingSymbol(classSymbol), + { args => + Some( + TypeApply( + Select.unique( + Apply( + Select.unique(Ref(mockFunctionValDef.symbol), "apply"), + args.flatten.collect { case t: Term => t } + ), + "asInstanceOf" + ), + definition.tpe + .resolveParamRefs(definition.resTypeWithPathDependentOverrideFor(classSymbol), args) + .asType match { case '[t] => List(TypeTree.of[t]) } + ) + ) + } + ) + List(mockFunctionValDef, definitionOverride) + } + ) + + Block( + List(classDef), + Typed(Apply(Select(New(TypeIdent(classSymbol)), classSymbol.primaryConstructor), Nil), TypeTree.of[T & Selectable]) + ).asExprOf[T & Selectable] \ No newline at end of file diff --git a/shared/src/main/scala-3/org/scalamock/clazz/MockType.scala b/shared/src/main/scala-3/org/scalamock/clazz/MockType.scala new file mode 100644 index 00000000..8aa9ff02 --- /dev/null +++ b/shared/src/main/scala-3/org/scalamock/clazz/MockType.scala @@ -0,0 +1,4 @@ +package org.scalamock.clazz + +private[clazz] enum MockType: + case Mock, Stub \ No newline at end of file diff --git a/shared/src/main/scala-3/org/scalamock/clazz/Utils.scala b/shared/src/main/scala-3/org/scalamock/clazz/Utils.scala new file mode 100644 index 00000000..a966a499 --- /dev/null +++ b/shared/src/main/scala-3/org/scalamock/clazz/Utils.scala @@ -0,0 +1,143 @@ +package org.scalamock.clazz + +import scala.quoted.* +import org.scalamock.context.MockContext + +import scala.annotation.tailrec +private[clazz] class Utils(using val quotes: Quotes): + import quotes.reflect.* + + extension (tpe: TypeRepr) + def collectPathDependent(ownerSymbol: Symbol): List[TypeRepr] = + def loop(currentTpe: TypeRepr, names: List[String]): List[TypeRepr] = + currentTpe match + case AppliedType(inner, appliedTypes) => loop(inner, names) ++ appliedTypes.flatMap(_.collectPathDependent(ownerSymbol)) + case TypeRef(inner, name) if name == ownerSymbol.name && names.nonEmpty => List(tpe) + case TypeRef(inner, name) => loop(inner, name :: names) + case _ => Nil + + loop(tpe, Nil) + + def pathDependentOverride(ownerSymbol: Symbol, newOwnerSymbol: Symbol, applyTypes: Boolean): TypeRepr = + @tailrec + def loop(currentTpe: TypeRepr, names: List[(String, List[TypeRepr])], appliedTypes: List[TypeRepr]): TypeRepr = + currentTpe match + case AppliedType(inner, appliedTypes) => + loop(inner, names, appliedTypes) + + case TypeRef(inner, name) if name == ownerSymbol.name && names.nonEmpty => + names.foldLeft[TypeRepr](This(newOwnerSymbol).tpe) { case (tpe, (name, appliedTypes)) => + tpe + .select(tpe.typeSymbol.typeMember(name)) + .appliedTo(appliedTypes.filter(_ => applyTypes)) + } + + case TypeRef(inner, name) => + loop(inner, name -> appliedTypes :: names, Nil) + + case other => + tpe + + if (ownerSymbol == newOwnerSymbol) + tpe + else + loop(tpe, Nil, Nil) + + + def mapParamRefWithWildcard: TypeRepr = + tpe match + case ParamRef(PolyType(_, bounds, _), idx) => + bounds(idx) + case AppliedType(tycon, args) => + tycon.appliedTo(args.map(_.mapParamRefWithWildcard)) + case _ => + tpe + + def resolveParamRefs(resType: TypeRepr, methodArgs: List[List[Tree]]) = + def loop(baseBindings: TypeRepr, typeRepr: TypeRepr): TypeRepr = + typeRepr match + case pr@ParamRef(bindings, idx) if bindings == baseBindings => + methodArgs.head(idx).asInstanceOf[TypeTree].tpe + + case AppliedType(tycon, args) => + AppliedType(tycon, args.map(arg => loop(baseBindings, arg))) + + case other => other + + tpe match + case pt: PolyType => loop(pt, resType) + case _ => resType + + + def collectTypes: List[TypeRepr] = + def loop(currentTpe: TypeRepr, params: List[TypeRepr]): List[TypeRepr] = + currentTpe match + case PolyType(_, _, res) => loop(res, Nil) + case MethodType(_, argTypes, res) => argTypes ++ loop(res, params) + case other => List(other) + loop(tpe, Nil) + + case class MockableDefinition(idx: Int, symbol: Symbol, ownerTpe: TypeRepr): + val mockValName = s"mock$$${symbol.name}$$$idx" + val tpe = ownerTpe.memberType(symbol) + private val rawTypes = tpe.widen.collectTypes + val parameterTypes = prepareTypesFor(ownerTpe.typeSymbol).map(_.tpe).init + + def resTypeWithPathDependentOverrideFor(classSymbol: Symbol): TypeRepr = + val pd = rawTypes.last.collectPathDependent(ownerTpe.typeSymbol) + val pdUpdated = pd.map(_.pathDependentOverride(ownerTpe.typeSymbol, classSymbol, applyTypes = false)) + rawTypes.last.substituteTypes(pd.map(_.typeSymbol), pdUpdated) + + def tpeWithSubstitutedPathDependentFor(classSymbol: Symbol): TypeRepr = + val pathDependentTypes = rawTypes.flatMap(_.collectPathDependent(ownerTpe.typeSymbol)) + val pdUpdated = pathDependentTypes.map(_.pathDependentOverride(ownerTpe.typeSymbol, classSymbol, applyTypes = false)) + tpe.substituteTypes(pathDependentTypes.map(_.typeSymbol), pdUpdated) + + def prepareTypesFor(classSymbol: Symbol) = rawTypes + .map(_.pathDependentOverride(ownerTpe.typeSymbol, classSymbol, applyTypes = true)) + .map { typeRepr => + val adjusted = + typeRepr.widen.mapParamRefWithWildcard match + case TypeBounds(lower, upper) => upper + case AppliedType(TypeRef(_, ""), elemTyps) => + TypeRepr.typeConstructorOf(classOf[Seq[_]]).appliedTo(elemTyps) + case other => other + adjusted.asType match + case '[t] => TypeTree.of[t] + } + + object MockableDefinitions: + def find(tpe: TypeRepr, name: String, paramTypes: List[TypeRepr], appliedTypes: List[TypeRepr]): String = + def appliedTypesMatch(method: MockableDefinition, appliedTypes: List[TypeRepr]): Boolean = + method.tpe match + case poly: PolyType => poly.paramTypes.lengthCompare(appliedTypes) == 0 + case _ => appliedTypes.isEmpty + + def typesMatch(method: MockableDefinition, paramTypes: List[TypeRepr]): Boolean = + paramTypes.lengthCompare(method.parameterTypes) == 0 && + paramTypes.zip(method.parameterTypes).forall(_ <:< _) + + val method = MockableDefinitions(tpe) + .filter(m => m.symbol.name == name && typesMatch(m, paramTypes) && appliedTypesMatch(m, appliedTypes)) + .sortWith((a, b) => a.parameterTypes.zip(b.parameterTypes).forall(_ <:< _)) + .headOption + .getOrElse(report.errorAndAbort(s"Method with such signature not found")) + + method.mockValName + + + def apply(tpe: TypeRepr): List[MockableDefinition] = + val methods = (tpe.typeSymbol.methodMembers.toSet -- TypeRepr.of[Object].typeSymbol.methodMembers).toList + .filter(sym => !sym.flags.is(Flags.Private) && !sym.flags.is(Flags.Final) && !sym.flags.is(Flags.Mutable)) + .filterNot(sym => tpe.memberType(sym) match + case defaultParam @ ByNameType(AnnotatedType(_, Apply(Select(New(Inferred()), ""), Nil))) => true + case _ => false + ) + .zipWithIndex + .map((sym, idx) => MockableDefinition(idx, sym, tpe)) + + val vals = tpe.typeSymbol.fieldMembers + .filter(_.flags.is(Flags.Deferred)) + .map(sym => MockableDefinition(0, sym, tpe)) + methods ++ vals + diff --git a/shared/src/main/scala-3/org/scalamock/proxy/ProxyMockFactory.scala b/shared/src/main/scala-3/org/scalamock/proxy/ProxyMockFactory.scala new file mode 100644 index 00000000..c4dca0d4 --- /dev/null +++ b/shared/src/main/scala-3/org/scalamock/proxy/ProxyMockFactory.scala @@ -0,0 +1,46 @@ +// Copyright (c) ScalaMock Contributors (https://github.com/paulbutcher/ScalaMock/graphs/contributors) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package org.scalamock.proxy + +import org.scalamock.context.MockContext + +import java.lang.reflect.{InvocationHandler, Proxy as JavaProxy} +import scala.reflect.{ClassTag, classTag} + +trait ProxyMockFactory { + + protected def mock[T : ClassTag](implicit mockContext: MockContext) = + createProxy[T, Mock](new MockInvocationHandler(mockContext)) + + protected def stub[T : ClassTag](implicit mockContext: MockContext) = + createProxy[T, Stub](new StubInvocationHandler(mockContext)) + + private def createProxy[T : ClassTag, F : ClassTag](handler: InvocationHandler) = { + val classLoader = Thread.currentThread.getContextClassLoader + val interfaces = Array[Class[_]](classTag[T].runtimeClass, classTag[F].runtimeClass) + try { + JavaProxy.newProxyInstance(classLoader, interfaces, handler).asInstanceOf[T & F & scala.reflect.Selectable] + } catch { + case e: IllegalArgumentException => + throw new IllegalArgumentException("Unable to create proxy - possible classloader issue?", e) + } + } +} \ No newline at end of file diff --git a/shared/src/main/scala/org/scalamock/MockFactoryBase.scala b/shared/src/main/scala/org/scalamock/MockFactoryBase.scala index 342244f3..bc06709d 100644 --- a/shared/src/main/scala/org/scalamock/MockFactoryBase.scala +++ b/shared/src/main/scala/org/scalamock/MockFactoryBase.scala @@ -65,7 +65,7 @@ trait MockFactoryBase extends AbstractMockFactoryBase with MockContext { inContext(new OrderedHandlers(logging = true))(what) // https://issues.scala-lang.org/browse/SI-5831 - implicit val _factory = this + implicit val _factory: MockFactoryBase = this private def initializeExpectations(): Unit = { val initialHandlers = new UnorderedHandlers diff --git a/shared/src/main/scala/org/scalamock/function/MockFunction.scala b/shared/src/main/scala/org/scalamock/function/MockFunction.scala index b6cbe919..a3eb3179 100644 --- a/shared/src/main/scala/org/scalamock/function/MockFunction.scala +++ b/shared/src/main/scala/org/scalamock/function/MockFunction.scala @@ -36,8 +36,8 @@ class MockFunction0[R: Defaultable](mockContext: MockContext, name: Symbol) def expects() = mockContext.add(new CallHandler0[R](this)) def expects(matcher: FunctionAdapter0[Boolean]) = mockContext.add(new CallHandler0[R](this, matcher)) - def stubs() = mockContext.add(new CallHandler0[R](this)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter0[Boolean]) = mockContext.add(new CallHandler0[R](this, matcher)).anyNumberOfTimes + def stubs() = mockContext.add(new CallHandler0[R](this)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter0[Boolean]) = mockContext.add(new CallHandler0[R](this, matcher)).anyNumberOfTimes() } class MockFunction1[T1, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -46,8 +46,8 @@ class MockFunction1[T1, R: Defaultable](mockContext: MockContext, name: Symbol) def expects(v1: MockParameter[T1]) = mockContext.add(new CallHandler1[T1, R](this, v1)) def expects(matcher: FunctionAdapter1[T1, Boolean]) = mockContext.add(new CallHandler1[T1, R](this, matcher)) - def stubs(v1: MockParameter[T1]) = mockContext.add(new CallHandler1[T1, R](this, v1)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter1[T1, Boolean]) = mockContext.add(new CallHandler1[T1, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1]) = mockContext.add(new CallHandler1[T1, R](this, v1)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter1[T1, Boolean]) = mockContext.add(new CallHandler1[T1, R](this, matcher)).anyNumberOfTimes() } class MockFunction2[T1, T2, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -56,8 +56,8 @@ class MockFunction2[T1, T2, R: Defaultable](mockContext: MockContext, name: Symb def expects(v1: MockParameter[T1], v2: MockParameter[T2]) = mockContext.add(new CallHandler2[T1, T2, R](this, v1, v2)) def expects(matcher: FunctionAdapter2[T1, T2, Boolean]) = mockContext.add(new CallHandler2[T1, T2, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2]) = mockContext.add(new CallHandler2[T1, T2, R](this, v1, v2)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter2[T1, T2, Boolean]) = mockContext.add(new CallHandler2[T1, T2, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2]) = mockContext.add(new CallHandler2[T1, T2, R](this, v1, v2)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter2[T1, T2, Boolean]) = mockContext.add(new CallHandler2[T1, T2, R](this, matcher)).anyNumberOfTimes() } class MockFunction3[T1, T2, T3, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -66,8 +66,8 @@ class MockFunction3[T1, T2, T3, R: Defaultable](mockContext: MockContext, name: def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3]) = mockContext.add(new CallHandler3[T1, T2, T3, R](this, v1, v2, v3)) def expects(matcher: FunctionAdapter3[T1, T2, T3, Boolean]) = mockContext.add(new CallHandler3[T1, T2, T3, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3]) = mockContext.add(new CallHandler3[T1, T2, T3, R](this, v1, v2, v3)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter3[T1, T2, T3, Boolean]) = mockContext.add(new CallHandler3[T1, T2, T3, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3]) = mockContext.add(new CallHandler3[T1, T2, T3, R](this, v1, v2, v3)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter3[T1, T2, T3, Boolean]) = mockContext.add(new CallHandler3[T1, T2, T3, R](this, matcher)).anyNumberOfTimes() } class MockFunction4[T1, T2, T3, T4, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -76,8 +76,8 @@ class MockFunction4[T1, T2, T3, T4, R: Defaultable](mockContext: MockContext, na def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4]) = mockContext.add(new CallHandler4[T1, T2, T3, T4, R](this, v1, v2, v3, v4)) def expects(matcher: FunctionAdapter4[T1, T2, T3, T4, Boolean]) = mockContext.add(new CallHandler4[T1, T2, T3, T4, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4]) = mockContext.add(new CallHandler4[T1, T2, T3, T4, R](this, v1, v2, v3, v4)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter4[T1, T2, T3, T4, Boolean]) = mockContext.add(new CallHandler4[T1, T2, T3, T4, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4]) = mockContext.add(new CallHandler4[T1, T2, T3, T4, R](this, v1, v2, v3, v4)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter4[T1, T2, T3, T4, Boolean]) = mockContext.add(new CallHandler4[T1, T2, T3, T4, R](this, matcher)).anyNumberOfTimes() } class MockFunction5[T1, T2, T3, T4, T5, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -86,8 +86,8 @@ class MockFunction5[T1, T2, T3, T4, T5, R: Defaultable](mockContext: MockContext def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5]) = mockContext.add(new CallHandler5[T1, T2, T3, T4, T5, R](this, v1, v2, v3, v4, v5)) def expects(matcher: FunctionAdapter5[T1, T2, T3, T4, T5, Boolean]) = mockContext.add(new CallHandler5[T1, T2, T3, T4, T5, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5]) = mockContext.add(new CallHandler5[T1, T2, T3, T4, T5, R](this, v1, v2, v3, v4, v5)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter5[T1, T2, T3, T4, T5, Boolean]) = mockContext.add(new CallHandler5[T1, T2, T3, T4, T5, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5]) = mockContext.add(new CallHandler5[T1, T2, T3, T4, T5, R](this, v1, v2, v3, v4, v5)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter5[T1, T2, T3, T4, T5, Boolean]) = mockContext.add(new CallHandler5[T1, T2, T3, T4, T5, R](this, matcher)).anyNumberOfTimes() } class MockFunction6[T1, T2, T3, T4, T5, T6, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -96,8 +96,8 @@ class MockFunction6[T1, T2, T3, T4, T5, T6, R: Defaultable](mockContext: MockCon def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6]) = mockContext.add(new CallHandler6[T1, T2, T3, T4, T5, T6, R](this, v1, v2, v3, v4, v5, v6)) def expects(matcher: FunctionAdapter6[T1, T2, T3, T4, T5, T6, Boolean]) = mockContext.add(new CallHandler6[T1, T2, T3, T4, T5, T6, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6]) = mockContext.add(new CallHandler6[T1, T2, T3, T4, T5, T6, R](this, v1, v2, v3, v4, v5, v6)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter6[T1, T2, T3, T4, T5, T6, Boolean]) = mockContext.add(new CallHandler6[T1, T2, T3, T4, T5, T6, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6]) = mockContext.add(new CallHandler6[T1, T2, T3, T4, T5, T6, R](this, v1, v2, v3, v4, v5, v6)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter6[T1, T2, T3, T4, T5, T6, Boolean]) = mockContext.add(new CallHandler6[T1, T2, T3, T4, T5, T6, R](this, matcher)).anyNumberOfTimes() } class MockFunction7[T1, T2, T3, T4, T5, T6, T7, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -106,8 +106,8 @@ class MockFunction7[T1, T2, T3, T4, T5, T6, T7, R: Defaultable](mockContext: Moc def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7]) = mockContext.add(new CallHandler7[T1, T2, T3, T4, T5, T6, T7, R](this, v1, v2, v3, v4, v5, v6, v7)) def expects(matcher: FunctionAdapter7[T1, T2, T3, T4, T5, T6, T7, Boolean]) = mockContext.add(new CallHandler7[T1, T2, T3, T4, T5, T6, T7, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7]) = mockContext.add(new CallHandler7[T1, T2, T3, T4, T5, T6, T7, R](this, v1, v2, v3, v4, v5, v6, v7)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter7[T1, T2, T3, T4, T5, T6, T7, Boolean]) = mockContext.add(new CallHandler7[T1, T2, T3, T4, T5, T6, T7, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7]) = mockContext.add(new CallHandler7[T1, T2, T3, T4, T5, T6, T7, R](this, v1, v2, v3, v4, v5, v6, v7)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter7[T1, T2, T3, T4, T5, T6, T7, Boolean]) = mockContext.add(new CallHandler7[T1, T2, T3, T4, T5, T6, T7, R](this, matcher)).anyNumberOfTimes() } class MockFunction8[T1, T2, T3, T4, T5, T6, T7, T8, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -116,8 +116,8 @@ class MockFunction8[T1, T2, T3, T4, T5, T6, T7, T8, R: Defaultable](mockContext: def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8]) = mockContext.add(new CallHandler8[T1, T2, T3, T4, T5, T6, T7, T8, R](this, v1, v2, v3, v4, v5, v6, v7, v8)) def expects(matcher: FunctionAdapter8[T1, T2, T3, T4, T5, T6, T7, T8, Boolean]) = mockContext.add(new CallHandler8[T1, T2, T3, T4, T5, T6, T7, T8, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8]) = mockContext.add(new CallHandler8[T1, T2, T3, T4, T5, T6, T7, T8, R](this, v1, v2, v3, v4, v5, v6, v7, v8)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter8[T1, T2, T3, T4, T5, T6, T7, T8, Boolean]) = mockContext.add(new CallHandler8[T1, T2, T3, T4, T5, T6, T7, T8, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8]) = mockContext.add(new CallHandler8[T1, T2, T3, T4, T5, T6, T7, T8, R](this, v1, v2, v3, v4, v5, v6, v7, v8)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter8[T1, T2, T3, T4, T5, T6, T7, T8, Boolean]) = mockContext.add(new CallHandler8[T1, T2, T3, T4, T5, T6, T7, T8, R](this, matcher)).anyNumberOfTimes() } class MockFunction9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -126,8 +126,8 @@ class MockFunction9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R: Defaultable](mockCont def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9]) = mockContext.add(new CallHandler9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9)) def expects(matcher: FunctionAdapter9[T1, T2, T3, T4, T5, T6, T7, T8, T9, Boolean]) = mockContext.add(new CallHandler9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9]) = mockContext.add(new CallHandler9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter9[T1, T2, T3, T4, T5, T6, T7, T8, T9, Boolean]) = mockContext.add(new CallHandler9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9]) = mockContext.add(new CallHandler9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter9[T1, T2, T3, T4, T5, T6, T7, T8, T9, Boolean]) = mockContext.add(new CallHandler9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](this, matcher)).anyNumberOfTimes() } class MockFunction10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -136,8 +136,8 @@ class MockFunction10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R: Defaultable](mo def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10]) = mockContext.add(new CallHandler10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10)) def expects(matcher: FunctionAdapter10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, Boolean]) = mockContext.add(new CallHandler10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10]) = mockContext.add(new CallHandler10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, Boolean]) = mockContext.add(new CallHandler10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10]) = mockContext.add(new CallHandler10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, Boolean]) = mockContext.add(new CallHandler10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](this, matcher)).anyNumberOfTimes() } class MockFunction11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -146,8 +146,8 @@ class MockFunction11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R: Defaultabl def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11]) = mockContext.add(new CallHandler11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11)) def expects(matcher: FunctionAdapter11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, Boolean]) = mockContext.add(new CallHandler11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11]) = mockContext.add(new CallHandler11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, Boolean]) = mockContext.add(new CallHandler11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11]) = mockContext.add(new CallHandler11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, Boolean]) = mockContext.add(new CallHandler11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](this, matcher)).anyNumberOfTimes() } class MockFunction12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -156,8 +156,8 @@ class MockFunction12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R: Defau def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12]) = mockContext.add(new CallHandler12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12)) def expects(matcher: FunctionAdapter12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, Boolean]) = mockContext.add(new CallHandler12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12]) = mockContext.add(new CallHandler12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, Boolean]) = mockContext.add(new CallHandler12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12]) = mockContext.add(new CallHandler12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, Boolean]) = mockContext.add(new CallHandler12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](this, matcher)).anyNumberOfTimes() } class MockFunction13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -166,8 +166,8 @@ class MockFunction13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R: def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13]) = mockContext.add(new CallHandler13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13)) def expects(matcher: FunctionAdapter13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, Boolean]) = mockContext.add(new CallHandler13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13]) = mockContext.add(new CallHandler13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, Boolean]) = mockContext.add(new CallHandler13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13]) = mockContext.add(new CallHandler13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, Boolean]) = mockContext.add(new CallHandler13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](this, matcher)).anyNumberOfTimes() } class MockFunction14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -176,8 +176,8 @@ class MockFunction14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14]) = mockContext.add(new CallHandler14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14)) def expects(matcher: FunctionAdapter14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, Boolean]) = mockContext.add(new CallHandler14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14]) = mockContext.add(new CallHandler14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, Boolean]) = mockContext.add(new CallHandler14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14]) = mockContext.add(new CallHandler14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, Boolean]) = mockContext.add(new CallHandler14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](this, matcher)).anyNumberOfTimes() } class MockFunction15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -186,8 +186,8 @@ class MockFunction15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15]) = mockContext.add(new CallHandler15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)) def expects(matcher: FunctionAdapter15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, Boolean]) = mockContext.add(new CallHandler15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15]) = mockContext.add(new CallHandler15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, Boolean]) = mockContext.add(new CallHandler15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15]) = mockContext.add(new CallHandler15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, Boolean]) = mockContext.add(new CallHandler15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](this, matcher)).anyNumberOfTimes() } class MockFunction16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -196,8 +196,8 @@ class MockFunction16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16]) = mockContext.add(new CallHandler16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16)) def expects(matcher: FunctionAdapter16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, Boolean]) = mockContext.add(new CallHandler16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16]) = mockContext.add(new CallHandler16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, Boolean]) = mockContext.add(new CallHandler16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16]) = mockContext.add(new CallHandler16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, Boolean]) = mockContext.add(new CallHandler16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](this, matcher)).anyNumberOfTimes() } class MockFunction17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -206,8 +206,8 @@ class MockFunction17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17]) = mockContext.add(new CallHandler17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17)) def expects(matcher: FunctionAdapter17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, Boolean]) = mockContext.add(new CallHandler17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17]) = mockContext.add(new CallHandler17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, Boolean]) = mockContext.add(new CallHandler17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17]) = mockContext.add(new CallHandler17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, Boolean]) = mockContext.add(new CallHandler17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](this, matcher)).anyNumberOfTimes() } class MockFunction18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -216,8 +216,8 @@ class MockFunction18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18]) = mockContext.add(new CallHandler18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18)) def expects(matcher: FunctionAdapter18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, Boolean]) = mockContext.add(new CallHandler18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18]) = mockContext.add(new CallHandler18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, Boolean]) = mockContext.add(new CallHandler18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18]) = mockContext.add(new CallHandler18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, Boolean]) = mockContext.add(new CallHandler18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](this, matcher)).anyNumberOfTimes() } class MockFunction19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -226,8 +226,8 @@ class MockFunction19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19]) = mockContext.add(new CallHandler19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19)) def expects(matcher: FunctionAdapter19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, Boolean]) = mockContext.add(new CallHandler19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19]) = mockContext.add(new CallHandler19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, Boolean]) = mockContext.add(new CallHandler19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19]) = mockContext.add(new CallHandler19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, Boolean]) = mockContext.add(new CallHandler19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](this, matcher)).anyNumberOfTimes() } class MockFunction20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -236,8 +236,8 @@ class MockFunction20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20]) = mockContext.add(new CallHandler20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20)) def expects(matcher: FunctionAdapter20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, Boolean]) = mockContext.add(new CallHandler20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20]) = mockContext.add(new CallHandler20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, Boolean]) = mockContext.add(new CallHandler20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20]) = mockContext.add(new CallHandler20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, Boolean]) = mockContext.add(new CallHandler20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](this, matcher)).anyNumberOfTimes() } class MockFunction21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -246,8 +246,8 @@ class MockFunction21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20], v21: MockParameter[T21]) = mockContext.add(new CallHandler21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21)) def expects(matcher: FunctionAdapter21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, Boolean]) = mockContext.add(new CallHandler21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20], v21: MockParameter[T21]) = mockContext.add(new CallHandler21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, Boolean]) = mockContext.add(new CallHandler21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20], v21: MockParameter[T21]) = mockContext.add(new CallHandler21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, Boolean]) = mockContext.add(new CallHandler21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](this, matcher)).anyNumberOfTimes() } class MockFunction22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R: Defaultable](mockContext: MockContext, name: Symbol) @@ -256,7 +256,7 @@ class MockFunction22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 def expects(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20], v21: MockParameter[T21], v22: MockParameter[T22]) = mockContext.add(new CallHandler22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22)) def expects(matcher: FunctionAdapter22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, Boolean]) = mockContext.add(new CallHandler22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](this, matcher)) - def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20], v21: MockParameter[T21], v22: MockParameter[T22]) = mockContext.add(new CallHandler22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22)).anyNumberOfTimes - def stubs(matcher: FunctionAdapter22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, Boolean]) = mockContext.add(new CallHandler22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](this, matcher)).anyNumberOfTimes + def stubs(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20], v21: MockParameter[T21], v22: MockParameter[T22]) = mockContext.add(new CallHandler22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22)).anyNumberOfTimes() + def stubs(matcher: FunctionAdapter22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, Boolean]) = mockContext.add(new CallHandler22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](this, matcher)).anyNumberOfTimes() } diff --git a/shared/src/main/scala/org/scalamock/function/MockFunctions.scala b/shared/src/main/scala/org/scalamock/function/MockFunctions.scala index a2f88f44..37eaf6c9 100644 --- a/shared/src/main/scala/org/scalamock/function/MockFunctions.scala +++ b/shared/src/main/scala/org/scalamock/function/MockFunctions.scala @@ -27,8 +27,8 @@ trait MockFunctions { this: MockContext => import scala.language.implicitConversions protected case class FunctionName(name: Symbol) - protected implicit def functionName(name: Symbol) = FunctionName(name) - protected implicit def functionName(name: String) = FunctionName(Symbol(name)) + protected implicit def functionName(name: Symbol): FunctionName = FunctionName(name) + protected implicit def functionName(name: String): FunctionName = FunctionName(Symbol(name)) protected def mockFunction[R: Defaultable](name: FunctionName) = new MockFunction0[R](this, name.name) protected def mockFunction[T1, R: Defaultable](name: FunctionName) = new MockFunction1[T1, R](this, name.name) diff --git a/shared/src/main/scala/org/scalamock/function/StubFunction.scala b/shared/src/main/scala/org/scalamock/function/StubFunction.scala index 8c4bb778..27d37ee6 100644 --- a/shared/src/main/scala/org/scalamock/function/StubFunction.scala +++ b/shared/src/main/scala/org/scalamock/function/StubFunction.scala @@ -28,8 +28,8 @@ import org.scalamock.util.Defaultable class StubFunction0[R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction0[R](mockContext, name) { - def when() = mockContext.add((new CallHandler0[R](this)).anyNumberOfTimes) - def when(matcher: FunctionAdapter0[Boolean]) = mockContext.add((new CallHandler0[R](this, matcher)).anyNumberOfTimes) + def when() = mockContext.add((new CallHandler0[R](this)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter0[Boolean]) = mockContext.add((new CallHandler0[R](this, matcher)).anyNumberOfTimes()) def verify() = mockContext.add(new CallHandler0[R](this) with Verify) def verify(matcher: FunctionAdapter0[Boolean]) = mockContext.add(new CallHandler0[R](this, matcher) with Verify) @@ -40,8 +40,8 @@ class StubFunction0[R: Defaultable](mockContext: MockContext, name: Symbol) class StubFunction1[T1, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction1[T1, R](mockContext, name) { - def when(v1: MockParameter[T1]) = mockContext.add((new CallHandler1[T1, R](this, v1)).anyNumberOfTimes) - def when(matcher: FunctionAdapter1[T1, Boolean]) = mockContext.add((new CallHandler1[T1, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1]) = mockContext.add((new CallHandler1[T1, R](this, v1)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter1[T1, Boolean]) = mockContext.add((new CallHandler1[T1, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1]) = mockContext.add(new CallHandler1[T1, R](this, v1) with Verify) def verify(matcher: FunctionAdapter1[T1, Boolean]) = mockContext.add(new CallHandler1[T1, R](this, matcher) with Verify) @@ -52,8 +52,8 @@ class StubFunction1[T1, R: Defaultable](mockContext: MockContext, name: Symbol) class StubFunction2[T1, T2, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction2[T1, T2, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2]) = mockContext.add((new CallHandler2[T1, T2, R](this, v1, v2)).anyNumberOfTimes) - def when(matcher: FunctionAdapter2[T1, T2, Boolean]) = mockContext.add((new CallHandler2[T1, T2, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2]) = mockContext.add((new CallHandler2[T1, T2, R](this, v1, v2)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter2[T1, T2, Boolean]) = mockContext.add((new CallHandler2[T1, T2, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2]) = mockContext.add(new CallHandler2[T1, T2, R](this, v1, v2) with Verify) def verify(matcher: FunctionAdapter2[T1, T2, Boolean]) = mockContext.add(new CallHandler2[T1, T2, R](this, matcher) with Verify) @@ -64,8 +64,8 @@ class StubFunction2[T1, T2, R: Defaultable](mockContext: MockContext, name: Symb class StubFunction3[T1, T2, T3, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction3[T1, T2, T3, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3]) = mockContext.add((new CallHandler3[T1, T2, T3, R](this, v1, v2, v3)).anyNumberOfTimes) - def when(matcher: FunctionAdapter3[T1, T2, T3, Boolean]) = mockContext.add((new CallHandler3[T1, T2, T3, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3]) = mockContext.add((new CallHandler3[T1, T2, T3, R](this, v1, v2, v3)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter3[T1, T2, T3, Boolean]) = mockContext.add((new CallHandler3[T1, T2, T3, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3]) = mockContext.add(new CallHandler3[T1, T2, T3, R](this, v1, v2, v3) with Verify) def verify(matcher: FunctionAdapter3[T1, T2, T3, Boolean]) = mockContext.add(new CallHandler3[T1, T2, T3, R](this, matcher) with Verify) @@ -76,8 +76,8 @@ class StubFunction3[T1, T2, T3, R: Defaultable](mockContext: MockContext, name: class StubFunction4[T1, T2, T3, T4, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction4[T1, T2, T3, T4, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4]) = mockContext.add((new CallHandler4[T1, T2, T3, T4, R](this, v1, v2, v3, v4)).anyNumberOfTimes) - def when(matcher: FunctionAdapter4[T1, T2, T3, T4, Boolean]) = mockContext.add((new CallHandler4[T1, T2, T3, T4, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4]) = mockContext.add((new CallHandler4[T1, T2, T3, T4, R](this, v1, v2, v3, v4)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter4[T1, T2, T3, T4, Boolean]) = mockContext.add((new CallHandler4[T1, T2, T3, T4, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4]) = mockContext.add(new CallHandler4[T1, T2, T3, T4, R](this, v1, v2, v3, v4) with Verify) def verify(matcher: FunctionAdapter4[T1, T2, T3, T4, Boolean]) = mockContext.add(new CallHandler4[T1, T2, T3, T4, R](this, matcher) with Verify) @@ -88,8 +88,8 @@ class StubFunction4[T1, T2, T3, T4, R: Defaultable](mockContext: MockContext, na class StubFunction5[T1, T2, T3, T4, T5, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction5[T1, T2, T3, T4, T5, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5]) = mockContext.add((new CallHandler5[T1, T2, T3, T4, T5, R](this, v1, v2, v3, v4, v5)).anyNumberOfTimes) - def when(matcher: FunctionAdapter5[T1, T2, T3, T4, T5, Boolean]) = mockContext.add((new CallHandler5[T1, T2, T3, T4, T5, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5]) = mockContext.add((new CallHandler5[T1, T2, T3, T4, T5, R](this, v1, v2, v3, v4, v5)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter5[T1, T2, T3, T4, T5, Boolean]) = mockContext.add((new CallHandler5[T1, T2, T3, T4, T5, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5]) = mockContext.add(new CallHandler5[T1, T2, T3, T4, T5, R](this, v1, v2, v3, v4, v5) with Verify) def verify(matcher: FunctionAdapter5[T1, T2, T3, T4, T5, Boolean]) = mockContext.add(new CallHandler5[T1, T2, T3, T4, T5, R](this, matcher) with Verify) @@ -100,8 +100,8 @@ class StubFunction5[T1, T2, T3, T4, T5, R: Defaultable](mockContext: MockContext class StubFunction6[T1, T2, T3, T4, T5, T6, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction6[T1, T2, T3, T4, T5, T6, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6]) = mockContext.add((new CallHandler6[T1, T2, T3, T4, T5, T6, R](this, v1, v2, v3, v4, v5, v6)).anyNumberOfTimes) - def when(matcher: FunctionAdapter6[T1, T2, T3, T4, T5, T6, Boolean]) = mockContext.add((new CallHandler6[T1, T2, T3, T4, T5, T6, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6]) = mockContext.add((new CallHandler6[T1, T2, T3, T4, T5, T6, R](this, v1, v2, v3, v4, v5, v6)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter6[T1, T2, T3, T4, T5, T6, Boolean]) = mockContext.add((new CallHandler6[T1, T2, T3, T4, T5, T6, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6]) = mockContext.add(new CallHandler6[T1, T2, T3, T4, T5, T6, R](this, v1, v2, v3, v4, v5, v6) with Verify) def verify(matcher: FunctionAdapter6[T1, T2, T3, T4, T5, T6, Boolean]) = mockContext.add(new CallHandler6[T1, T2, T3, T4, T5, T6, R](this, matcher) with Verify) @@ -112,8 +112,8 @@ class StubFunction6[T1, T2, T3, T4, T5, T6, R: Defaultable](mockContext: MockCon class StubFunction7[T1, T2, T3, T4, T5, T6, T7, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction7[T1, T2, T3, T4, T5, T6, T7, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7]) = mockContext.add((new CallHandler7[T1, T2, T3, T4, T5, T6, T7, R](this, v1, v2, v3, v4, v5, v6, v7)).anyNumberOfTimes) - def when(matcher: FunctionAdapter7[T1, T2, T3, T4, T5, T6, T7, Boolean]) = mockContext.add((new CallHandler7[T1, T2, T3, T4, T5, T6, T7, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7]) = mockContext.add((new CallHandler7[T1, T2, T3, T4, T5, T6, T7, R](this, v1, v2, v3, v4, v5, v6, v7)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter7[T1, T2, T3, T4, T5, T6, T7, Boolean]) = mockContext.add((new CallHandler7[T1, T2, T3, T4, T5, T6, T7, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7]) = mockContext.add(new CallHandler7[T1, T2, T3, T4, T5, T6, T7, R](this, v1, v2, v3, v4, v5, v6, v7) with Verify) def verify(matcher: FunctionAdapter7[T1, T2, T3, T4, T5, T6, T7, Boolean]) = mockContext.add(new CallHandler7[T1, T2, T3, T4, T5, T6, T7, R](this, matcher) with Verify) @@ -124,8 +124,8 @@ class StubFunction7[T1, T2, T3, T4, T5, T6, T7, R: Defaultable](mockContext: Moc class StubFunction8[T1, T2, T3, T4, T5, T6, T7, T8, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction8[T1, T2, T3, T4, T5, T6, T7, T8, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8]) = mockContext.add((new CallHandler8[T1, T2, T3, T4, T5, T6, T7, T8, R](this, v1, v2, v3, v4, v5, v6, v7, v8)).anyNumberOfTimes) - def when(matcher: FunctionAdapter8[T1, T2, T3, T4, T5, T6, T7, T8, Boolean]) = mockContext.add((new CallHandler8[T1, T2, T3, T4, T5, T6, T7, T8, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8]) = mockContext.add((new CallHandler8[T1, T2, T3, T4, T5, T6, T7, T8, R](this, v1, v2, v3, v4, v5, v6, v7, v8)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter8[T1, T2, T3, T4, T5, T6, T7, T8, Boolean]) = mockContext.add((new CallHandler8[T1, T2, T3, T4, T5, T6, T7, T8, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8]) = mockContext.add(new CallHandler8[T1, T2, T3, T4, T5, T6, T7, T8, R](this, v1, v2, v3, v4, v5, v6, v7, v8) with Verify) def verify(matcher: FunctionAdapter8[T1, T2, T3, T4, T5, T6, T7, T8, Boolean]) = mockContext.add(new CallHandler8[T1, T2, T3, T4, T5, T6, T7, T8, R](this, matcher) with Verify) @@ -136,8 +136,8 @@ class StubFunction8[T1, T2, T3, T4, T5, T6, T7, T8, R: Defaultable](mockContext: class StubFunction9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9]) = mockContext.add((new CallHandler9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9)).anyNumberOfTimes) - def when(matcher: FunctionAdapter9[T1, T2, T3, T4, T5, T6, T7, T8, T9, Boolean]) = mockContext.add((new CallHandler9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9]) = mockContext.add((new CallHandler9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter9[T1, T2, T3, T4, T5, T6, T7, T8, T9, Boolean]) = mockContext.add((new CallHandler9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9]) = mockContext.add(new CallHandler9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9) with Verify) def verify(matcher: FunctionAdapter9[T1, T2, T3, T4, T5, T6, T7, T8, T9, Boolean]) = mockContext.add(new CallHandler9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](this, matcher) with Verify) @@ -148,8 +148,8 @@ class StubFunction9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R: Defaultable](mockCont class StubFunction10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10]) = mockContext.add((new CallHandler10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10)).anyNumberOfTimes) - def when(matcher: FunctionAdapter10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, Boolean]) = mockContext.add((new CallHandler10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10]) = mockContext.add((new CallHandler10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, Boolean]) = mockContext.add((new CallHandler10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10]) = mockContext.add(new CallHandler10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) with Verify) def verify(matcher: FunctionAdapter10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, Boolean]) = mockContext.add(new CallHandler10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](this, matcher) with Verify) @@ -160,8 +160,8 @@ class StubFunction10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R: Defaultable](mo class StubFunction11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11]) = mockContext.add((new CallHandler11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11)).anyNumberOfTimes) - def when(matcher: FunctionAdapter11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, Boolean]) = mockContext.add((new CallHandler11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11]) = mockContext.add((new CallHandler11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, Boolean]) = mockContext.add((new CallHandler11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11]) = mockContext.add(new CallHandler11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) with Verify) def verify(matcher: FunctionAdapter11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, Boolean]) = mockContext.add(new CallHandler11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](this, matcher) with Verify) @@ -172,8 +172,8 @@ class StubFunction11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R: Defaultabl class StubFunction12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12]) = mockContext.add((new CallHandler12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12)).anyNumberOfTimes) - def when(matcher: FunctionAdapter12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, Boolean]) = mockContext.add((new CallHandler12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12]) = mockContext.add((new CallHandler12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, Boolean]) = mockContext.add((new CallHandler12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12]) = mockContext.add(new CallHandler12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) with Verify) def verify(matcher: FunctionAdapter12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, Boolean]) = mockContext.add(new CallHandler12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](this, matcher) with Verify) @@ -184,8 +184,8 @@ class StubFunction12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R: Defau class StubFunction13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13]) = mockContext.add((new CallHandler13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13)).anyNumberOfTimes) - def when(matcher: FunctionAdapter13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, Boolean]) = mockContext.add((new CallHandler13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13]) = mockContext.add((new CallHandler13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, Boolean]) = mockContext.add((new CallHandler13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13]) = mockContext.add(new CallHandler13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) with Verify) def verify(matcher: FunctionAdapter13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, Boolean]) = mockContext.add(new CallHandler13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](this, matcher) with Verify) @@ -196,8 +196,8 @@ class StubFunction13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R: class StubFunction14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14]) = mockContext.add((new CallHandler14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14)).anyNumberOfTimes) - def when(matcher: FunctionAdapter14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, Boolean]) = mockContext.add((new CallHandler14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14]) = mockContext.add((new CallHandler14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, Boolean]) = mockContext.add((new CallHandler14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14]) = mockContext.add(new CallHandler14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) with Verify) def verify(matcher: FunctionAdapter14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, Boolean]) = mockContext.add(new CallHandler14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](this, matcher) with Verify) @@ -208,8 +208,8 @@ class StubFunction14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 class StubFunction15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15]) = mockContext.add((new CallHandler15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)).anyNumberOfTimes) - def when(matcher: FunctionAdapter15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, Boolean]) = mockContext.add((new CallHandler15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15]) = mockContext.add((new CallHandler15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, Boolean]) = mockContext.add((new CallHandler15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15]) = mockContext.add(new CallHandler15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) with Verify) def verify(matcher: FunctionAdapter15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, Boolean]) = mockContext.add(new CallHandler15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](this, matcher) with Verify) @@ -220,8 +220,8 @@ class StubFunction15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 class StubFunction16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16]) = mockContext.add((new CallHandler16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16)).anyNumberOfTimes) - def when(matcher: FunctionAdapter16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, Boolean]) = mockContext.add((new CallHandler16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16]) = mockContext.add((new CallHandler16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, Boolean]) = mockContext.add((new CallHandler16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16]) = mockContext.add(new CallHandler16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) with Verify) def verify(matcher: FunctionAdapter16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, Boolean]) = mockContext.add(new CallHandler16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](this, matcher) with Verify) @@ -232,8 +232,8 @@ class StubFunction16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 class StubFunction17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17]) = mockContext.add((new CallHandler17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17)).anyNumberOfTimes) - def when(matcher: FunctionAdapter17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, Boolean]) = mockContext.add((new CallHandler17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17]) = mockContext.add((new CallHandler17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, Boolean]) = mockContext.add((new CallHandler17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17]) = mockContext.add(new CallHandler17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) with Verify) def verify(matcher: FunctionAdapter17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, Boolean]) = mockContext.add(new CallHandler17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](this, matcher) with Verify) @@ -244,8 +244,8 @@ class StubFunction17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 class StubFunction18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18]) = mockContext.add((new CallHandler18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18)).anyNumberOfTimes) - def when(matcher: FunctionAdapter18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, Boolean]) = mockContext.add((new CallHandler18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18]) = mockContext.add((new CallHandler18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, Boolean]) = mockContext.add((new CallHandler18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18]) = mockContext.add(new CallHandler18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) with Verify) def verify(matcher: FunctionAdapter18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, Boolean]) = mockContext.add(new CallHandler18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](this, matcher) with Verify) @@ -256,8 +256,8 @@ class StubFunction18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 class StubFunction19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19]) = mockContext.add((new CallHandler19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19)).anyNumberOfTimes) - def when(matcher: FunctionAdapter19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, Boolean]) = mockContext.add((new CallHandler19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19]) = mockContext.add((new CallHandler19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, Boolean]) = mockContext.add((new CallHandler19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19]) = mockContext.add(new CallHandler19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) with Verify) def verify(matcher: FunctionAdapter19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, Boolean]) = mockContext.add(new CallHandler19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](this, matcher) with Verify) @@ -268,8 +268,8 @@ class StubFunction19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 class StubFunction20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20]) = mockContext.add((new CallHandler20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20)).anyNumberOfTimes) - def when(matcher: FunctionAdapter20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, Boolean]) = mockContext.add((new CallHandler20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20]) = mockContext.add((new CallHandler20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, Boolean]) = mockContext.add((new CallHandler20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20]) = mockContext.add(new CallHandler20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) with Verify) def verify(matcher: FunctionAdapter20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, Boolean]) = mockContext.add(new CallHandler20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](this, matcher) with Verify) @@ -280,8 +280,8 @@ class StubFunction20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 class StubFunction21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20], v21: MockParameter[T21]) = mockContext.add((new CallHandler21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21)).anyNumberOfTimes) - def when(matcher: FunctionAdapter21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, Boolean]) = mockContext.add((new CallHandler21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20], v21: MockParameter[T21]) = mockContext.add((new CallHandler21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, Boolean]) = mockContext.add((new CallHandler21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20], v21: MockParameter[T21]) = mockContext.add(new CallHandler21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) with Verify) def verify(matcher: FunctionAdapter21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, Boolean]) = mockContext.add(new CallHandler21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](this, matcher) with Verify) @@ -292,8 +292,8 @@ class StubFunction21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 class StubFunction22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R: Defaultable](mockContext: MockContext, name: Symbol) extends FakeFunction22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](mockContext, name) { - def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20], v21: MockParameter[T21], v22: MockParameter[T22]) = mockContext.add((new CallHandler22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22)).anyNumberOfTimes) - def when(matcher: FunctionAdapter22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, Boolean]) = mockContext.add((new CallHandler22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](this, matcher)).anyNumberOfTimes) + def when(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20], v21: MockParameter[T21], v22: MockParameter[T22]) = mockContext.add((new CallHandler22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22)).anyNumberOfTimes()) + def when(matcher: FunctionAdapter22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, Boolean]) = mockContext.add((new CallHandler22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](this, matcher)).anyNumberOfTimes()) def verify(v1: MockParameter[T1], v2: MockParameter[T2], v3: MockParameter[T3], v4: MockParameter[T4], v5: MockParameter[T5], v6: MockParameter[T6], v7: MockParameter[T7], v8: MockParameter[T8], v9: MockParameter[T9], v10: MockParameter[T10], v11: MockParameter[T11], v12: MockParameter[T12], v13: MockParameter[T13], v14: MockParameter[T14], v15: MockParameter[T15], v16: MockParameter[T16], v17: MockParameter[T17], v18: MockParameter[T18], v19: MockParameter[T19], v20: MockParameter[T20], v21: MockParameter[T21], v22: MockParameter[T22]) = mockContext.add(new CallHandler22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](this, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) with Verify) def verify(matcher: FunctionAdapter22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, Boolean]) = mockContext.add(new CallHandler22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](this, matcher) with Verify) diff --git a/shared/src/main/scala/org/scalamock/handlers/Handlers.scala b/shared/src/main/scala/org/scalamock/handlers/Handlers.scala index bc5926ff..60df5b9e 100644 --- a/shared/src/main/scala/org/scalamock/handlers/Handlers.scala +++ b/shared/src/main/scala/org/scalamock/handlers/Handlers.scala @@ -30,7 +30,7 @@ private[scalamock] abstract class Handlers extends Handler { override def toString = handlers.flatMap { h => // see https://github.com/scala/bug/issues/11125. linesIterator would be better but we crossbuild with 2.11 - scala.Predef.augmentString(h.toString).lines.toArray.map { l => " " + l } + scala.Predef.augmentString(h.toString).linesIterator.toArray.map { l => " " + l } }.mkString(s"$prefix {\n", "\n", "\n}") protected var handlers = new ListBuffer[Handler] diff --git a/shared/src/main/scala/org/scalamock/matchers/ArgAssert.scala b/shared/src/main/scala/org/scalamock/matchers/ArgAssert.scala index 9073f8b9..abb172dc 100644 --- a/shared/src/main/scala/org/scalamock/matchers/ArgAssert.scala +++ b/shared/src/main/scala/org/scalamock/matchers/ArgAssert.scala @@ -27,7 +27,7 @@ package org.scalamock.matchers import scala.reflect.ClassTag /** Matcher that uses provided assertions block to perform matching */ -protected class ArgAssert[T](assertions: T => Unit, clue: Option[String]) +protected class ArgAssert[T](assertions: T => Any, clue: Option[String]) (implicit classTag: ClassTag[T]) extends Matcher[T] { override def safeEquals(that: T) = { diff --git a/shared/src/main/scala/org/scalamock/matchers/Matchers.scala b/shared/src/main/scala/org/scalamock/matchers/Matchers.scala index c0676f00..5b062d2d 100644 --- a/shared/src/main/scala/org/scalamock/matchers/Matchers.scala +++ b/shared/src/main/scala/org/scalamock/matchers/Matchers.scala @@ -52,12 +52,12 @@ trait Matchers { this: MockContext => protected def where[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](matcher: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => Boolean) = new FunctionAdapter21(matcher) protected def where[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](matcher: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => Boolean) = new FunctionAdapter22(matcher) - protected def assertArgs[T1](matcher: (T1) => Unit): FunctionAdapter1[T1, Boolean] = { + protected def assertArgs[T1](matcher: (T1) => Any): FunctionAdapter1[T1, Boolean] = { val f: (T1) => Boolean = (t1) => { matcher(t1); true } new FunctionAdapter1[T1, Boolean](f) } - protected def assertArgs[T1, T2](matcher: (T1, T2) => Unit): FunctionAdapter2[T1, T2, Boolean] = { + protected def assertArgs[T1, T2](matcher: (T1, T2) => Any): FunctionAdapter2[T1, T2, Boolean] = { val f: (T1, T2) => Boolean = (t1, t2) => { matcher(t1, t2); true } new FunctionAdapter2[T1, T2, Boolean](f) } @@ -169,10 +169,10 @@ trait Matchers { this: MockContext => protected def argThat[T](predicate: T => Boolean) (implicit classTag: ClassTag[T]): MatcherBase = new ArgThat[T](predicate, clue = None) - protected def argAssert[T](clue: String)(assertions: T => Unit) + protected def argAssert[T](clue: String)(assertions: T => Any) (implicit classTag: ClassTag[T]): MatcherBase = new ArgAssert[T](assertions, clue = Some(clue)) - protected def argAssert[T](assertions: T => Unit) + protected def argAssert[T](assertions: T => Any) (implicit classTag: ClassTag[T]): MatcherBase = new ArgAssert[T](assertions, clue = None) protected def capture[T](cap: Capture[T]) = new CaptureMatcher[T](cap) @@ -180,10 +180,10 @@ trait Matchers { this: MockContext => protected def * = new MatchAny protected class EpsilonMatcher(d: Double) { - def unary_~() = new MatchEpsilon(d) + def unary_~ = new MatchEpsilon(d) } - protected implicit def doubleToEpsilon(d: Double) = new EpsilonMatcher(d) - protected implicit def toMockParameter[T](v: T) = new MockParameter(v) - protected implicit def matcherBaseToMockParameter[T](m: MatcherBase) = new MockParameter[T](m) + protected implicit def doubleToEpsilon(d: Double): EpsilonMatcher = new EpsilonMatcher(d) + protected implicit def toMockParameter[T](v: T): MockParameter[T] = new MockParameter(v) + protected implicit def matcherBaseToMockParameter[T](m: MatcherBase): MockParameter[T] = new MockParameter[T](m) } diff --git a/shared/src/main/scala/org/scalamock/matchers/MockParameter.scala b/shared/src/main/scala/org/scalamock/matchers/MockParameter.scala index b93208b6..6302ffa0 100644 --- a/shared/src/main/scala/org/scalamock/matchers/MockParameter.scala +++ b/shared/src/main/scala/org/scalamock/matchers/MockParameter.scala @@ -29,8 +29,8 @@ package org.scalamock.matchers class MockParameter[T] protected (private[scalamock] val value: AnyRef, dummy: Boolean = false) { - def this(v: T) = this(v.asInstanceOf[AnyRef]) - def this(v: MatcherBase) = this(v.asInstanceOf[AnyRef]) + def this(v: T) = this(v.asInstanceOf[AnyRef], false) + def this(v: MatcherBase) = this(v.asInstanceOf[AnyRef], false) override def hashCode() = value.## diff --git a/shared/src/main/scala/org/scalamock/proxy/FakeFunction.scala b/shared/src/main/scala/org/scalamock/proxy/FakeFunction.scala index 576e744b..241c5800 100644 --- a/shared/src/main/scala/org/scalamock/proxy/FakeFunction.scala +++ b/shared/src/main/scala/org/scalamock/proxy/FakeFunction.scala @@ -42,8 +42,8 @@ abstract class FakeFunction(mockContext: MockContext, name: Symbol) } private[proxy] def seq2Product(seq: Seq[AnyRef]): Product = seq match { - case List() => None case null => None + case Seq() => None case Seq(v1) => Tuple1(v1) case Seq(v1, v2) => (v1, v2) case Seq(v1, v2, v3) => (v1, v2, v3) @@ -54,7 +54,6 @@ abstract class FakeFunction(mockContext: MockContext, name: Symbol) case Seq(v1, v2, v3, v4, v5, v6, v7, v8) => (v1, v2, v3, v4, v5, v6, v7, v8) case Seq(v1, v2, v3, v4, v5, v6, v7, v8, v9) => (v1, v2, v3, v4, v5, v6, v7, v8, v9) case Seq(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) => (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) - case Seq(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) => (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) case Seq(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) => (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) case Seq(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) => (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) case Seq(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) => (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) diff --git a/shared/src/main/scala/org/scalamock/proxy/InvocationHandlerBase.scala b/shared/src/main/scala/org/scalamock/proxy/InvocationHandlerBase.scala index 2f2a1316..fcc2cf33 100644 --- a/shared/src/main/scala/org/scalamock/proxy/InvocationHandlerBase.scala +++ b/shared/src/main/scala/org/scalamock/proxy/InvocationHandlerBase.scala @@ -30,9 +30,9 @@ abstract class InvocationHandlerBase[T <: FakeFunction] extends InvocationHandle val name = Symbol(method.getName) lazy val fake = getFake(args(0).asInstanceOf[Symbol]) (handle(name, fake).getOrElse(name match { - case 'toString => s"proxy mock object ${System.identityHashCode(proxy)}" - case 'hashCode => System.identityHashCode(proxy) - case 'equals => (args(0) eq proxy) + case Symbol("toString") => s"proxy mock object ${System.identityHashCode(proxy)}" + case Symbol("hashCode") => System.identityHashCode(proxy) + case Symbol("equals") => (args(0) eq proxy) case _ => getFake(name).handle(args) })).asInstanceOf[AnyRef] } diff --git a/shared/src/main/scala/org/scalamock/proxy/MockInvocationHandler.scala b/shared/src/main/scala/org/scalamock/proxy/MockInvocationHandler.scala index d636c9e3..aabe2a52 100644 --- a/shared/src/main/scala/org/scalamock/proxy/MockInvocationHandler.scala +++ b/shared/src/main/scala/org/scalamock/proxy/MockInvocationHandler.scala @@ -26,7 +26,7 @@ class MockInvocationHandler(mockContext: MockContext) extends InvocationHandlerB protected override def handle(name: Symbol, fake: => MockFunction) = name match { - case 'expects => Some(fake.expectationHandler) + case Symbol("expects") => Some(fake.expectationHandler()) case _ => None } diff --git a/shared/src/main/scala/org/scalamock/proxy/StubFunction.scala b/shared/src/main/scala/org/scalamock/proxy/StubFunction.scala index 792bc7d7..5bfae946 100644 --- a/shared/src/main/scala/org/scalamock/proxy/StubFunction.scala +++ b/shared/src/main/scala/org/scalamock/proxy/StubFunction.scala @@ -33,7 +33,7 @@ class StubFunction(mockContext: MockContext, name: Symbol) extends FakeFunction( def verifyHandler() = new VerifyHander private[proxy] class WhenHander extends ExpectationHandler { - override def apply(args: MockParameter[Any]*) = super.apply(args:_*).anyNumberOfTimes + override def apply(args: MockParameter[Any]*) = super.apply(args:_*).anyNumberOfTimes() } private[proxy] class VerifyHander extends ExpectationHandler { diff --git a/shared/src/main/scala/org/scalamock/proxy/StubInvocationHandler.scala b/shared/src/main/scala/org/scalamock/proxy/StubInvocationHandler.scala index 48e47348..b69cbc88 100644 --- a/shared/src/main/scala/org/scalamock/proxy/StubInvocationHandler.scala +++ b/shared/src/main/scala/org/scalamock/proxy/StubInvocationHandler.scala @@ -26,8 +26,8 @@ class StubInvocationHandler(mockContext: MockContext) extends InvocationHandlerB protected override def handle(name: Symbol, fake: => StubFunction) = name match { - case 'when => Some(fake.whenHandler) - case 'verify => Some(fake.verifyHandler) + case Symbol("when") => Some(fake.whenHandler()) + case Symbol("verify") => Some(fake.verifyHandler()) case _ => None } diff --git a/shared/src/main/scala/org/scalamock/scalatest/AsyncMockFactoryBase.scala b/shared/src/main/scala/org/scalamock/scalatest/AsyncMockFactoryBase.scala index 96cc2c8a..d1838222 100644 --- a/shared/src/main/scala/org/scalamock/scalatest/AsyncMockFactoryBase.scala +++ b/shared/src/main/scala/org/scalamock/scalatest/AsyncMockFactoryBase.scala @@ -12,7 +12,7 @@ import scala.util.{Failure, Success} trait AsyncMockFactoryBase extends MockContext with Mock with MockFunctions with Matchers { //! TODO - https://issues.scala-lang.org/browse/SI-5831 - implicit val _factory = this + implicit val _factory: AsyncMockFactoryBase = this implicit def executionContext: ExecutionContext diff --git a/shared/src/main/scala/org/scalamock/util/Defaultable.scala b/shared/src/main/scala/org/scalamock/util/Defaultable.scala index 2e48646e..558abd96 100644 --- a/shared/src/main/scala/org/scalamock/util/Defaultable.scala +++ b/shared/src/main/scala/org/scalamock/util/Defaultable.scala @@ -28,7 +28,7 @@ trait Defaultable[T] { trait LowPriorityDefaultable { - implicit def default[T] = new Defaultable[T] { val default = null.asInstanceOf[T] } + implicit def default[T]: Defaultable[T] = new Defaultable[T] { val default = null.asInstanceOf[T] } } object Defaultable extends LowPriorityDefaultable { diff --git a/shared/src/test/scala/com/paulbutcher/test/PolymorphicTrait.scala b/shared/src/test/scala-2/com.paulbutcher.test/PolymorphicTrait.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/PolymorphicTrait.scala rename to shared/src/test/scala-2/com.paulbutcher.test/PolymorphicTrait.scala diff --git a/shared/src/test/scala-2/com.paulbutcher.test/VarSpec.scala b/shared/src/test/scala-2/com.paulbutcher.test/VarSpec.scala new file mode 100644 index 00000000..ad61b0ca --- /dev/null +++ b/shared/src/test/scala-2/com.paulbutcher.test/VarSpec.scala @@ -0,0 +1,26 @@ +package com.paulbutcher.test + +import org.scalamock.scalatest.MockFactory +import org.scalatest.funspec.AnyFunSpec + +class VarSpec extends AnyFunSpec with MockFactory { + + autoVerify = false + + trait Vars { + var aVar: String + var concreteVar = "foo" + } + + it("mock traits with vars") { + withExpectations { + val m = mock[Vars] + (m.aVar_= _).expects("foo") + (() => m.aVar).expects().returning("bar") + m.aVar = "foo" + assertResult("bar") { + m.aVar + } + } + } +} \ No newline at end of file diff --git a/shared/src/test/scala-3/com/paulbutcher/test/PolymorphicTrait.scala b/shared/src/test/scala-3/com/paulbutcher/test/PolymorphicTrait.scala new file mode 100644 index 00000000..bda6bacb --- /dev/null +++ b/shared/src/test/scala-3/com/paulbutcher/test/PolymorphicTrait.scala @@ -0,0 +1,37 @@ +// Copyright (c) 2011-2015 ScalaMock Contributors (https://github.com/paulbutcher/ScalaMock/graphs/contributors) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package com.paulbutcher.test + +trait PolymorphicTrait[T] { + def method[U](x: Int, y: T, z: U): T + + trait Embedded[V] { + trait ATrait[A, B] + + def innerTrait(t: T, v: V): ATrait[T, V] + def outerTrait(t: T, v: V): PolymorphicTrait.this.ATrait[T, V] + + def innerTraitInOption(x: Option[ATrait[T, V]]): Option[ATrait[T, V]] + def innerTraitInOptions(x: Option[Option[ATrait[T, V]]]): Option[Option[ATrait[T, V]]] + } + + trait ATrait[A, B] +} \ No newline at end of file diff --git a/shared/src/test/scala-3/com/paulbutcher/test/Scala3Spec.scala b/shared/src/test/scala-3/com/paulbutcher/test/Scala3Spec.scala new file mode 100644 index 00000000..b7bdb78c --- /dev/null +++ b/shared/src/test/scala-3/com/paulbutcher/test/Scala3Spec.scala @@ -0,0 +1,42 @@ +package com.paulbutcher.test + +import org.scalamock.scalatest.MockFactory +import org.scalatest.funspec.AnyFunSpec +import org.scalatest.matchers.should.Matchers + +class Scala3Spec extends AnyFunSpec with MockFactory with Matchers { + + + it("mock traits with parameters") { + trait Test(val a: Int) { + def method(x: Int): Int + } + + val m = mock[Test] + } + + it("mock parameters with & and | types") { + trait A + trait B + trait Test { + def method(x: Int | String, y: A & B): Int + } + + val m = mock[Test] + + (m.method _).expects(*, *).returns(0) + m.method(1, new A with B) shouldBe 0 + } + + it("mock methods returning function") { + trait Test { + def method(x: Int): Int => String + } + + val m = mock[Test] + + (m.method _).expects(*).returns((_: Int) => "f") + m.method(1)(0) shouldBe "f" + + } +} diff --git a/shared/src/test/scala-3/com/paulbutcher/test/VarSpec.scala b/shared/src/test/scala-3/com/paulbutcher/test/VarSpec.scala new file mode 100644 index 00000000..40294f95 --- /dev/null +++ b/shared/src/test/scala-3/com/paulbutcher/test/VarSpec.scala @@ -0,0 +1,19 @@ +package com.paulbutcher.test + +import org.scalamock.scalatest.MockFactory +import org.scalatest.funspec.AnyFunSpec + +class VarSpec extends AnyFunSpec with MockFactory { + + trait Vars { + var aVar: Int = scala.compiletime.uninitialized + var concreteVar = "foo" + } + + it("mock traits with vars") { + val m = mock[Vars] + m.aVar = 6 + m.concreteVar = "bar" + } + +} diff --git a/shared/src/test/scala/com/paulbutcher/test/SpecializedClass.scala b/shared/src/test/scala/com/paulbutcher/test/SpecializedClass.scala index eeda730d..d8ade5e9 100644 --- a/shared/src/test/scala/com/paulbutcher/test/SpecializedClass.scala +++ b/shared/src/test/scala/com/paulbutcher/test/SpecializedClass.scala @@ -20,6 +20,6 @@ package com.paulbutcher.test -class SpecializedClass[@specialized T] { +trait SpecializedClass[@specialized T] { def identity(x: T) = x } \ No newline at end of file diff --git a/shared/src/test/scala/com/paulbutcher/test/SpecializedClass2.scala b/shared/src/test/scala/com/paulbutcher/test/SpecializedClass2.scala index e0669d0b..40c5535c 100644 --- a/shared/src/test/scala/com/paulbutcher/test/SpecializedClass2.scala +++ b/shared/src/test/scala/com/paulbutcher/test/SpecializedClass2.scala @@ -20,6 +20,6 @@ package com.paulbutcher.test -class SpecializedClass2[@specialized T1, @specialized T2] extends SpecializedClass[T1] { +trait SpecializedClass2[@specialized T1, @specialized T2] extends SpecializedClass[T1] { def identity2(x: T1, y: T2) = (x,y) } \ No newline at end of file diff --git a/shared/src/test/scala/com/paulbutcher/test/TestTrait.scala b/shared/src/test/scala/com/paulbutcher/test/TestTrait.scala index ad94a67c..31d1620a 100644 --- a/shared/src/test/scala/com/paulbutcher/test/TestTrait.scala +++ b/shared/src/test/scala/com/paulbutcher/test/TestTrait.scala @@ -22,7 +22,6 @@ package com.paulbutcher.test import some.other.pkg._ -import scala.reflect.runtime.universe.TypeTag trait TestTrait { def nullary: String @@ -48,8 +47,7 @@ trait TestTrait { def upperBound[T <: Product](x: T): Int def lowerBound[T >: U, U](x: T, y: List[U]): String - def contextBound[T: TypeTag](x: T): String - def viewBound[T <% Ordered[T]](x: T, y: T): Boolean + def contextBound[T: Ordering](x: T): String def withImplementation(x: Int) = x * x @@ -57,9 +55,6 @@ trait TestTrait { def otherPackageUpperBound[T <: SomeClass](x: T): T def explicitPackageReference(x: yet.another.pkg.YetAnotherClass): yet.another.pkg.YetAnotherClass def explicitPackageUpperBound[T <: yet.another.pkg.YetAnotherClass](x: T): T - - var aVar: String - var concreteVar = "foo" val aVal: String val concreteVal = "foo" diff --git a/shared/src/test/scala/com/paulbutcher/test/features/CallCountTest.scala b/shared/src/test/scala/com/paulbutcher/test/features/CallCountTest.scala index 779ab3eb..3a363008 100644 --- a/shared/src/test/scala/com/paulbutcher/test/features/CallCountTest.scala +++ b/shared/src/test/scala/com/paulbutcher/test/features/CallCountTest.scala @@ -21,7 +21,6 @@ package com.paulbutcher.test.features import com.paulbutcher.test.IsolatedSpec -import org.scalatest.{OneInstancePerTest, Suite} class CallCountTest extends IsolatedSpec { @@ -37,17 +36,17 @@ class CallCountTest extends IsolatedSpec { } it should "fail if a method isn't called often enough (once)" in withExpectations { - intFunMock.expects(42).once + intFunMock.expects(42).once() intFunMock(42) } it should "not fail if a method is called once (once)" in withExpectations { - intFunMock.expects(42).once + intFunMock.expects(42).once() intFunMock(42) } it should "fail if a method is called too often (once)" in withExpectations { - intFunMock.expects(42).twice + intFunMock.expects(42).twice() intFunMock(42) intFunMock(42) @@ -57,14 +56,14 @@ class CallCountTest extends IsolatedSpec { it should "fail if a method isn't called often enough (twice)" in { intercept[ExpectationException] { withExpectations { - intFunMock.expects(42).twice + intFunMock.expects(42).twice() intFunMock(42) } } } it should "fail if a method is called too often (twice)" in withExpectations { - intFunMock.expects(42).twice + intFunMock.expects(42).twice() intFunMock(42) intFunMock(42) @@ -72,22 +71,22 @@ class CallCountTest extends IsolatedSpec { } it should "handle noMoreThanTwice call count (zero)" in withExpectations { - intFunMock.expects(2).noMoreThanTwice + intFunMock.expects(2).noMoreThanTwice() } it should "handle noMoreThanTwice call count (one)" in withExpectations { - intFunMock.expects(2).noMoreThanTwice + intFunMock.expects(2).noMoreThanTwice() intFunMock(2) } it should "handle noMoreThanTwice call count (two)" in withExpectations { - intFunMock.expects(2).noMoreThanTwice + intFunMock.expects(2).noMoreThanTwice() intFunMock(2) intFunMock(2) } it should "handle noMoreThanTwice call count (three)" in withExpectations { - intFunMock.expects(2).noMoreThanTwice + intFunMock.expects(2).noMoreThanTwice() intFunMock(2) intFunMock(2) intercept[ExpectationException] { intFunMock(42) } @@ -111,7 +110,7 @@ class CallCountTest extends IsolatedSpec { } it should "handle repeated(3).times call count (3)" in withExpectations { - intFunMock.expects(2).repeated(3).times + intFunMock.expects(2).repeated(3).times() intFunMock(2) intFunMock(2) diff --git a/shared/src/test/scala/com/paulbutcher/test/features/OrderingTest.scala b/shared/src/test/scala/com/paulbutcher/test/features/OrderingTest.scala index ddad8900..7e7adc4c 100644 --- a/shared/src/test/scala/com/paulbutcher/test/features/OrderingTest.scala +++ b/shared/src/test/scala/com/paulbutcher/test/features/OrderingTest.scala @@ -72,8 +72,8 @@ class OrderingTest extends IsolatedSpec { def setupExpectations(): Unit = { inSequence { intFunMock.expects(1).returning(1).repeated(3 to 7) - intFunMock.expects(2).returning(2).once - intFunMock.expects(3).returning(3).twice + intFunMock.expects(2).returning(2).once() + intFunMock.expects(3).returning(3).twice() } } } @@ -141,8 +141,8 @@ class OrderingTest extends IsolatedSpec { it should "not match a previous item in the sequence" in withExpectations { inSequence { - intFunMock.expects(1).returning(1).anyNumberOfTimes - intFunMock.expects(2).returning(2).once + intFunMock.expects(1).returning(1).anyNumberOfTimes() + intFunMock.expects(2).returning(2).once() } intFunMock(1) shouldBe 1 @@ -153,8 +153,8 @@ class OrderingTest extends IsolatedSpec { it should "fail if unexpected call is made" in { demandExpectationException { inSequence { - intFunMock.expects(1).returning(1).anyNumberOfTimes - intFunMock.expects(2).returning(2).once + intFunMock.expects(1).returning(1).anyNumberOfTimes() + intFunMock.expects(2).returning(2).once() } intFunMock(1) shouldBe 1 @@ -235,10 +235,10 @@ class OrderingTest extends IsolatedSpec { it should "handle a sequence in which functions are called zero times" in withExpectations { val m = mockFunction[Int, Unit] inSequence { - m.expects(1).once - m.expects(2).never - m.expects(3).anyNumberOfTimes - m.expects(4).once + m.expects(1).once() + m.expects(2).never() + m.expects(3).anyNumberOfTimes() + m.expects(4).once() } m(1) m(4) @@ -257,7 +257,7 @@ class OrderingTest extends IsolatedSpec { m.expects("2.2.2.1") m.expects("2.2.2.2") } - m.expects("2.2.3").anyNumberOfTimes + m.expects("2.2.3").anyNumberOfTimes() } m.expects("2.3") } diff --git a/shared/src/test/scala/com/paulbutcher/test/features/ReturnTest.scala b/shared/src/test/scala/com/paulbutcher/test/features/ReturnTest.scala index 577a065e..20365938 100644 --- a/shared/src/test/scala/com/paulbutcher/test/features/ReturnTest.scala +++ b/shared/src/test/scala/com/paulbutcher/test/features/ReturnTest.scala @@ -45,7 +45,7 @@ class ReturnTest extends IsolatedSpec { } it should "return a calculated return value" in { - intToIntMock.expects(*).onCall({ arg: Int => arg + 1 }) + intToIntMock.expects(*).onCall({ (arg: Int) => arg + 1 }) intToIntMock(42) shouldBe (43) } @@ -75,16 +75,16 @@ class ReturnTest extends IsolatedSpec { } it should "handle stacked expectations (onCall)" in { - intToStringMock.expects(*).onCall({ _: Int => "1" }) - intToStringMock.expects(*).onCall({ _: Int => "2" }) + intToStringMock.expects(*).onCall({ (_: Int) => "1" }) + intToStringMock.expects(*).onCall({ (_: Int) => "2" }) intToStringMock(1) shouldBe ("1") intToStringMock(2) shouldBe ("2") } it should "handle stacked expectations (onCall) and call count" in { - intToStringMock.expects(*).onCall({ _: Int => "1" }).twice - intToStringMock.expects(*).onCall({ _: Int => "2" }) + intToStringMock.expects(*).onCall({ (_: Int) => "1" }).twice() + intToStringMock.expects(*).onCall({ (_: Int) => "2" }) intToStringMock(1) shouldBe ("1") intToStringMock(1) shouldBe ("1") @@ -92,8 +92,8 @@ class ReturnTest extends IsolatedSpec { } it should "match return value to provided arguments (returning)" in { - intToStringMock.expects(1).onCall({ _: Int => "1" }) - intToStringMock.expects(2).onCall({ _: Int => "2" }) + intToStringMock.expects(1).onCall({ (_: Int) => "1" }) + intToStringMock.expects(2).onCall({ (_: Int) => "2" }) intToStringMock(2) shouldBe ("2") intToStringMock(1) shouldBe ("1") diff --git a/shared/src/test/scala/com/paulbutcher/test/features/ThrowTest.scala b/shared/src/test/scala/com/paulbutcher/test/features/ThrowTest.scala index 0e5b6979..896c482d 100644 --- a/shared/src/test/scala/com/paulbutcher/test/features/ThrowTest.scala +++ b/shared/src/test/scala/com/paulbutcher/test/features/ThrowTest.scala @@ -43,7 +43,7 @@ class ThrowTest extends IsolatedSpec { } it should "throw computed exception" in { - intFunMock.expects(*).repeat(3 to 3).onCall({ arg: Int => + intFunMock.expects(*).repeat(3 to 3).onCall({ (arg: Int) => if (arg == 1) throw new TestException() else if (arg == 2) throw new AnotherTestException() else "Foo" diff --git a/shared/src/test/scala/com/paulbutcher/test/matchers/MatchEpsilonTest.scala b/shared/src/test/scala/com/paulbutcher/test/matchers/MatchEpsilonTest.scala index 03159a1c..dca2e003 100644 --- a/shared/src/test/scala/com/paulbutcher/test/matchers/MatchEpsilonTest.scala +++ b/shared/src/test/scala/com/paulbutcher/test/matchers/MatchEpsilonTest.scala @@ -28,20 +28,20 @@ class MatchEpsilonTest extends AnyFreeSpec { "MatchEpsilon should" - { "match anything that's close to the given value" in { - assert(new MatchEpsilon(1.0) == 1.0) - assert(new MatchEpsilon(1.0) == 1.0f) - assert(new MatchEpsilon(1.0) == 1.0001) - assert(new MatchEpsilon(1.0) == 1.0001f) - assert(new MatchEpsilon(1.0) == 1) + assert(new MatchEpsilon(1.0).equals(1.0)) + assert(new MatchEpsilon(1.0).equals(1.0f)) + assert(new MatchEpsilon(1.0).equals(1.0001)) + assert(new MatchEpsilon(1.0).equals(1.0001f)) + assert(new MatchEpsilon(1.0).equals(1)) } "not match anything that's not close enough" in { - assert(!(new MatchEpsilon(1.0) == 1.1)) - assert(!(new MatchEpsilon(1.0) == 0.9)) + assert(!(new MatchEpsilon(1.0).equals(1.1))) + assert(!(new MatchEpsilon(1.0).equals(0.9))) } "only match numbers" in { - assert(!(new MatchEpsilon(1.0) == "foo")) + assert(!(new MatchEpsilon(1.0).equals("foo"))) } } } diff --git a/shared/src/test/scala/com/paulbutcher/test/matchers/MatchersTest.scala b/shared/src/test/scala/com/paulbutcher/test/matchers/MatchersTest.scala index 34bae887..31667411 100644 --- a/shared/src/test/scala/com/paulbutcher/test/matchers/MatchersTest.scala +++ b/shared/src/test/scala/com/paulbutcher/test/matchers/MatchersTest.scala @@ -66,8 +66,8 @@ class MatchersTest extends IsolatedSpec { behavior of "where matcher" it can "be used to create complex predicates (one parameter)" in withExpectations { - (userDatabaseMock.storeUser _).expects(where { user: User => user.age > 18 && user.name.startsWith("A") }).returning("matched").twice - (userDatabaseMock.storeUser _).expects(*).returning("unmatched").once + (userDatabaseMock.storeUser _).expects(where { (user: User) => user.age > 18 && user.name.startsWith("A") }).returning("matched").twice() + (userDatabaseMock.storeUser _).expects(*).returning("unmatched").once() userDatabaseMock.storeUser(User("Adam", 22)) shouldBe "matched" userDatabaseMock.storeUser(User("Eve", 21)) shouldBe "unmatched" @@ -75,8 +75,8 @@ class MatchersTest extends IsolatedSpec { } it can "be used to create complex predicates (two parameters)" in withExpectations { - (testMock.twoParams _).expects(where { (x, y) => x + y > 100 }).returning("matched").twice - (testMock.twoParams _).expects(*, *).returning("unmatched").once + (testMock.twoParams _).expects(where { (x, y) => x + y > 100 }).returning("matched").twice() + (testMock.twoParams _).expects(*, *).returning("unmatched").once() testMock.twoParams(99, 2.0) shouldBe "matched" testMock.twoParams(50, 49.0) shouldBe "unmatched" @@ -86,12 +86,12 @@ class MatchersTest extends IsolatedSpec { behavior of "assertArgs matcher" it can "be used to fail tests early (one parameter)" in withExpectations { - (userDatabaseMock.storeUser _).expects(assertArgs { user: User => + (userDatabaseMock.storeUser _).expects(assertArgs { (user: User) => user.age shouldBe 18 user.name should startWith("A") }).returning("matched") - (userDatabaseMock.storeUser _).expects(assertArgs { user: User => + (userDatabaseMock.storeUser _).expects(assertArgs { (user: User) => user.age shouldBe 21 user.name should startWith("E") }).returning("matched2") @@ -112,10 +112,10 @@ class MatchersTest extends IsolatedSpec { it can "be used to create complex predicates" in withExpectations { (userDatabaseMock.addUserAddress _) - .expects(*, argThat { address: Address => address.city == "Berlin" }) + .expects(*, argThat { (address: Address) => address.city == "Berlin" }) .returning("matched") (userDatabaseMock.addUserAddress _) - .expects(*, argThat("Someone in London") { address: Address => address.city == "London" }) + .expects(*, argThat("Someone in London") { (address: Address) => address.city == "London" }) .returning("matched") (userDatabaseMock.addUserAddress _).expects(*, *).returning("unmatched") @@ -125,7 +125,7 @@ class MatchersTest extends IsolatedSpec { } it should "be displayed correctly" in withExpectations { - val expectation = (userDatabaseMock.addUserAddress _).expects(*, argThat { _: Address => true }).never() + val expectation = (userDatabaseMock.addUserAddress _).expects(*, argThat { (_: Address) => true }).never() expectation.toString() should include("UserDatabase.addUserAddress(*, argThat[Address])") } @@ -135,11 +135,11 @@ class MatchersTest extends IsolatedSpec { val testUser = User("John", 23) (userDatabaseMock.addUserAddress _) - .expects(*, argAssert { address: Address => + .expects(*, argAssert { (address: Address) => address.city shouldBe "Berlin" }) .returning("matched") (userDatabaseMock.addUserAddress _) - .expects(*, argAssert("Someone in London") { address: Address => + .expects(*, argAssert("Someone in London") { (address: Address) => address.city shouldBe "London" }) .returning("matched") @@ -151,7 +151,7 @@ class MatchersTest extends IsolatedSpec { val testUser = User("John", 23) (userDatabaseMock.addUserAddress _) - .expects(*, argAssert { address: Address => + .expects(*, argAssert { (address: Address) => address.city shouldBe "London" }) a[TestFailedException] shouldBe thrownBy { @@ -163,7 +163,7 @@ class MatchersTest extends IsolatedSpec { } it should "be displayed correctly" in withExpectations { - val expectation = (userDatabaseMock.addUserAddress _).expects(*, argAssert{ _: Address => ()}).never() + val expectation = (userDatabaseMock.addUserAddress _).expects(*, argAssert{ (_: Address) => ()}).never() expectation.toString() should include("UserDatabase.addUserAddress(*, argAssert[Address])") } diff --git a/shared/src/test/scala/com/paulbutcher/test/matchers/MockParameterTest.scala b/shared/src/test/scala/com/paulbutcher/test/matchers/MockParameterTest.scala index 1f5c6da1..1bec816f 100644 --- a/shared/src/test/scala/com/paulbutcher/test/matchers/MockParameterTest.scala +++ b/shared/src/test/scala/com/paulbutcher/test/matchers/MockParameterTest.scala @@ -29,15 +29,15 @@ class MockParameterTest extends AnyFreeSpec with Matchers { "A mock parameter should" - { "be equal" - { "if its value is equal" in { - new MockParameter(42) shouldBe 42 + new MockParameter(42) shouldEqual 42 } "with a wildcard" in { - new MockParameter[Int](new MatchAny) shouldBe 123 + new MockParameter[Int](new MatchAny) shouldEqual 123 } "with an epsilon" in { - new MockParameter[Double](new MatchEpsilon(1.0)) shouldBe 1.0001 + new MockParameter[Double](new MatchEpsilon(1.0)) shouldEqual 1.0001 } } diff --git a/shared/src/test/scala/com/paulbutcher/test/mock/MockNamingTest.scala b/shared/src/test/scala/com/paulbutcher/test/mock/MockNamingTest.scala index 0eb29eb2..99500d61 100644 --- a/shared/src/test/scala/com/paulbutcher/test/mock/MockNamingTest.scala +++ b/shared/src/test/scala/com/paulbutcher/test/mock/MockNamingTest.scala @@ -31,7 +31,7 @@ class MockNamingTest extends IsolatedSpec { behavior of "Mock" it should "have a sensible method name when mocking a method without parameters" in { - getMockMethodName(() => m.noParams) shouldBe " TestTrait.noParams" + getMockMethodName(() => m.noParams()) shouldBe " TestTrait.noParams" } it should "have a sensible method name when mocking one parameter method" in { @@ -80,12 +80,12 @@ class MockNamingTest extends IsolatedSpec { it should "have sensible default name assigned" in { val myMock = mock[TestTrait] - getMockMethodName(() => myMock.noParams) shouldBe " TestTrait.noParams" + getMockMethodName(() => myMock.noParams()) shouldBe " TestTrait.noParams" } it should "have consistent names of mocked methods" in { val myMock = mock[TestTrait] - getMockMethodName(() => myMock.noParams) shouldBe " TestTrait.noParams" + getMockMethodName(() => myMock.noParams()) shouldBe " TestTrait.noParams" getMockMethodName(myMock.twoParams _) shouldBe " TestTrait.twoParams" // not } diff --git a/shared/src/test/scala/com/paulbutcher/test/mock/MockTest.scala b/shared/src/test/scala/com/paulbutcher/test/mock/MockTest.scala index 2dbbe726..cdd5f31a 100644 --- a/shared/src/test/scala/com/paulbutcher/test/mock/MockTest.scala +++ b/shared/src/test/scala/com/paulbutcher/test/mock/MockTest.scala @@ -24,7 +24,6 @@ import org.scalamock.function.FunctionAdapter1 import org.scalamock.scalatest.MockFactory import scala.reflect.ClassTag -import scala.reflect.runtime.universe.{TypeTag, typeTag} import scala.util.{Failure, Try} import com.paulbutcher.test._ @@ -37,15 +36,18 @@ class MockTest extends AnyFreeSpec with MockFactory with Matchers { autoVerify = false "Mocks should" - { - "cope with a var" in { + //! TODO - in scala 3 we can't distinguish abstract var setters with non abstract vars setters + // TODO and override modifier is not allowed when overriding abstract vars + /* + "cope with a var" in { withExpectations { val m = mock[TestTrait] (m.aVar_= _).expects("foo") - (m.aVar _).expects().returning("bar") + (() => m.aVar).expects().returning("bar") m.aVar = "foo" - assertResult("bar") { m.aVar } + assertResult(null) { m.aVar } } - } + }*/ "fail if an unexpected method call is made" in { withExpectations { @@ -74,7 +76,7 @@ class MockTest extends AnyFreeSpec with MockFactory with Matchers { "cope with nullary methods" in { withExpectations { val m = mock[TestTrait] - (m.nullary _).expects().returning("a return value") + (() => m.nullary).expects().returning("a return value") assertResult("a return value") { m.nullary } } } @@ -152,25 +154,6 @@ class MockTest extends AnyFreeSpec with MockFactory with Matchers { } } - "cope with methods with by name parameters" in { - withExpectations { - val m = mock[TestTrait] - (m.byNameParam _).expects(*).returning("it worked") - assertResult("it worked") { m.byNameParam(42) } - } - } - - //! TODO - find a way to make this less ugly - "match methods with by name parameters" in { - withExpectations { - val m = mock[TestTrait] - val f: (=> Int) => Boolean = { x => x == 1 && x == 2 } - ((m.byNameParam _): (=> Int) => String).expects(new FunctionAdapter1(f)).returning("it works") - var y = 0 - assertResult("it works") { m.byNameParam { y += 1; y } } - } - } - "cope with methods with implicit parameters" in { withExpectations { implicit val y: Double = 1.23 @@ -216,16 +199,16 @@ class MockTest extends AnyFreeSpec with MockFactory with Matchers { } } - //! TODO - currently doesn't work because we can't override concrete vars + /* //! TODO - currently doesn't work because we can't override concrete vars "cope with a non-abstract var" ignore { withExpectations { val m = mock[TestTrait] (m.concreteVar_= _).expects("foo") - (m.concreteVar _).expects().returning("bar") + (() => m.concreteVar).expects().returning("bar") m.concreteVar = "foo" assertResult("bar") { m.concreteVar } } - } + }*/ "cope with curried varargs" in { withExpectations { @@ -239,6 +222,7 @@ class MockTest extends AnyFreeSpec with MockFactory with Matchers { } } + "cope with a val" in { withExpectations { val m = mock[TestTrait] @@ -268,25 +252,27 @@ class MockTest extends AnyFreeSpec with MockFactory with Matchers { } } + "mock an embeddded trait" in { withExpectations { val m = mock[TestTrait] val e = mock[m.Embedded] - (() => m.referencesEmbedded).expects().returning(e) - assertResult(e) { m.referencesEmbedded } + (() => m.referencesEmbedded()).expects().returning(e) + assertResult(e) { m.referencesEmbedded() } } } + "handle projected types correctly" in { withExpectations { val m = mock[TestTrait] val e = mock[m.Embedded] val o = mock[m.ATrait] val i = mock[e.ATrait] - (() => e.innerTraitProjected).expects().returning(i) - (() => e.outerTraitProjected).expects().returning(o) - assertResult(o) { e.outerTraitProjected } - assertResult(i) { e.innerTraitProjected } + (() => e.innerTraitProjected()).expects().returning(i) + (() => e.outerTraitProjected()).expects().returning(o) + assertResult(o) { e.outerTraitProjected() } + assertResult(i) { e.innerTraitProjected() } } } @@ -296,10 +282,10 @@ class MockTest extends AnyFreeSpec with MockFactory with Matchers { val e = mock[m.Embedded] val o = mock[m.ATrait] val i = mock[e.ATrait] - (() => e.innerTrait).expects().returning(i) - (() => e.outerTrait).expects().returning(o) - assertResult(o) { e.outerTrait } - assertResult(i) { e.innerTrait } + (() => e.innerTrait()).expects().returning(i) + (() => e.outerTrait()).expects().returning(o) + assertResult(o) { e.outerTrait() } + assertResult(i) { e.innerTrait() } } } @@ -319,15 +305,6 @@ class MockTest extends AnyFreeSpec with MockFactory with Matchers { } } - //! TODO - fails in 2.11 - // "cope with view bounds" in { - // withExpectations { - // val m = mock[TestTrait] - // (m.viewBound(_: Int, _: Int)(_: Int => Ordered[Int])).expects(1, 2, *).returning(true) - // assertResult(true) { m.viewBound(1, 2) } - // } - // } - "mock a polymorphic trait" in { withExpectations { val m = mock[PolymorphicTrait[String]] @@ -440,11 +417,14 @@ class MockTest extends AnyFreeSpec with MockFactory with Matchers { provider.find[User](13) shouldBe a[Failure[_]] } + "mock class with nonempty default constructor" in { class TestNonEmptyDefaultConstructor(a: Int, b: String, c: AnyRef, d: Any)(aa: String) val m = mock[TestNonEmptyDefaultConstructor] } + + // TODO: issue 150 - causes a compiler error // "cope with curried function returning methods" in { // withExpectations { @@ -456,6 +436,7 @@ class MockTest extends AnyFreeSpec with MockFactory with Matchers { // } + // issue 132 "mock a trait which has a final method" in withExpectations { trait FinalMethodTrait { @@ -469,6 +450,7 @@ class MockTest extends AnyFreeSpec with MockFactory with Matchers { // m.someFinalMethod _ expects * anyNumberOfTimes() } + "mock a trait which has a protected method" in withExpectations { trait FooTrait { def somePublicMethod(param: String): Unit diff --git a/shared/src/test/scala/com/paulbutcher/test/mock/OverloadedMethodsTest.scala b/shared/src/test/scala/com/paulbutcher/test/mock/OverloadedMethodsTest.scala index 597bd3a2..9eb3a132 100644 --- a/shared/src/test/scala/com/paulbutcher/test/mock/OverloadedMethodsTest.scala +++ b/shared/src/test/scala/com/paulbutcher/test/mock/OverloadedMethodsTest.scala @@ -108,7 +108,7 @@ class OverloadedMethodsTest extends IsolatedSpec { } they should "mock PrintStream.print(String)" in { // test for issue #39 - import java.io.{ OutputStream, PrintStream } + import java.io.{OutputStream, PrintStream} class MockablePrintStream extends PrintStream(mock[OutputStream], false) val m = mock[MockablePrintStream] @@ -116,6 +116,7 @@ class OverloadedMethodsTest extends IsolatedSpec { m.print("foo") } + they should "handle type aliases correctly" in { type X = Int type Y = X @@ -134,6 +135,7 @@ class OverloadedMethodsTest extends IsolatedSpec { m.foo()(new ConcreteType()) } + override def newInstance = new OverloadedMethodsTest } diff --git a/shared/src/test/scala/com/paulbutcher/test/stub/StubFunctionTest.scala b/shared/src/test/scala/com/paulbutcher/test/stub/StubFunctionTest.scala index cdc77bd0..4dd8c751 100644 --- a/shared/src/test/scala/com/paulbutcher/test/stub/StubFunctionTest.scala +++ b/shared/src/test/scala/com/paulbutcher/test/stub/StubFunctionTest.scala @@ -79,7 +79,7 @@ class StubFunctionTest extends AnyFreeSpec with MockFactory { "unless told otherwise" in { withExpectations { val m = stubFunction[String] - m.when().returns("a return value").twice + m.when().returns("a return value").twice() assertResult("a return value") { m() } assertResult("a return value") { m() } assertResult(null) { m() } @@ -121,7 +121,7 @@ class StubFunctionTest extends AnyFreeSpec with MockFactory { intercept[ExpectationException](withExpectations { val m = stubFunction[String, Int, Int] m("foo", 42) - m.verify("foo", 42).twice + m.verify("foo", 42).twice() }) } @@ -131,7 +131,7 @@ class StubFunctionTest extends AnyFreeSpec with MockFactory { m("foo", 42) m("foo", 42) m("foo", 42) - m.verify("foo", 42).twice + m.verify("foo", 42).twice() }) } @@ -152,8 +152,8 @@ class StubFunctionTest extends AnyFreeSpec with MockFactory { m(1, 2) m(2, 1) m(2, 1) - m.verify(where { _ < _}).once - m.verify(where { _ > _}).twice + m.verify(where { _ < _}).once() + m.verify(where { _ > _}).twice() } } } @@ -176,8 +176,8 @@ class StubFunctionTest extends AnyFreeSpec with MockFactory { repeat(2) { m(44) } inSequence { m.verify(42).repeated(3 to 7) - m.verify(43).once - m.verify(44).twice + m.verify(43).once() + m.verify(44).twice() } } } @@ -189,8 +189,8 @@ class StubFunctionTest extends AnyFreeSpec with MockFactory { m(44) inSequence { m.verify(42).repeated(3 to 7) - m.verify(43).once - m.verify(44).twice + m.verify(43).once() + m.verify(44).twice() } }) } @@ -202,8 +202,8 @@ class StubFunctionTest extends AnyFreeSpec with MockFactory { repeat(1) { m(43) } inSequence { m.verify(42).repeated(3 to 7) - m.verify(43).once - m.verify(44).twice + m.verify(43).once() + m.verify(44).twice() } }) } @@ -215,7 +215,7 @@ class StubFunctionTest extends AnyFreeSpec with MockFactory { m(43) m(42) inSequence { - m.verify(42).anyNumberOfTimes + m.verify(42).anyNumberOfTimes() m.verify(43) m.verify(42) } @@ -256,10 +256,10 @@ class StubFunctionTest extends AnyFreeSpec with MockFactory { m(1) m(4) inSequence { - m.verify(1).once - m.verify(2).never - m.verify(3).anyNumberOfTimes - m.verify(4).once + m.verify(1).once() + m.verify(2).never() + m.verify(3).anyNumberOfTimes() + m.verify(4).once() } } } @@ -287,7 +287,7 @@ class StubFunctionTest extends AnyFreeSpec with MockFactory { m.verify("2.2.2.1") m.verify("2.2.2.2") } - m.verify("2.2.3").anyNumberOfTimes + m.verify("2.2.3").anyNumberOfTimes() } m.verify("2.3") } @@ -332,8 +332,8 @@ class StubFunctionTest extends AnyFreeSpec with MockFactory { assertResult("m1") { m1(42) } assertResult("m2") { m2(42) } - m1.verify(42).once - m2.verify(42).once + m1.verify(42).once() + m2.verify(42).once() } } } diff --git a/shared/src/test/scala/com/paulbutcher/test/stub/StubNamingTest.scala b/shared/src/test/scala/com/paulbutcher/test/stub/StubNamingTest.scala index 9b099ff0..b40b5842 100644 --- a/shared/src/test/scala/com/paulbutcher/test/stub/StubNamingTest.scala +++ b/shared/src/test/scala/com/paulbutcher/test/stub/StubNamingTest.scala @@ -31,12 +31,12 @@ class StubNamingTest extends IsolatedSpec { it should "have a sensible method name when mocking a method without parameters" in { val myStub = stub[TestTrait] - getStubMethodName(() => myStub.noParams) shouldBe " TestTrait.noParams" + getStubMethodName(() => myStub.noParams()) shouldBe " TestTrait.noParams" } it can "be named using string literal" in { val myStub = stub[TestTrait]("stub name") - getStubMethodName(() => myStub.noParams) shouldBe " TestTrait.noParams" + getStubMethodName(() => myStub.noParams()) shouldBe " TestTrait.noParams" } // NOTE: MockNamingTest contains more test cases related to mock naming diff --git a/shared/src/test/scala/com/paulbutcher/test/stub/StubTest.scala b/shared/src/test/scala/com/paulbutcher/test/stub/StubTest.scala index 21ae4a99..78eaa989 100644 --- a/shared/src/test/scala/com/paulbutcher/test/stub/StubTest.scala +++ b/shared/src/test/scala/com/paulbutcher/test/stub/StubTest.scala @@ -56,13 +56,13 @@ class StubTest extends IsolatedSpec { it should "verify calls" in withExpectations { m.twoParams(42, 1.23) m.twoParams(42, 1.23) - (m.twoParams _).verify(42, 1.23).twice + (m.twoParams _).verify(42, 1.23).twice() } it should "fail when verification fails because of parameter mismatch" in { demandExpectationException { m.twoParams(42, 1.00) - (m.twoParams _).verify(42, 1.23).once + (m.twoParams _).verify(42, 1.23).once() } } @@ -70,7 +70,7 @@ class StubTest extends IsolatedSpec { demandExpectationException { m.twoParams(42, 1.23) m.twoParams(42, 1.23) - (m.twoParams _).verify(42, 1.23).once + (m.twoParams _).verify(42, 1.23).once() } } override def newInstance = new StubTest diff --git a/shared/src/test/scala/org/scalamock/jstests/matchers/MatchEpsilonTest.scala b/shared/src/test/scala/org/scalamock/jstests/matchers/MatchEpsilonTest.scala index 503e2d1d..32dbd3f1 100644 --- a/shared/src/test/scala/org/scalamock/jstests/matchers/MatchEpsilonTest.scala +++ b/shared/src/test/scala/org/scalamock/jstests/matchers/MatchEpsilonTest.scala @@ -28,20 +28,20 @@ class MatchEpsilonTest extends AnyFreeSpec { "MatchEpsilon should" - { "match anything that's close to the given value" in { - assert(new MatchEpsilon(1.0) == 1.0) - assert(new MatchEpsilon(1.0) == 1.0f) - assert(new MatchEpsilon(1.0) == 1.0001) - assert(new MatchEpsilon(1.0) == 1.0001f) - assert(new MatchEpsilon(1.0) == 1) + assert(new MatchEpsilon(1.0).equals(1.0)) + assert(new MatchEpsilon(1.0).equals(1.0f)) + assert(new MatchEpsilon(1.0).equals(1.0001)) + assert(new MatchEpsilon(1.0).equals(1.0001f)) + assert(new MatchEpsilon(1.0).equals(1)) } "not match anything that's not close enough" in { - assert(!(new MatchEpsilon(1.0) == 1.1)) - assert(!(new MatchEpsilon(1.0) == 0.9)) + assert(!(new MatchEpsilon(1.0).equals(1.1))) + assert(!(new MatchEpsilon(1.0).equals(0.9))) } "only match numbers" in { - assert(!(new MatchEpsilon(1.0) == "foo")) + assert(!(new MatchEpsilon(1.0).equals("foo"))) } } } diff --git a/shared/src/test/scala/org/scalamock/test/scalatest/AsyncSyncMixinTest.scala b/shared/src/test/scala/org/scalamock/test/scalatest/AsyncSyncMixinTest.scala index abccef9d..87d8030a 100644 --- a/shared/src/test/scala/org/scalamock/test/scalatest/AsyncSyncMixinTest.scala +++ b/shared/src/test/scala/org/scalamock/test/scalatest/AsyncSyncMixinTest.scala @@ -21,23 +21,25 @@ package org.scalamock.test.scalatest import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.flatspec.AsyncFlatSpec -import org.scalamock.scalatest.MockFactory -import org.scalamock.scalatest.AsyncMockFactory +import org.scalatest._ /** * Tests for issue #371 */ +@Ignore class AsyncSyncMixinTest extends AnyFlatSpec { "MockFactory" should "be mixed only with Any*Spec and not Async*Spec traits" in { assertCompiles("new AnyFlatSpec with MockFactory") - assertDoesNotCompile("new AsyncFlatSpec with MockFactory") + + //! FIXME //github.com/scalatest/scalatest/issues/2283 + //assertDoesNotCompile("new AsyncFlatSpec with MockFactory") } "AsyncMockFactory" should "be mixed only with Async*Spec and not Any*Spec traits" in { assertCompiles("new AsyncFlatSpec with AsyncMockFactory") - assertDoesNotCompile("new AnyFlatSpec with AsyncMockFactory") + //! FIXME //github.com/scalatest/scalatest/issues/2283 + //assertDoesNotCompile("new AnyFlatSpec with AsyncMockFactory") } } diff --git a/shared/src/test/scala/org/scalamock/test/scalatest/StackableSuitesTest.scala b/shared/src/test/scala/org/scalamock/test/scalatest/StackableSuitesTest.scala index b6215213..3a1170e3 100644 --- a/shared/src/test/scala/org/scalamock/test/scalatest/StackableSuitesTest.scala +++ b/shared/src/test/scala/org/scalamock/test/scalatest/StackableSuitesTest.scala @@ -47,7 +47,7 @@ class StackableSuitesTest extends AnyFlatSpec with Matchers with TestSuiteRunner class TestedSuite extends AnyFunSuite with SuiteWrapper with MockFactory with Matchers { test("execute block of code") { val mockedTrait = mock[TestTrait] - (mockedTrait.oneParamMethod _).expects(1).onCall { arg: Int => + (mockedTrait.oneParamMethod _).expects(1).onCall { (arg: Int) => EventLogger.logEvent("mock method called") "one" }