Daryl Odnert
Daryl Odnert

Reputation: 532

ScalaMock: Is it possible to mock a trait with an overloaded method expecting a curried function parameter?

My application is using Scala 2.13 and ScalaMock 5.1. Is it possible to mock the bar method in a trait like this one?

trait Foo {
  def bar(f: Double): Double
  def bar(i: Int)(f: => Double): Double
}

The following attempt does not compile. The error from the compiler is: _ must follow method; cannot follow Double

val mockFoo = mock[Foo]
(mockFoo.bar(_: Int)(_: Double) _).expects(1, 1.0).returns(2.0)

This attempt also does not compile. The error from the compiler is: type mismatch; found: () => Double, required: Double

val mockFoo = mock[Foo]
(mockFoo.bar(_: Int)(_: () => Double) _).expects(1, 1.0).returns(2.0)

This attempt does not compile. It returns the same error as the previous attempt.

val mockFoo = mock[Foo]
(mockFoo.bar(_: Int)(_: () => Double)).expects(1, 1.0).returns(2.0)

And this attempt also fails to compile. This time, the error is Unable to resolve overloaded method bar

val mockFoo = mock[Foo]
(mockFoo.bar(_: Int)(_: Double)).expects(1, 1.0).returns(2.0)

Upvotes: 2

Views: 206

Answers (0)

Related Questions