Skip to content

Commit

Permalink
remove 2.12; move scala-2 tests to scala-2 directory
Browse files Browse the repository at this point in the history
  • Loading branch information
goshacodes committed Sep 12, 2023
1 parent 9d86cc4 commit 4e86d80
Show file tree
Hide file tree
Showing 59 changed files with 65 additions and 9 deletions.
12 changes: 10 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

Expand Down Expand Up @@ -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, _)) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions shared/src/main/scala-3/org/scalamock/clazz/Mock.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]]})}
Expand Down
46 changes: 46 additions & 0 deletions shared/src/main/scala-3/org/scalamock/proxy/ProxyMockFactory.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit 4e86d80

Please sign in to comment.