有没有办法,使用Mockito来定义这样的表达式?
when(mockObject.getValuesFor(in(1, 2, 3)).thenReturn(List.of(...)));
在ArgumentMatchers
和AdditionalMatchers
中定义的方法中,我找不到像in()
这样的方法,所以我想知道哪种方法是实现我所需要的方法的常用方法。
- 注意**我所模拟的方法声明如下:
List<Integer> getValuesFor(int arg) {...}
有没有办法,使用Mockito来定义这样的表达式?
when(mockObject.getValuesFor(in(1, 2, 3)).thenReturn(List.of(...)));
在ArgumentMatchers
和AdditionalMatchers
中定义的方法中,我找不到像in()
这样的方法,所以我想知道哪种方法是实现我所需要的方法的常用方法。
List<Integer> getValuesFor(int arg) {...}
2条答案
按热度按时间kcugc4gi1#
我认为
intThat
非常接近您的需求:此外,您可以提取一个生成内部
ArgumentMatcher<Integer>
的方法,这将使您的代码看起来像72qzrwbm2#
我找不到。所以我使用下面的解决方法。
如果没有传递相同的列表作为方法参数,则测试用例在assert语句中将失败。