If I have a Scala trait with two functions defined on it, one defined using just the signature def foo : Int => String
and the other function declared with a paramter and a return type def bar(myInt : Int): String
then I get different behavior for those methods.
import org.scalamock.scalatest.MockFactory
import org.scalatest.{Matchers, WordSpec}
class DefTest {
trait DefTrait {
def foo : Int => String
def bar(myInt: Int) : String
}
class DefTest extends WordSpec with Matchers with MockFactory {
val defStub = stub[DefTrait]
defStub.bar _ when * returns "Works"
defStub.foo _ when * return "nope"
}
}
IntellJ says there are Too many arguments for method when
and expected: FunctionAdapter0[Boolean], actual: MatchAny
.
SBT says:
type mismatch;
[error] found : org.scalamock.matchers.MatchAny
[error] required: org.scalamock.function.FunctionAdapter0[Boolean]
[error] defStub.foo _ when * returns "nope"
[error] ^
This makes me wonder:
- What is the difference between these two types of function declarations? I thought they were equivalent and I seem to have been able to use them interchangeably up until now.
- Is it possible to use the signature function definition
foo: Int => String
with thedefStub.foo _ when 42 return "yay"
syntax?