android - 如何伪造 Result.toMappedResponse?
问题描述
尝试制作用于测试的假类不知道如何使其返回所需的带有 MyData 对象的列表。
val result = Result.toMappedResponse(
//Put something here to make it return List of MyData
)
override suspend fun getMyData(
ex: String,
us: String
): Result<List<MyData>> {
return result
}
而且这不是伪造的原始功能
override suspend fun getMyData(
ex: String,
us: String
): Result<List<MyData>> {
return Result.toMappedResponse(
{
toMyDataList(data, this)
},
{ myApi.getDataList() }
)
}
错误说
Not enough information to infer type variable T
public final inline fun <reified T, reified M> toMappedResponse(
mapper: M.() → T,
operation: () → Response<M?> ): Result<T>
并且描述 Helper 来包装操作并根据异常的缺席或存在返回 Success 或 Failure。如果正文为空,则返回 Empty。mapper 用于将操作转换为易于使用的数据。由于协程的性质,try/catch 里程会有所不同。
解决方案
推荐阅读
- reactjs - 如何在一个反应组件中创建多个 swiper 实例并通过另一个滑动来控制一个?
- css - 为什么旋转在 Firefox 中我的元素前后添加空间?
- java - 如何避免通过 iText7 读取复杂 PDF 时内存不足?
- java - Java的作业问题:我正在尝试运行我的程序,它没有显示错误但是当我尝试运行它时它不起作用?
- python - 值错误:时间数据“12:00:01 AM”与使用 time.strptime 的格式“%I:%M:00 %p”不匹配
- javascript - 我想通过使用 php 或其他语言选择多个文本框来进行过滤?
- mysql - 有什么方法可以使用 mysql 在 ssh 上对用户进行身份验证?
- facebook - 营销 API - 缺少系统用户权限,使用开发层
- javascript - 如何使用 bootstrap-datetime-picker-for-rails gem 以 UTC 格式而不是本地时间显示日期选择器
- redhat - Red Hat 8 vpn 客户端无法连接到路由器 ac5300 上的 OpenVPN 服务器