java – 为任何整数输入参数设置模拟返回值
发布时间:2020-09-07 16:32:22 所属栏目:Java 来源:互联网
导读:when(candidateService.findById(1)).thenReturn(new Candidate()); 我想扩展这种行为为任何整数(不一定为1) 如果我吃惊 when(candidateService.findById( any(Integer.class) )).thenReturn(new Candidate()); 我有编译错误 The method findByI
when(candidateService.findById(1)).thenReturn(new Candidate()); 我想扩展这种行为为任何整数(不一定为1) 如果我吃惊 when(candidateService.findById( any(Integer.class) )).thenReturn(new Candidate()); 我有编译错误
UPDATE 进口: import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import java.util.ArrayList; import java.util.HashSet; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; 解决方法尝试anyInt():when(candidateService.findById( anyInt())).thenReturn(new Candidate()); 例如我的项目中有anyLong(): when(dao.getAddress(anyLong())).thenReturn(Arrays.asList(dto)); 编辑: import static org.mockito.Matchers.anyInt; (编辑:东莞站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- JAVA中使用JSON进行数据传递示例
- Java多线程--让主线程等待所有子线程执行完毕在执行
- Java用 Rhino/Nashorn 代替第三方 JSON 转换库
- java Swing实现选项卡功能(JTabbedPane)实例代码
- java – K和V的HashMap默认类型
- java – JsonMappingException没有单String构造函数/工厂方
- JDK类中java.lang.ref.WeakReference对象的内存泄漏
- java 查询oracle数据库所有表DatabaseMetaData的用法(详解)
- java基于正则提取字符串中的数字功能【如提取短信中的验证码
- Java用正则表达式实现${name}形式的字符串模板实例
