有没有办法匹配 Specs 中 Mockito 模拟对象的按名称调用参数? [英] Is there a way to match on a call-by-name argument of a Mockito mock object in Specs?

查看:41
本文介绍了有没有办法匹配 Specs 中 Mockito 模拟对象的按名称调用参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一些具有按名称调用参数的方法测试一个对象和另一个对象之间的交互.但是,我无法弄清楚如何为该按名称调用参数创建参数匹配器.

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): 任何

然后我真正想做的是测试是否使用已知的第二个参数调用该方法.我什至不太关心第一个参数,但是有一种方法来正确测试它也会是一个奖励.

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.

这不起作用:

<代码>有一个(模拟) fn(any[()=>String], eq(12))

也不是这个:

<代码>有一个(模拟) fn(any[Function0[String]], eq(12))

这甚至不能编译:

<代码>有一个(模拟) fn(any[=>String], eq(12))...这显然是可以预料的.

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

推荐答案

我刚刚在 specs2 中为 按名称参数和函数/部分函数参数.请尝试最新的规范 2-1.9-SNAPSHOT 并在 GitHub 上创建问题,如果这对您不起作用.

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.

这篇关于有没有办法匹配 Specs 中 Mockito 模拟对象的按名称调用参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆