当前位置:网站首页>Mockito no return value method and exception mock
Mockito no return value method and exception mock
2022-06-09 06:32:00 【ISaiSai】
- No return value method exception mock
doThrow(new RuntimeException()).when(testMethod).testMethod(anyString());
Assertions.assertThrows(Exception.class, () -> testMethod.testMethod("foo"));
- Normal with return value mock
given(testMethod.testMethodWithReturn(anyString())).willThrow(new Exception("TestError"));
perhaps
when(testMethod.testMethodWithReturn(anyString())).thenThrow(new Exception("TestError"));
- Throw an exception based on a specific input parameter (answer Method )
when(testMethod.testMethodWithReturn(anyString())).thenAnswer(
new Answer() {
public Object answer(InvocationOnMock invocation) throws Exception {
Object[] args = invocation.getArguments();
if (args[0].equals("foo")) {
throw new Exception("mock Abnormal response ");
}
return "ok";
}
});
边栏推荐
- “TypeError: ‘list‘ object is not callable”
- LDAP application: openldap integrated into jumpserver
- Postman installation
- 你真的懂熵了吗(含交叉熵)
- MySQL 5.7 installation tutorial (full step, nanny level tutorial)
- LDAP application: openldap integrated into open***
- SQLServer 导入导出数据,后台有进程,前台无显示。
- ImportError: cannot import name ‘joblib‘ from ‘sklearn. externals‘
- Analysis and Discussion on security level of 6-bit password lock
- Modularity in typescrtipt
猜你喜欢

Qt控制台工程显示Label小窗口

工业级AM335X核心模块选型

Coredns part 4-compiling and installing unbound

Coredns part 2- compiling and installing external plugins

Quanzhi v3s learning record (9) buildreoot file system construction

Banana pie bpi-m2 ultra miniaturized version -com-x40i core board

二叉树的递归套路

全志V3s学习记录--ESP8089的使用

Singh function sinc (x) and sampling function SA (T)

Transplant qt5.12 to t507 development board
随机推荐
zgc gc消息类型及触发时机
“TypeError: ‘list‘ object is not callable”
Chapter_05 使用Opencv相加(融合)两个图像
UML系列文章(23)高级行为---进程和线程
二叉 树
Comparison between ZGC and G1 and the meaning of color points
全国产工业级全志T3/A40i核心板-CoM-X40I,助力智能电力系统
工业级AM335X核心模块选型
Ping: xxx: unknown name or service reason analysis
Coredns part 3-access Prometheus monitoring
Chapter_03 矩阵的掩膜操作
Wechat applet page scrolls to the bottom
戒烟日志_03 (day_07)
Bladed software windfile calculation
matlab如何向mat文件写入带标题的连续数据
The BSP tailoring of the Quanzhi platform (1) kernel tailoring -- tailoring of debugging tools and debugging information
MySQL federated query
指数移动加权平均
MySQL 5.7 installation tutorial (full step, nanny level tutorial)
两个Integer比较大小,为什么100等于100,1000不等于1000?