java - 如何为 int[] 编写 easyMock.expect

标签 java unit-testing reflection easymock

抛出错误TargetincallException。

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 个报告的错误。由于无法匹配模拟对象和原始值

最佳答案

andReturn方法将返回值作为参数,但是 EasyMock.aryEq返回 null(请参阅 Source )。您可以使用 .andReturn(new int[] {1})相反 .andReturn(EasyMock.arEq(new int[] {1}))) .

关于java - 如何为 int[] 编写 easyMock.expect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58637915/

相关文章:

java - EJB3 业务代表

java - 尝试使用正则表达式解析日志文件

php - 将 PHPUnit 从 4.8 升级到 5.5

javascript - Jasmine - 监视 EXTJS 监听器中调用的函数

java - 是否可以从 SWT 到 JavaFx 使用 NatTable 组件?

java - 如何停止执行直到所有异步任务在android中完成执行?

ios - 单元测试 key

java - 有没有办法判断运行时类型是否被删除

c# - 如何使用反射按名称调用方法

java - Java中如何通过反射获取方法参数的值?