我的单元测试用例中出现以下异常
org.mockito.exceptions.misusing.WrongTypeOfReturnValue:
ConstFuture cannot be returned by toString()
toString() should return String
我测试的代码段在这里
class DeviceStoreServiceESRetrySpec extends WordSpec with Matchers {
// val elasticStore = mock[ElasticsearchStore]
val esDao = mock[ESDeviceDao]
implicit val bulkPutPool: FuturePool =
FuturePool.interruptible(
Executors.newFixedThreadPool(10)
)
val deviceUpdateStatus = DeviceUpdateStatus("abc", "")
val res1 = BulkResponse(201, "", List.empty, List.empty, List(deviceUpdateStatus))
val resp1JsonStr: String = res1.asJson.nospaces
val res2 = BulkResponse(200, "", List.empty, List.empty, List.empty)
val resp2JsonStr: String = res2.asJson.nospaces
val deviceRecords = DeviceArbitraries.bulkArbDevice(2)
when(esDao.binaryManifestBulkIndex(deviceRecords)(bulkPutPool)) thenReturn (Future.value(
Try(resp2JsonStr)
))
object MockDeviceServiceModule extends TwitterModule {
@Provides
@Singleton
def provideDeviceDataService(): DeviceStoreService = {
new DeviceStoreService(
esDao.binaryManifestBulkIndex,
100,
StatsReceiverFactory.nullStatsReceiverFactory,
StorageConfig("DeviceStoreServiceESRetrySpec", 30, 5),
Map("host" -> "ES"),
"Elasticsearch Client"
)
}
val injector = TestInjector(MockDeviceServiceModule)
val deviceStoreService = injector.instance[DeviceStoreService]
"An DeviceStoreService instance" should {
"successfully index device events" in {
deviceStoreService.store(deviceRecords)
Mockito.verify(esDao, times(10)).binaryManifestBulkIndex(deviceRecords)
}
}
}
}
请在这里任何帮助