Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 无法解析重载的方法返回_Scala_File_Testing_Mockito_Scalatest - Fatal编程技术网

Scala 无法解析重载的方法返回

Scala 无法解析重载的方法返回,scala,file,testing,mockito,scalatest,Scala,File,Testing,Mockito,Scalatest,我是斯卡拉的新手。我正在编写以下代码,其中一个API端点正在缓存文件中的值(SomeJsonData.toString()),另一个端点正在从该文件中检索(Json.parse())。使用When thenReturn编写测试时,出现重载方法错误 我哪里做错了 缓存文件内容: {"time":92345845,"value":[{"name":"Jack","hobby":"paint&

我是斯卡拉的新手。我正在编写以下代码,其中一个API端点正在缓存文件中的值(SomeJsonData.toString()),另一个端点正在从该文件中检索(Json.parse())。使用When thenReturn编写测试时,出现重载方法错误

我哪里做错了

缓存文件内容:

{"time":92345845,"value":[{"name":"Jack","hobby":"paint"}]
CacheController.scala

def retrieveCache = {
    File(filePath).createFile()
    val source = Source.fromFile(filePath)
    val content = try source.mkString
    .....       
}
CacheControllerTest.scala

it("test") {
    val mockSuggestions = "[{\"name\":\"Jack\",\"hobby\":\"paint\"}]"
    val jsonData =Json.obj("time" -> DateTime.now(), "value" -> mockSuggestions)

    when(Source.fromFile(anyString())).thenReturn(jsonData.toString())
    // error: cannot resolve overloaded method thenReturn
}

Source.fromFile
返回一个
BufferedSource
,因此您必须传递
中的一个,然后返回
,而不是字符串