模仿抛出InvalidUseOfMatchersException [英] mockito throwing InvalidUseOfMatchersException

查看:86
本文介绍了模仿抛出InvalidUseOfMatchersException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的getUserDetails类将User(客户类)和字符串作为参数并返回User.如果我按如下方式使用Mockito匹配器:

My getUserDetails class take User(custome class) and string as arguments and return User. If I use Mockito matcher as below:

when(authService.getUserDetails(any(User.class),anyString())).thenReturn(any(User.class));

它给了我InvalidUseOfMatchersException预期有2个匹配器,找到3个.我不能使用上面的表达式吗?

It gives me InvalidUseOfMatchersException 2 matchers expected, 3 found. Can't I use the above expression?

推荐答案

匹配器不用于返回.

.thenReturn(any(User.class));

您必须在此处退还有形物品.匹配器仅用于匹配输入,以便您可以指定提供某些输入时返回的内容.您仍然需要真实的输出才能返回.

You have to return something tangible here. Matchers are just for matching up input so that you can dictate what is returned when certain input is provided. You still need to have a real output to return.

这篇关于模仿抛出InvalidUseOfMatchersException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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