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(ke开发者_C百科y: 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?
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/)
精彩评论