【问题标题】:how to match a mocked call with wildcard in scala test?如何在scala测试中将模拟调用与通配符匹配?
【发布时间】:2017-05-31 10:26:19
【问题描述】:

寻找这样的东西:

    //Mockito when rawData.filter(filter) thenReturn mockInfo
    //this won't work because the parameter can only match one instance
    //but I want
    Mockito when rawDataRDD.filter(*) thenReturn mockInfo

那么我应该如何在 Scala 测试中匹配带有通配符的间谍调用?

更多解释:

我正在scala test 中寻找一个间谍模拟,其中所有对 RDD 过滤器的调用都将被捕获并返回指定的模拟结果。

更一般地说,在 Scala 中寻找匹配函数(就像 java 中的 AnyString),如 anyFunction 以匹配所有过滤器函数。

【问题讨论】:

标签: scala testing mockito


【解决方案1】:

使用Matchers.any()

 Mockito when rawDataRDD.filter(Matchers.any()) thenReturn mockInfo

【讨论】:

  • 太棒了,谢谢。为什么我很难在文档中搜索这样的东西
  • 对于更高版本的 Mockito,这应该是 org.mockito.Mockito.any(),以免与 Hamcrest 混淆。 org.mockito.Matchers.any() 现已弃用
猜你喜欢
  • 1970-01-01
  • 2013-09-03
  • 2020-10-21
  • 2014-02-21
  • 2017-07-02
  • 2015-02-17
  • 2016-08-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多