Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/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
Kotlin mockito参数匹配器问题_Kotlin_Mockito_Mockito Kotlin - Fatal编程技术网

Kotlin mockito参数匹配器问题

Kotlin mockito参数匹配器问题,kotlin,mockito,mockito-kotlin,Kotlin,Mockito,Mockito Kotlin,我试图在多个参数中验证一个特定的参数。我想核实的其他论点性质简单。但是有一个论点我想用check{}来彻底验证它。此操作失败并出现错误。我已经记下了代码和错误 测试: 内部类UserInfoServiceTest:StringSpec(){ 初始化{ “应从身份验证服务器返回用户信息”{ val userInfo=userInfo(“Sethu”、“pictureUrl”) val restTemplate:restTemplate=mock{ 关于{交换( eq(“authurl/userIn

我试图在多个参数中验证一个特定的参数。我想核实的其他论点性质简单。但是有一个论点我想用check{}来彻底验证它。此操作失败并出现错误。我已经记下了代码和错误

测试:

内部类UserInfoServiceTest:StringSpec(){
初始化{
“应从身份验证服务器返回用户信息”{
val userInfo=userInfo(“Sethu”、“pictureUrl”)
val restTemplate:restTemplate=mock{
关于{交换(
eq(“authurl/userInfo”),
eq(HttpMethod.GET),
any(),
eq(UserInfo::class.java))
}多雷图恩
响应(用户信息(“Sethu”、“pictureUrl”),
HttpStatus.OK)
}
val userInfoService=userInfoService(restTemplate,“authurl”)
val returnedUserInfo=userInfoService.getUserInfoFromAuth(“accessToken”)
returnedUserInfo应为userInfo
验证(restTemplate).exchange(eq(“authurl/userInfo”),
eq(HttpMethod.GET),
选中{httpEntity->
httpEntity.headers.getValue(“授权”)应为“承载访问令牌”
},
eq(UserInfo::class.java))
}
}
}

主题:

data class UserInfo(val name: String, val picture: String?)

@Service
class UserInfoService(val restTemplate: RestTemplate,
                  @Value(value = "\${auth0.issuer}") val authServerUrl: String) {

fun getUserInfoFromAuth(accessToken: String): UserInfo {
    val headers = HttpHeaders()
    headers.set(HttpHeaders.AUTHORIZATION, "Bearer $accessToken")
    val request = HttpEntity<Void>(headers)
    val response = restTemplate.exchange("$authServerUrl/userInfo", HttpMethod.GET, request, UserInfo::class.java)
    return response.body!!
}
}
数据类UserInfo(val名称:String,val图片:String?)
@服务
类UserInfoService(val restTemplate:restTemplate,
@值(Value=“\${auth0.issuer}”)val authServerUrl:String){
fun getUserInfoFromAuth(accessToken:String):UserInfo{
val headers=HttpHeaders()
headers.set(HttpHeaders.AUTHORIZATION,“Bearer$accessToken”)
val请求=HttpEntity(标头)
val response=restemplate.exchange(“$authServerUrl/userInfo”,HttpMethod.GET,request,userInfo::class.java)
回复。身体!!
}
}
错误:

Argument(s) are different! Wanted:
restTemplate.exchange(
    "authurl/userInfo",
    GET,
    <custom argument matcher>,
    class csmart.api.user.UserInfo
);
-> at csmart.api.user.UserInfoServiceTest$1.invokeSuspend(UserInfoServiceTest.kt:29)
Actual invocation has different arguments:
restTemplate.exchange(
    "authurl/userInfo",
    GET,
    <[Authorization:"Bearer accessToken"]>,
    class csmart.api.user.UserInfo
);
-> at csmart.api.user.UserInfoService.getUserInfoFromAuth(UserInfoService.kt:21)
参数不同!通缉:
restTemplate.exchange(
“authurl/userInfo”,
得到,
,
类csmart.api.user.UserInfo
);
->在csmart.api.user.UserInfoServiceTest$1.invokeSuspend(UserInfoServiceTest.kt:29)
实际调用有不同的参数:
restTemplate.exchange(
“authurl/userInfo”,
得到,
,
类csmart.api.user.UserInfo
);
->在csmart.api.user.UserInfoService.getUserInfoFromAuth(UserInfoService.kt:21)上

我已经开始使用Mock库在kotlin中进行模拟。它非常坚固,而且更加成熟。
Argument(s) are different! Wanted:
restTemplate.exchange(
    "authurl/userInfo",
    GET,
    <custom argument matcher>,
    class csmart.api.user.UserInfo
);
-> at csmart.api.user.UserInfoServiceTest$1.invokeSuspend(UserInfoServiceTest.kt:29)
Actual invocation has different arguments:
restTemplate.exchange(
    "authurl/userInfo",
    GET,
    <[Authorization:"Bearer accessToken"]>,
    class csmart.api.user.UserInfo
);
-> at csmart.api.user.UserInfoService.getUserInfoFromAuth(UserInfoService.kt:21)