【发布时间】:2019-03-17 05:32:15
【问题描述】:
我有一个看起来像这样的配置提取器。
def getForCountry[A](path: String, fallbackToDefault: Boolean)
(implicit loader: ConfigLoader[A], ac: AppContext): A = {
configuration.getOptional[A](s"${ac.country}.$path") match {
case Some(value) =>
value
case None if fallbackToDefault =>
configuration.get[A](path)
case None if !fallbackToDefault =>
throw new RuntimeException(s"${ac.country}.$path key not found in configuration")
}
同一个方法的调用如下-
val countrySpecificConfig =
configurationHelper.getForCountry[Map[String, String]]("googleCloudPlatform.jobConfig.demandBasedPricing", fallbackToDefault = false)
现在我想在我的单元测试中模拟 getForCountry 方法 -
when(configurationHelper
.getForCountry[Map[String, String]]("googleCloudPlatform.jobConfig.demandBasedPricing", fallbackToDefault = false))
.thenReturn(countryPricingWeekConfiguation)
令人惊讶的是,这种期望似乎没有正确设置。在执行测试时,模拟返回 null。
关于如何进行此操作的任何线索?如果您需要更多详细信息,请随时告诉我。
【问题讨论】:
标签: scala unit-testing playframework mockito expectations