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/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 b01692df..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) 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..1d11552b 100644 --- a/shared/src/main/scala/org/scalamock/proxy/FakeFunction.scala +++ b/shared/src/main/scala/org/scalamock/proxy/FakeFunction.scala @@ -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/test/scala/com/paulbutcher/test/features/ReturnTest.scala b/shared/src/test/scala/com/paulbutcher/test/features/ReturnTest.scala index 229363e1..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 bd329c2d..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,7 +66,7 @@ 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(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" @@ -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/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/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" }