- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个相当复杂的测试用例,我正在尝试将以下 verify() 添加到:
verify(userService).getUserById(anyLong()).setPasswordChangeRequired(eq(Boolean.TRUE));
失败并出现以下错误:
org.mockito.exceptions.verification.TooManyActualInvocations:
userService.getUserById(<any>);
Wanted 1 time:
-> at test.controllers.AuthenticationControllerMockTest.testLookupsExceeded(AuthenticationControllerMockTest.java:404)
But was 4 times. Undesired invocation:
所以我改成了这样:
verify(userService, atLeastOnce()).getUserById(anyLong()).setPasswordChangeRequired(eq(Boolean.TRUE));
现在它失败了:
java.lang.NullPointerException
at test.controllers.AuthenticationControllerMockTest.testLookupsExceeded(AuthenticationControllerMockTest.java:404)
因为这是返回 null:
verify(userService, atLeastOnce()).getUserById(anyLong())
这似乎令人费解 - 如果我使用默认值(仅一次调用),它会失败,因为它被多次调用,但如果我告诉它多次调用没问题,它会失败,因为它找不到任何调用!
有人可以帮忙吗?
最佳答案
看起来你们都想模拟调用 userService.getUserById()
时发生的情况,并且还要验证是否对返回的对象调用了 setPasswordChangeRequired(true)
.
您可以通过以下方式完成此操作:
UserService userService = mock(UserService.class);
User user = mock(User.class);
when(userService.getUserById(anyLong())).thenReturn(user);
...
// invoke the method being tested
...
verify(user).setPasswordChangeRequired(true);
关于java - Mockito verify() 失败,返回 "too many actual invocations",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12609976/
为什么Intellij会给出这个警告,这是什么意思,我怎样才能让它变得更好? import akka.actor.Props object Router { def props(config: C
我在两个类中使用react-native-image picker和react-native-image-crop picker库。 一个是启动库图像(react-native-image picke
晚上好, 我刚开始使用 Microsoft.Contracts(最新版本)并将其插入示例界面之上,现在它看起来像这样: namespace iRMA2.Core.Interfaces { us
我尝试制作用于 Symfony 2 上传的 ajax 脚本。Chrome 返回此错误: Uncaught TypeError: Illegal invocation jquery.min.js:4 我
我正在尝试在 java 中运行一些 javascript。我不确定脚本是否正确,我想在一段时间后终止调用。这就是我运行脚本的方式。 returnMethod = invocableEngine.inv
我正在为一个服务类编写 Spock 测试,该服务类的方法在 spring boot 应用程序中调用 Dao 类中的另一个方法。但是,我得到: Too few invocations for: 1
我们正在运行一个 Create React App (CRA) Web 应用程序,我们已向其中添加了 Google Analytics v4。我们使用 ga-4-react 启动分析npm 包。 in
我想将多个图像对象发布到 testphp.php。但控制台打印错误说非法调用。 我已经尝试过: submit $("#sub").click(function(){ // get th
当文本框为空时尝试禁用按钮时,我在 google chrome 控制台中收到此错误: function isEmpty() { var r = document.getElementById;
这是 html 这是脚本 $('#submit').click(function() { var files = $("[type='file']")[0].fil
我尝试通过ajax提交表单,下面是表单。 Date Upload File
我想弄乱 Speech Recognition API,所以我从简单的页面开始,该页面在单击 body 元素时开始识别。我的 scripts.js 文件是: var recognition = new
我在 Google 上进行了搜索,也浏览了 Stack 上提供的一系列类似问题,但不幸的是没有一个能帮助我解决问题。 下面是我正在做的事情,我从主视图调用 PartialView,但我的 Partia
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
为简单起见,我们来看一个非常简单的类: public class TestingClass { public void method1(){ System.out.printl
编辑:到目前为止建议的答案都不起作用。 我正在使用 django 运行此调用。第一次运行时,服务器返回“n_usr”(这会更改用户文件的形式)。第二次,它只是抛出一个非法调用错误。 function
每当我必须使用 gcloud 部署新的 python 函数时sdk 我收到这条消息 Allow unauthenticated invocations of new function [functio
这个问题已经有答案了: getUserMedia() in JavaScript normalizes across browsers. Illegal Invocation (1 个回答) 已关闭
我试图通过发布一些 xml 来登录来测试登录 Web 服务,但它再次出现此错误: 未捕获的类型错误:非法调用 这是代码: $(document).ready(function() { var da
function submit() { console.log('Submit!'); } function foo(callback, param) { console.log(ca
我是一名优秀的程序员,十分优秀!