Skip to content

Scala 2.13 support #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ lazy val commonSettings =
source.close
version.get
},
crossScalaVersions := Seq("2.11.12", "2.12.6"),
crossScalaVersions := Seq("2.11.12", "2.12.8", "2.13.0-M2"),
scalacOptions ++= Seq(
"-unchecked",
"-feature",
Expand All @@ -31,7 +31,7 @@ lazy val commonSettings =
)

lazy val commonLibraries = Seq(
"org.mockito" % "mockito-core" % "2.21.0",
"org.mockito" % "mockito-core" % "2.24.0",
"org.scalactic" %% "scalactic" % "3.0.5",
"ru.vyarus" % "generics-resolver" % "3.0.0",
"org.scalatest" %% "scalatest" % "3.0.5" % "provided",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright © 2017 Morgan Stanley. All rights reserved.
*
* THIS SOFTWARE IS SUBJECT TO THE TERMS OF THE MIT LICENSE.
* 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.
*
* IN ADDITION, THE FOLLOWING DISCLAIMER APPLIES IN CONNECTION WITH THIS SOFTWARE:
* THIS SOFTWARE IS LICENSED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY WARRANTY OF NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE MAY BE REDISTRIBUTED TO OTHERS ONLY BY EFFECTIVELY USING THIS OR ANOTHER EQUIVALENT DISCLAIMER IN ADDITION TO ANY OTHER REQUIRED LICENSE TERMS.
*/

package org.mockito

import org.mockito.matchers._

/**
* Trait that provides some syntax sugar and type mapping.
*
* It mostly forwards the calls to org.mockito.ArgumentMatchers, but with a few improvements to make it more scala-like
* It also renames the "eq" matcher to "eqTo" as in Scala "eq" is a keyword used to do object identity equality
*
* @author Bruno Bonanno
*
*/
trait ArgumentMatchersSugar
extends AnyMatchers
with EqMatchers
with EqMatchers_213
with ThatMatchers
with StringThatMatchers
with NullMatchers
with FunctionMatchers
with NumericMatchers
with MacroBasedMatchers

/**
* Simple object to allow the usage of the trait without mixing it in
*
* @author Bruno Bonanno
*
*/
object ArgumentMatchersSugar extends ArgumentMatchersSugar
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.mockito.matchers

import org.mockito.internal.ValueClassExtractor
import org.mockito.{ArgumentMatcher, ArgumentMatchers => JavaMatchers}
import org.scalactic.Equality

import scala.collection.mutable

trait EqMatchers_213 {

/**
* Creates a matcher that delegates on {{org.scalactic.Equality}} so you can always customise how the values are compared
* Also works with value classes
*/
def eqTo[T](value: T, others: T*)(implicit $eq: Equality[T], $vce: ValueClassExtractor[T]): T = {
val rawValues: Seq[T] = Seq(value) ++ others
JavaMatchers.argThat(new ArgumentMatcher[T] {
override def matches(v: T): Boolean = v match {
case a: mutable.WrappedArray[_] if rawValues.length == a.length =>
(rawValues zip a) forall {
case (expected, got) => $eq.areEqual(expected.asInstanceOf[T], got)
}
case other =>
$eq.areEqual($vce.extract(value).asInstanceOf[T], other)
}
override def toString: String = s"eqTo(${rawValues.mkString(", ")})"
})
value
}

/**
* It was intended to be used instead of eqTo when the argument is a value class,
* but eqTo now supports value classes so it is not needed anymore
*/
@deprecated("Use 'eqTo' instead", since = "1.0.2")
def eqToVal[T](value: T)(implicit $eq: Equality[T], $vce: ValueClassExtractor[T]): T = eqTo(value)
}
5 changes: 0 additions & 5 deletions core/src/main/scala/org/mockito/MockitoScalaSession.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ object MockitoScalaSession {
logger: MockitoSessionLogger = MockitoScalaLogger): MockitoScalaSession =
new MockitoScalaSession(name, strictness, logger)

object SyntheticLocation extends Location
object SyntheticMethodInvocation extends DescribedInvocation {
override def getLocation: Location = SyntheticLocation
}

trait Reporter {
def report(): Unit
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MockitoScalaSessionTest extends WordSpec with IdiomaticMockito with scalat
}

"check incorrect stubs" in {
an[PotentialStubbingProblem] should be thrownBy {
an[UnnecessaryStubbingException] should be thrownBy {
MockitoScalaSession().run {
val foo = mock[Foo]

Expand Down Expand Up @@ -120,7 +120,7 @@ class MockitoScalaSessionTest extends WordSpec with IdiomaticMockito with scalat
}

"check incorrect stubs with default arguments" in {
an[PotentialStubbingProblem] should be thrownBy {
an[UnnecessaryStubbingException] should be thrownBy {
MockitoScalaSession().run {
val foo = mock[Foo]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object ValueClassExtractor {

val r = if (isValueClass) {

if (ScalaVersion.startsWith("2.12"))
if (ScalaVersion.startsWith("2.12") || ScalaVersion.startsWith("2.13"))
c.Expr[ValueClassExtractor[VC]](q"new _root_.org.mockito.internal.ReflectionExtractor[$tpe]")
else if (ScalaVersion.startsWith("2.11"))
c.Expr[ValueClassExtractor[VC]] {
Expand Down
2 changes: 1 addition & 1 deletion version.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Version of the produced binaries. This file is intended to be checked-in.
#It will be automatically bumped by release automation.
version=1.0.11
version=1.1.0
previousVersion=1.0.10