java - 如何为 int[] 编写 easyMock.expect
问题描述
引发错误 Targetinvocationexception。
public class A{
public method_name(){
int[] selections = grid.getSelectedIndices(); // Facing issue here...!
// Problem occur above line.
}
}
public class A_test{
Grid grid = EasyMock.createNicemock(Grid.class);
EasyMock.expect(grid.getSelectedIndices().andReturn(EasyMock.arEq(new int[] {1})));
EasyMock.replay(grid);
// I able to invoke method with the help of reflection
// method.invoke();
}
问题:我无法期待“getSelectedIndices()”。在某些更改中,它给了我 0 个匹配器和 1 个报告的错误。因为无法匹配模拟对象和原始值
解决方案
类似于另一个答案。它的工作方式是通过匹配参数来期望参数,如果匹配,则返回一个值。所以代码应该是。
public class A_test {
Grid grid = niceMock(Grid.class);
expect(grid.getSelectedIndices()).andReturn(new int[] {1});
replay(grid);
A a = new A(grid);
a.method_name();
}
推荐阅读
- python - Django 错误:无法使用 ImageField,因为未安装 Pillow
- javascript - 运行进程时codeigniter中的空白屏幕
- python - 如何通过python和selenium按照html单击文本为Continue的按钮
- angular - Angular 6 库 - 引导样式
- java - 创建一个包含方法的列表,然后在 Android 中执行
- oracle - 如何在 PL SQL Developer 中设置 OJDBC 版本
- javascript - React.js 从系统加载降价文件作为字符串
- android - 实时数据库安全 [Android]
- html - Bootstrap 4 列未达到 100% 高度
- windows - 如何在 .bat 文件 (Windows) 中使用 ImageMagick 来调整所有子目录中的所有图像的大小?