抛出错误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/