From 4e86d80d01bfd1180f9dfc893f0ffb233d73a3ae Mon Sep 17 00:00:00 2001 From: Gosha Kovalyov Date: Mon, 11 Sep 2023 20:00:34 +0600 Subject: [PATCH] remove 2.12; move scala-2 tests to scala-2 directory --- build.sbt | 12 ++++- .../com/example/ControllerTest.scala | 0 .../example/HigherOrderFunctionsTest.scala | 0 .../com/example/OrderSpecification.scala | 0 .../com/example/OrderTest.scala | 0 .../com/example/ReallySimpleExampleTest.scala | 2 +- .../example/mockitostyle/ControllerTest.scala | 0 .../HigherOrderFunctionsTest.scala | 0 .../com/example/mockitostyle/OrderTest.scala | 0 .../org/scalamock/jstests/JSNativeTest.scala | 0 .../jstests/matchers/ArgThatTest.scala | 0 .../matchers/ArgThatTest.scala | 0 .../matchers/MatchAnyTest.scala | 0 .../mock/JavaMockNamingTest.scala | 0 .../mock/JavaMocksTest.scala | 0 .../mock/MockTestJvm.scala | 0 .../proxy/ProxyMockManyParamsTest.scala | 0 .../proxy/ProxyMockTest.scala | 0 .../AsyncMockFactoryNoDuplicatedRun.scala | 0 .../test/scalatest/ConcurrencyTest.scala | 0 .../test/scalatest/MixedMockFactoryTest.scala | 0 .../scalatest/SuiteScopeProxyMockTest.scala | 0 .../test/specs2/ConcurrencyTest.scala | 0 .../specs2/SuiteScopeMockParallelTest.scala | 0 .../SuiteScopePresetMockParallelTest.scala | 0 .../scalamock/proxy/ProxyMockFactory.scala | 2 +- .../scala-3/org/scalamock/clazz/Mock.scala | 12 +++-- .../scalamock/proxy/ProxyMockFactory.scala | 46 +++++++++++++++++++ .../com/paulbutcher/test/IsolatedSpec.scala | 0 .../test/features/CallCountTest.scala | 0 .../test/features/OrderingTest.scala | 0 .../test/features/ReturnTest.scala | 0 .../paulbutcher/test/features/ThrowTest.scala | 0 .../test/matchers/ArgCaptureTest.scala | 0 .../test/matchers/MatchersTest.scala | 0 .../test/matchers/MockParameterTest.scala | 0 .../mock/MethodsWithDefaultParamsTest.scala | 0 .../test/mock/MockFunctionNamingTest.scala | 0 .../test/mock/MockFunctionTest.scala | 0 .../test/mock/MockNamingTest.scala | 0 .../com/paulbutcher/test/mock/MockTest.scala | 0 .../test/mock/MockTestManyParams.scala | 0 .../test/mock/OverloadedMethodsTest.scala | 0 .../test/stub/StubFunctionNamingTest.scala | 0 .../test/stub/StubFunctionTest.scala | 0 .../test/stub/StubNamingTest.scala | 0 .../com/paulbutcher/test/stub/StubTest.scala | 0 .../test/scalatest/AsyncSyncMixinTest.scala | 0 .../test/scalatest/BasicAsyncTest.scala | 0 .../scalamock/test/scalatest/BasicTest.scala | 0 .../test/scalatest/ErrorReportingTest.scala | 0 .../test/scalatest/FixtureContextTest.scala | 0 .../test/scalatest/PathSpecTest.scala | 0 .../test/scalatest/StackableSuitesTest.scala | 0 .../SuiteScopeMockParallelTest.scala | 0 .../SuiteScopePresetMockParallelTest.scala | 0 .../org/scalamock/test/specs2/BasicTest.scala | 0 .../test/specs2/FixtureContextTest.scala | 0 .../YetAnotherClass.scala | 0 59 files changed, 65 insertions(+), 9 deletions(-) rename examples/src/test/{scala => scala-2}/com/example/ControllerTest.scala (100%) rename examples/src/test/{scala => scala-2}/com/example/HigherOrderFunctionsTest.scala (100%) rename examples/src/test/{scala => scala-2}/com/example/OrderSpecification.scala (100%) rename examples/src/test/{scala => scala-2}/com/example/OrderTest.scala (100%) rename examples/src/test/{scala => scala-2}/com/example/ReallySimpleExampleTest.scala (97%) rename examples/src/test/{scala => scala-2}/com/example/mockitostyle/ControllerTest.scala (100%) rename examples/src/test/{scala => scala-2}/com/example/mockitostyle/HigherOrderFunctionsTest.scala (100%) rename examples/src/test/{scala => scala-2}/com/example/mockitostyle/OrderTest.scala (100%) rename js/src/test/{scala => scala-2}/org/scalamock/jstests/JSNativeTest.scala (100%) rename js/src/test/{scala => scala-2}/org/scalamock/jstests/matchers/ArgThatTest.scala (100%) rename jvm/src/test/{scala => scala-2}/com.paulbutcher.test/matchers/ArgThatTest.scala (100%) rename jvm/src/test/{scala => scala-2}/com.paulbutcher.test/matchers/MatchAnyTest.scala (100%) rename jvm/src/test/{scala => scala-2}/com.paulbutcher.test/mock/JavaMockNamingTest.scala (100%) rename jvm/src/test/{scala => scala-2}/com.paulbutcher.test/mock/JavaMocksTest.scala (100%) rename jvm/src/test/{scala => scala-2}/com.paulbutcher.test/mock/MockTestJvm.scala (100%) rename jvm/src/test/{scala => scala-2}/com.paulbutcher.test/proxy/ProxyMockManyParamsTest.scala (100%) rename jvm/src/test/{scala => scala-2}/com.paulbutcher.test/proxy/ProxyMockTest.scala (100%) rename jvm/src/test/{scala => scala-2}/org/scalamock/test/scalatest/AsyncMockFactoryNoDuplicatedRun.scala (100%) rename jvm/src/test/{scala => scala-2}/org/scalamock/test/scalatest/ConcurrencyTest.scala (100%) rename jvm/src/test/{scala => scala-2}/org/scalamock/test/scalatest/MixedMockFactoryTest.scala (100%) rename jvm/src/test/{scala => scala-2}/org/scalamock/test/scalatest/SuiteScopeProxyMockTest.scala (100%) rename jvm/src/test/{scala => scala-2}/org/scalamock/test/specs2/ConcurrencyTest.scala (100%) rename jvm/src/test/{scala => scala-2}/org/scalamock/test/specs2/SuiteScopeMockParallelTest.scala (100%) rename jvm/src/test/{scala => scala-2}/org/scalamock/test/specs2/SuiteScopePresetMockParallelTest.scala (100%) rename shared/src/main/{scala => scala-2}/org/scalamock/proxy/ProxyMockFactory.scala (97%) create mode 100644 shared/src/main/scala-3/org/scalamock/proxy/ProxyMockFactory.scala rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/IsolatedSpec.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/features/CallCountTest.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/features/OrderingTest.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/features/ReturnTest.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/features/ThrowTest.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/matchers/ArgCaptureTest.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/matchers/MatchersTest.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/matchers/MockParameterTest.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/mock/MethodsWithDefaultParamsTest.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/mock/MockFunctionNamingTest.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/mock/MockFunctionTest.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/mock/MockNamingTest.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/mock/MockTest.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/mock/MockTestManyParams.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/mock/OverloadedMethodsTest.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/stub/StubFunctionNamingTest.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/stub/StubFunctionTest.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/stub/StubNamingTest.scala (100%) rename shared/src/test/{scala => scala-2}/com/paulbutcher/test/stub/StubTest.scala (100%) rename shared/src/test/{scala => scala-2}/org/scalamock/test/scalatest/AsyncSyncMixinTest.scala (100%) rename shared/src/test/{scala => scala-2}/org/scalamock/test/scalatest/BasicAsyncTest.scala (100%) rename shared/src/test/{scala => scala-2}/org/scalamock/test/scalatest/BasicTest.scala (100%) rename shared/src/test/{scala => scala-2}/org/scalamock/test/scalatest/ErrorReportingTest.scala (100%) rename shared/src/test/{scala => scala-2}/org/scalamock/test/scalatest/FixtureContextTest.scala (100%) rename shared/src/test/{scala => scala-2}/org/scalamock/test/scalatest/PathSpecTest.scala (100%) rename shared/src/test/{scala => scala-2}/org/scalamock/test/scalatest/StackableSuitesTest.scala (100%) rename shared/src/test/{scala => scala-2}/org/scalamock/test/scalatest/SuiteScopeMockParallelTest.scala (100%) rename shared/src/test/{scala => scala-2}/org/scalamock/test/scalatest/SuiteScopePresetMockParallelTest.scala (100%) rename shared/src/test/{scala => scala-2}/org/scalamock/test/specs2/BasicTest.scala (100%) rename shared/src/test/{scala => scala-2}/org/scalamock/test/specs2/FixtureContextTest.scala (100%) rename shared/src/test/scala/{yet/another/pkg => yet.another.pkg}/YetAnotherClass.scala (100%) diff --git a/build.sbt b/build.sbt index 13b4415b..9e08a3cc 100644 --- a/build.sbt +++ b/build.sbt @@ -6,7 +6,7 @@ lazy val scalatest = Def.setting("org.scalatest" %%% "scalatest" % "3.2.16") lazy val specs2 = Def.setting("org.specs2" %%% "specs2-core" % "4.20.2") val commonSettings = Defaults.coreDefaultSettings ++ Seq( - scalaVersion := "3.3.0", + scalaVersion := "3.3.1", scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-release:8") ) @@ -48,9 +48,17 @@ def crossScalaSettings = { } } Seq( - crossScalaVersions := Seq("2.12.17", "2.13.11", scalaVersion.value), + crossScalaVersions := Seq("2.13.11", scalaVersion.value), Compile / unmanagedSourceDirectories ++= addDirsByScalaVersion("src/main").value, Test / unmanagedSourceDirectories ++= addDirsByScalaVersion("src/test").value, + scalacOptions ++= { + CrossVersion.partialVersion(scalaVersion.value) match { + case Some((2, 13)) => + Seq("-Ytasty-reader") + case _ => + Seq.empty + } + }, libraryDependencies ++= { CrossVersion.partialVersion(scalaVersion.value) match { case Some((2, _)) => diff --git a/examples/src/test/scala/com/example/ControllerTest.scala b/examples/src/test/scala-2/com/example/ControllerTest.scala similarity index 100% rename from examples/src/test/scala/com/example/ControllerTest.scala rename to examples/src/test/scala-2/com/example/ControllerTest.scala diff --git a/examples/src/test/scala/com/example/HigherOrderFunctionsTest.scala b/examples/src/test/scala-2/com/example/HigherOrderFunctionsTest.scala similarity index 100% rename from examples/src/test/scala/com/example/HigherOrderFunctionsTest.scala rename to examples/src/test/scala-2/com/example/HigherOrderFunctionsTest.scala diff --git a/examples/src/test/scala/com/example/OrderSpecification.scala b/examples/src/test/scala-2/com/example/OrderSpecification.scala similarity index 100% rename from examples/src/test/scala/com/example/OrderSpecification.scala rename to examples/src/test/scala-2/com/example/OrderSpecification.scala diff --git a/examples/src/test/scala/com/example/OrderTest.scala b/examples/src/test/scala-2/com/example/OrderTest.scala similarity index 100% rename from examples/src/test/scala/com/example/OrderTest.scala rename to examples/src/test/scala-2/com/example/OrderTest.scala diff --git a/examples/src/test/scala/com/example/ReallySimpleExampleTest.scala b/examples/src/test/scala-2/com/example/ReallySimpleExampleTest.scala similarity index 97% rename from examples/src/test/scala/com/example/ReallySimpleExampleTest.scala rename to examples/src/test/scala-2/com/example/ReallySimpleExampleTest.scala index e1cd91f9..6063bfab 100644 --- a/examples/src/test/scala/com/example/ReallySimpleExampleTest.scala +++ b/examples/src/test/scala-2/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) diff --git a/examples/src/test/scala/com/example/mockitostyle/ControllerTest.scala b/examples/src/test/scala-2/com/example/mockitostyle/ControllerTest.scala similarity index 100% rename from examples/src/test/scala/com/example/mockitostyle/ControllerTest.scala rename to examples/src/test/scala-2/com/example/mockitostyle/ControllerTest.scala diff --git a/examples/src/test/scala/com/example/mockitostyle/HigherOrderFunctionsTest.scala b/examples/src/test/scala-2/com/example/mockitostyle/HigherOrderFunctionsTest.scala similarity index 100% rename from examples/src/test/scala/com/example/mockitostyle/HigherOrderFunctionsTest.scala rename to examples/src/test/scala-2/com/example/mockitostyle/HigherOrderFunctionsTest.scala diff --git a/examples/src/test/scala/com/example/mockitostyle/OrderTest.scala b/examples/src/test/scala-2/com/example/mockitostyle/OrderTest.scala similarity index 100% rename from examples/src/test/scala/com/example/mockitostyle/OrderTest.scala rename to examples/src/test/scala-2/com/example/mockitostyle/OrderTest.scala diff --git a/js/src/test/scala/org/scalamock/jstests/JSNativeTest.scala b/js/src/test/scala-2/org/scalamock/jstests/JSNativeTest.scala similarity index 100% rename from js/src/test/scala/org/scalamock/jstests/JSNativeTest.scala rename to js/src/test/scala-2/org/scalamock/jstests/JSNativeTest.scala diff --git a/js/src/test/scala/org/scalamock/jstests/matchers/ArgThatTest.scala b/js/src/test/scala-2/org/scalamock/jstests/matchers/ArgThatTest.scala similarity index 100% rename from js/src/test/scala/org/scalamock/jstests/matchers/ArgThatTest.scala rename to js/src/test/scala-2/org/scalamock/jstests/matchers/ArgThatTest.scala diff --git a/jvm/src/test/scala/com.paulbutcher.test/matchers/ArgThatTest.scala b/jvm/src/test/scala-2/com.paulbutcher.test/matchers/ArgThatTest.scala similarity index 100% rename from jvm/src/test/scala/com.paulbutcher.test/matchers/ArgThatTest.scala rename to jvm/src/test/scala-2/com.paulbutcher.test/matchers/ArgThatTest.scala diff --git a/jvm/src/test/scala/com.paulbutcher.test/matchers/MatchAnyTest.scala b/jvm/src/test/scala-2/com.paulbutcher.test/matchers/MatchAnyTest.scala similarity index 100% rename from jvm/src/test/scala/com.paulbutcher.test/matchers/MatchAnyTest.scala rename to jvm/src/test/scala-2/com.paulbutcher.test/matchers/MatchAnyTest.scala diff --git a/jvm/src/test/scala/com.paulbutcher.test/mock/JavaMockNamingTest.scala b/jvm/src/test/scala-2/com.paulbutcher.test/mock/JavaMockNamingTest.scala similarity index 100% rename from jvm/src/test/scala/com.paulbutcher.test/mock/JavaMockNamingTest.scala rename to jvm/src/test/scala-2/com.paulbutcher.test/mock/JavaMockNamingTest.scala diff --git a/jvm/src/test/scala/com.paulbutcher.test/mock/JavaMocksTest.scala b/jvm/src/test/scala-2/com.paulbutcher.test/mock/JavaMocksTest.scala similarity index 100% rename from jvm/src/test/scala/com.paulbutcher.test/mock/JavaMocksTest.scala rename to jvm/src/test/scala-2/com.paulbutcher.test/mock/JavaMocksTest.scala diff --git a/jvm/src/test/scala/com.paulbutcher.test/mock/MockTestJvm.scala b/jvm/src/test/scala-2/com.paulbutcher.test/mock/MockTestJvm.scala similarity index 100% rename from jvm/src/test/scala/com.paulbutcher.test/mock/MockTestJvm.scala rename to jvm/src/test/scala-2/com.paulbutcher.test/mock/MockTestJvm.scala diff --git a/jvm/src/test/scala/com.paulbutcher.test/proxy/ProxyMockManyParamsTest.scala b/jvm/src/test/scala-2/com.paulbutcher.test/proxy/ProxyMockManyParamsTest.scala similarity index 100% rename from jvm/src/test/scala/com.paulbutcher.test/proxy/ProxyMockManyParamsTest.scala rename to jvm/src/test/scala-2/com.paulbutcher.test/proxy/ProxyMockManyParamsTest.scala diff --git a/jvm/src/test/scala/com.paulbutcher.test/proxy/ProxyMockTest.scala b/jvm/src/test/scala-2/com.paulbutcher.test/proxy/ProxyMockTest.scala similarity index 100% rename from jvm/src/test/scala/com.paulbutcher.test/proxy/ProxyMockTest.scala rename to jvm/src/test/scala-2/com.paulbutcher.test/proxy/ProxyMockTest.scala diff --git a/jvm/src/test/scala/org/scalamock/test/scalatest/AsyncMockFactoryNoDuplicatedRun.scala b/jvm/src/test/scala-2/org/scalamock/test/scalatest/AsyncMockFactoryNoDuplicatedRun.scala similarity index 100% rename from jvm/src/test/scala/org/scalamock/test/scalatest/AsyncMockFactoryNoDuplicatedRun.scala rename to jvm/src/test/scala-2/org/scalamock/test/scalatest/AsyncMockFactoryNoDuplicatedRun.scala diff --git a/jvm/src/test/scala/org/scalamock/test/scalatest/ConcurrencyTest.scala b/jvm/src/test/scala-2/org/scalamock/test/scalatest/ConcurrencyTest.scala similarity index 100% rename from jvm/src/test/scala/org/scalamock/test/scalatest/ConcurrencyTest.scala rename to jvm/src/test/scala-2/org/scalamock/test/scalatest/ConcurrencyTest.scala diff --git a/jvm/src/test/scala/org/scalamock/test/scalatest/MixedMockFactoryTest.scala b/jvm/src/test/scala-2/org/scalamock/test/scalatest/MixedMockFactoryTest.scala similarity index 100% rename from jvm/src/test/scala/org/scalamock/test/scalatest/MixedMockFactoryTest.scala rename to jvm/src/test/scala-2/org/scalamock/test/scalatest/MixedMockFactoryTest.scala diff --git a/jvm/src/test/scala/org/scalamock/test/scalatest/SuiteScopeProxyMockTest.scala b/jvm/src/test/scala-2/org/scalamock/test/scalatest/SuiteScopeProxyMockTest.scala similarity index 100% rename from jvm/src/test/scala/org/scalamock/test/scalatest/SuiteScopeProxyMockTest.scala rename to jvm/src/test/scala-2/org/scalamock/test/scalatest/SuiteScopeProxyMockTest.scala diff --git a/jvm/src/test/scala/org/scalamock/test/specs2/ConcurrencyTest.scala b/jvm/src/test/scala-2/org/scalamock/test/specs2/ConcurrencyTest.scala similarity index 100% rename from jvm/src/test/scala/org/scalamock/test/specs2/ConcurrencyTest.scala rename to jvm/src/test/scala-2/org/scalamock/test/specs2/ConcurrencyTest.scala diff --git a/jvm/src/test/scala/org/scalamock/test/specs2/SuiteScopeMockParallelTest.scala b/jvm/src/test/scala-2/org/scalamock/test/specs2/SuiteScopeMockParallelTest.scala similarity index 100% rename from jvm/src/test/scala/org/scalamock/test/specs2/SuiteScopeMockParallelTest.scala rename to jvm/src/test/scala-2/org/scalamock/test/specs2/SuiteScopeMockParallelTest.scala diff --git a/jvm/src/test/scala/org/scalamock/test/specs2/SuiteScopePresetMockParallelTest.scala b/jvm/src/test/scala-2/org/scalamock/test/specs2/SuiteScopePresetMockParallelTest.scala similarity index 100% rename from jvm/src/test/scala/org/scalamock/test/specs2/SuiteScopePresetMockParallelTest.scala rename to jvm/src/test/scala-2/org/scalamock/test/specs2/SuiteScopePresetMockParallelTest.scala 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 97% rename from shared/src/main/scala/org/scalamock/proxy/ProxyMockFactory.scala rename to shared/src/main/scala-2/org/scalamock/proxy/ProxyMockFactory.scala index bb782b4b..1a1538b6 100644 --- a/shared/src/main/scala/org/scalamock/proxy/ProxyMockFactory.scala +++ b/shared/src/main/scala-2/org/scalamock/proxy/ProxyMockFactory.scala @@ -37,7 +37,7 @@ trait ProxyMockFactory { val classLoader = Thread.currentThread.getContextClassLoader val interfaces = Array[Class[_]](classTag[T].runtimeClass, classTag[F].runtimeClass) try { - JavaProxy.newProxyInstance(classLoader, interfaces, handler).asInstanceOf[T with F with scala.reflect.Selectable] + JavaProxy.newProxyInstance(classLoader, interfaces, handler).asInstanceOf[T with F] } catch { case e: IllegalArgumentException => throw new IllegalArgumentException("Unable to create proxy - possible classloader issue?", e) diff --git a/shared/src/main/scala-3/org/scalamock/clazz/Mock.scala b/shared/src/main/scala-3/org/scalamock/clazz/Mock.scala index ada92f8b..ac26f819 100644 --- a/shared/src/main/scala-3/org/scalamock/clazz/Mock.scala +++ b/shared/src/main/scala-3/org/scalamock/clazz/Mock.scala @@ -21,18 +21,20 @@ package org.scalamock.clazz import org.scalamock.context.MockContext -import org.scalamock.function._ +import org.scalamock.function.* import org.scalamock.util.Defaultable + +import scala.annotation.experimental import scala.reflect.Selectable trait Mock: import scala.language.implicitConversions - inline def mock[T](implicit mockContext: MockContext): T & Selectable = ${MockImpl.mock('{mockContext})} - inline def stub[T](implicit mockContext: MockContext): T & Selectable = ${MockImpl.stub('{mockContext})} + @experimental inline def mock[T](implicit mockContext: MockContext): T & Selectable = ${MockImpl.mock[T]('{mockContext})} + @experimental 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('{mockName})('{mockContext})} - inline def stub[T](mockName: String)(implicit mockContext: MockContext): T & Selectable = ${MockImpl.stubWithName('{mockName})('{mockContext})} + @experimental inline def mock[T](mockName: String)(implicit mockContext: MockContext) : T & Selectable = ${MockImpl.mockWithName[T]('{mockName})('{mockContext})} + @experimental inline def stub[T](mockName: String)(implicit mockContext: MockContext): T & Selectable = ${MockImpl.stubWithName[T]('{mockName})('{mockContext})} inline implicit def toMockFunction0[R: Defaultable](f: () => R): MockFunction0[R] = ${MockImpl.toMockFunction0[R]('{f})('{summon[Defaultable[R]]})} inline implicit def toMockFunction1[T1, R: Defaultable](f: T1 => R): MockFunction1[T1, R] = ${MockImpl.toMockFunction1[T1, R]('{f})('{summon[Defaultable[R]]})} 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..a9f4e903 --- /dev/null +++ b/shared/src/main/scala-3/org/scalamock/proxy/ProxyMockFactory.scala @@ -0,0 +1,46 @@ +// 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 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 with F with 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/test/scala/com/paulbutcher/test/IsolatedSpec.scala b/shared/src/test/scala-2/com/paulbutcher/test/IsolatedSpec.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/IsolatedSpec.scala rename to shared/src/test/scala-2/com/paulbutcher/test/IsolatedSpec.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/features/CallCountTest.scala b/shared/src/test/scala-2/com/paulbutcher/test/features/CallCountTest.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/features/CallCountTest.scala rename to shared/src/test/scala-2/com/paulbutcher/test/features/CallCountTest.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/features/OrderingTest.scala b/shared/src/test/scala-2/com/paulbutcher/test/features/OrderingTest.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/features/OrderingTest.scala rename to shared/src/test/scala-2/com/paulbutcher/test/features/OrderingTest.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/features/ReturnTest.scala b/shared/src/test/scala-2/com/paulbutcher/test/features/ReturnTest.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/features/ReturnTest.scala rename to shared/src/test/scala-2/com/paulbutcher/test/features/ReturnTest.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/features/ThrowTest.scala b/shared/src/test/scala-2/com/paulbutcher/test/features/ThrowTest.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/features/ThrowTest.scala rename to shared/src/test/scala-2/com/paulbutcher/test/features/ThrowTest.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/matchers/ArgCaptureTest.scala b/shared/src/test/scala-2/com/paulbutcher/test/matchers/ArgCaptureTest.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/matchers/ArgCaptureTest.scala rename to shared/src/test/scala-2/com/paulbutcher/test/matchers/ArgCaptureTest.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/matchers/MatchersTest.scala b/shared/src/test/scala-2/com/paulbutcher/test/matchers/MatchersTest.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/matchers/MatchersTest.scala rename to shared/src/test/scala-2/com/paulbutcher/test/matchers/MatchersTest.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/matchers/MockParameterTest.scala b/shared/src/test/scala-2/com/paulbutcher/test/matchers/MockParameterTest.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/matchers/MockParameterTest.scala rename to shared/src/test/scala-2/com/paulbutcher/test/matchers/MockParameterTest.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/mock/MethodsWithDefaultParamsTest.scala b/shared/src/test/scala-2/com/paulbutcher/test/mock/MethodsWithDefaultParamsTest.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/mock/MethodsWithDefaultParamsTest.scala rename to shared/src/test/scala-2/com/paulbutcher/test/mock/MethodsWithDefaultParamsTest.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/mock/MockFunctionNamingTest.scala b/shared/src/test/scala-2/com/paulbutcher/test/mock/MockFunctionNamingTest.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/mock/MockFunctionNamingTest.scala rename to shared/src/test/scala-2/com/paulbutcher/test/mock/MockFunctionNamingTest.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/mock/MockFunctionTest.scala b/shared/src/test/scala-2/com/paulbutcher/test/mock/MockFunctionTest.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/mock/MockFunctionTest.scala rename to shared/src/test/scala-2/com/paulbutcher/test/mock/MockFunctionTest.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/mock/MockNamingTest.scala b/shared/src/test/scala-2/com/paulbutcher/test/mock/MockNamingTest.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/mock/MockNamingTest.scala rename to shared/src/test/scala-2/com/paulbutcher/test/mock/MockNamingTest.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/mock/MockTest.scala b/shared/src/test/scala-2/com/paulbutcher/test/mock/MockTest.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/mock/MockTest.scala rename to shared/src/test/scala-2/com/paulbutcher/test/mock/MockTest.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/mock/MockTestManyParams.scala b/shared/src/test/scala-2/com/paulbutcher/test/mock/MockTestManyParams.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/mock/MockTestManyParams.scala rename to shared/src/test/scala-2/com/paulbutcher/test/mock/MockTestManyParams.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/mock/OverloadedMethodsTest.scala b/shared/src/test/scala-2/com/paulbutcher/test/mock/OverloadedMethodsTest.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/mock/OverloadedMethodsTest.scala rename to shared/src/test/scala-2/com/paulbutcher/test/mock/OverloadedMethodsTest.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/stub/StubFunctionNamingTest.scala b/shared/src/test/scala-2/com/paulbutcher/test/stub/StubFunctionNamingTest.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/stub/StubFunctionNamingTest.scala rename to shared/src/test/scala-2/com/paulbutcher/test/stub/StubFunctionNamingTest.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/stub/StubFunctionTest.scala b/shared/src/test/scala-2/com/paulbutcher/test/stub/StubFunctionTest.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/stub/StubFunctionTest.scala rename to shared/src/test/scala-2/com/paulbutcher/test/stub/StubFunctionTest.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/stub/StubNamingTest.scala b/shared/src/test/scala-2/com/paulbutcher/test/stub/StubNamingTest.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/stub/StubNamingTest.scala rename to shared/src/test/scala-2/com/paulbutcher/test/stub/StubNamingTest.scala diff --git a/shared/src/test/scala/com/paulbutcher/test/stub/StubTest.scala b/shared/src/test/scala-2/com/paulbutcher/test/stub/StubTest.scala similarity index 100% rename from shared/src/test/scala/com/paulbutcher/test/stub/StubTest.scala rename to shared/src/test/scala-2/com/paulbutcher/test/stub/StubTest.scala diff --git a/shared/src/test/scala/org/scalamock/test/scalatest/AsyncSyncMixinTest.scala b/shared/src/test/scala-2/org/scalamock/test/scalatest/AsyncSyncMixinTest.scala similarity index 100% rename from shared/src/test/scala/org/scalamock/test/scalatest/AsyncSyncMixinTest.scala rename to shared/src/test/scala-2/org/scalamock/test/scalatest/AsyncSyncMixinTest.scala diff --git a/shared/src/test/scala/org/scalamock/test/scalatest/BasicAsyncTest.scala b/shared/src/test/scala-2/org/scalamock/test/scalatest/BasicAsyncTest.scala similarity index 100% rename from shared/src/test/scala/org/scalamock/test/scalatest/BasicAsyncTest.scala rename to shared/src/test/scala-2/org/scalamock/test/scalatest/BasicAsyncTest.scala diff --git a/shared/src/test/scala/org/scalamock/test/scalatest/BasicTest.scala b/shared/src/test/scala-2/org/scalamock/test/scalatest/BasicTest.scala similarity index 100% rename from shared/src/test/scala/org/scalamock/test/scalatest/BasicTest.scala rename to shared/src/test/scala-2/org/scalamock/test/scalatest/BasicTest.scala diff --git a/shared/src/test/scala/org/scalamock/test/scalatest/ErrorReportingTest.scala b/shared/src/test/scala-2/org/scalamock/test/scalatest/ErrorReportingTest.scala similarity index 100% rename from shared/src/test/scala/org/scalamock/test/scalatest/ErrorReportingTest.scala rename to shared/src/test/scala-2/org/scalamock/test/scalatest/ErrorReportingTest.scala diff --git a/shared/src/test/scala/org/scalamock/test/scalatest/FixtureContextTest.scala b/shared/src/test/scala-2/org/scalamock/test/scalatest/FixtureContextTest.scala similarity index 100% rename from shared/src/test/scala/org/scalamock/test/scalatest/FixtureContextTest.scala rename to shared/src/test/scala-2/org/scalamock/test/scalatest/FixtureContextTest.scala diff --git a/shared/src/test/scala/org/scalamock/test/scalatest/PathSpecTest.scala b/shared/src/test/scala-2/org/scalamock/test/scalatest/PathSpecTest.scala similarity index 100% rename from shared/src/test/scala/org/scalamock/test/scalatest/PathSpecTest.scala rename to shared/src/test/scala-2/org/scalamock/test/scalatest/PathSpecTest.scala diff --git a/shared/src/test/scala/org/scalamock/test/scalatest/StackableSuitesTest.scala b/shared/src/test/scala-2/org/scalamock/test/scalatest/StackableSuitesTest.scala similarity index 100% rename from shared/src/test/scala/org/scalamock/test/scalatest/StackableSuitesTest.scala rename to shared/src/test/scala-2/org/scalamock/test/scalatest/StackableSuitesTest.scala diff --git a/shared/src/test/scala/org/scalamock/test/scalatest/SuiteScopeMockParallelTest.scala b/shared/src/test/scala-2/org/scalamock/test/scalatest/SuiteScopeMockParallelTest.scala similarity index 100% rename from shared/src/test/scala/org/scalamock/test/scalatest/SuiteScopeMockParallelTest.scala rename to shared/src/test/scala-2/org/scalamock/test/scalatest/SuiteScopeMockParallelTest.scala diff --git a/shared/src/test/scala/org/scalamock/test/scalatest/SuiteScopePresetMockParallelTest.scala b/shared/src/test/scala-2/org/scalamock/test/scalatest/SuiteScopePresetMockParallelTest.scala similarity index 100% rename from shared/src/test/scala/org/scalamock/test/scalatest/SuiteScopePresetMockParallelTest.scala rename to shared/src/test/scala-2/org/scalamock/test/scalatest/SuiteScopePresetMockParallelTest.scala diff --git a/shared/src/test/scala/org/scalamock/test/specs2/BasicTest.scala b/shared/src/test/scala-2/org/scalamock/test/specs2/BasicTest.scala similarity index 100% rename from shared/src/test/scala/org/scalamock/test/specs2/BasicTest.scala rename to shared/src/test/scala-2/org/scalamock/test/specs2/BasicTest.scala diff --git a/shared/src/test/scala/org/scalamock/test/specs2/FixtureContextTest.scala b/shared/src/test/scala-2/org/scalamock/test/specs2/FixtureContextTest.scala similarity index 100% rename from shared/src/test/scala/org/scalamock/test/specs2/FixtureContextTest.scala rename to shared/src/test/scala-2/org/scalamock/test/specs2/FixtureContextTest.scala diff --git a/shared/src/test/scala/yet/another/pkg/YetAnotherClass.scala b/shared/src/test/scala/yet.another.pkg/YetAnotherClass.scala similarity index 100% rename from shared/src/test/scala/yet/another/pkg/YetAnotherClass.scala rename to shared/src/test/scala/yet.another.pkg/YetAnotherClass.scala