Skip to content
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

How to handle default arguments #17

Open
jetjager opened this issue Dec 13, 2023 · 0 comments
Open

How to handle default arguments #17

jetjager opened this issue Dec 13, 2023 · 0 comments

Comments

@jetjager
Copy link

Hi, I struggle with finding a method for mocking, when the method has default arguments.
The following fails with java.lang.AssertionError: Unexpected method call Foo.bar$default$2()

//> using dep "org.scalatest::scalatest:3.2.17"
//> using dep "org.scalatestplus::easymock-5-1:3.2.17.0"
//> using dep "org.easymock:easymock:5.1.0"
import org.scalatestplus.easymock.EasyMockSugar
import org.scalatest.funsuite.AnyFunSuite
import org.easymock.EasyMock.{capture, newCapture}

trait Foo {
  def bar(a: String, b: Int = 0): String
}

class EasyMockTest extends AnyFunSuite with EasyMockSugar {

  test("test") {
    val foo = mock[Foo]

    val aCapture = newCapture[String]
    val bCapture = newCapture[Int]
    expecting {
      foo.bar(capture(aCapture), capture(bCapture)).andStubReturn("bar")
    }

    whenExecuting(foo) {
      val bar1 = foo.bar("a", 0)
      assert(bar1 == "bar")

      val bar2 = foo.bar("a")
      assert(bar2 == "bar")

    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant