Is there a way to match on a call-by-name argument of a Mockito mock object in Specs?

心已入冬 提交于 2020-01-01 09:37:11

问题


I am testing the interaction between one object, and another object with some methods that have call-by-name arguments. However, I can't figure out how to create an argument matcher for that call-by-name argument.

Let's say that this is the signature of the mocked object:

def fn(arg1: => String, arg2: Int): Any

Then what I really want to do is test if that method is called with a known second argument. I don't even care all that much about the first argument, but having a way to properly test that as well would be a bonus.

This doesn't work:

there was one(mock) fn(any[()=>String], eq(12))

nor this:

there was one(mock) fn(any[Function0[String]], eq(12))

and this doesn't even compile:

there was one(mock) fn(any[=>String], eq(12)) ... which obviously is to be expected.


回答1:


I've just added some support in specs2 for byname arguments and functions/partial function arguments. Please try out the latest specs2-1.9-SNAPSHOT and create an issue on GitHub if that doesn't work for you.



来源:https://stackoverflow.com/questions/9512234/is-there-a-way-to-match-on-a-call-by-name-argument-of-a-mockito-mock-object-in-s

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!