Ralph
Ralph

Reputation: 32284

Scala (Easy)Mocking default method parameters

I have the following trait (that will be implemented by a java.util.prefs.Preferences wrapper):

trait PreferencesMethods {
  def get(key: String, default: String = ""): String
  def getInt(key: String, default: Int = 0): Int
  def put(key: String, value: String)
  def putInt(key: String, value: Int)
}

I created an EasyMock of it like this:

val preferencesMock = EasyMock.createMock(classOf[PreferencesMethods])

I am calling it like this in my test case:

EasyMock.expect(preferencesMock.getInt("key")).andReturn(0)

and like this in the class-under-test:

preferences.getInt("key")

but EasyMock complains that I have an unexpected call to "getInt$default$2": "java.lang.AssertionError: Unexpected method call getInt$default$2()"

How do I mock the default parameter?

Upvotes: 2

Views: 779

Answers (1)

Nilanjan
Nilanjan

Reputation: 741

I think you would be better off doing partial mock with easymock or look for more native scala solution like Borachio (http://www.paulbutcher.com/2011/02/announcing-borachio-native-scala-mocking/)

Upvotes: 2

Related Questions