我想知道是否有一种方法可以访问Android模拟器中文件系统的本地文件(比如文本文件,网页).
我正在使用Ubuntu 10.04进行Android开发.
我使用AndroidViewModelwith LiveData将Intent发送到IntentService并从EventBus接收事件。我需要意图和EventBus的应用程序上下文。
用本地测试测试AndroidViewModel类的最佳方法是什么?我可以从Robolectrics RuntimeEnvironment.application开始,但是似乎没有ShadowOf()用于AndroidViewModel来检查是否将正确的Intent发送到了正确的接收者。
也许可以通过Mockito使用我自己的模拟意图将其注入并注入到我的中AndroidViewModel,但这似乎不是很简单。
我的代码如下所示:
class UserViewModel(private val app: Application) : AndroidViewModel(app){
val user = MutableLiveData<String>()
...
private fun startGetUserService() {
val intent = Intent(app, MyIntentService::class.java)
intent.putExtra(...)
app.startService(intent)
}
@Subscribe
fun handleSuccess(event: UserCallback.Success) {
user.value = event.user
}
}
Run Code Online (Sandbox Code Playgroud)
肺动脉测试:
@RunWith(RobolectricTestRunner.class)
public class Test {
@Test
public void testUser() {
UserViewModel model = new UserViewModel(RuntimeEnvironment.application)
// how do I test that startGetUserService() is sending
// the Intent to MyIntentService and check the …Run Code Online (Sandbox Code Playgroud) 如果我有一个具有以下签名的方法:
def max[T <% Ordered[T]](list:List[T]): T={
//return max. element of List (for example)
}
Run Code Online (Sandbox Code Playgroud)
我想给它一个这样的对列表:
val fu:List[Pair[String, Double]] = List(Pair("a", 3.1),Pair("b", 1.7),Pair("c", 3.1),Pair("d", 5.4))
Run Code Online (Sandbox Code Playgroud)
如何在列表的第二个元素上定义排序,以便我能够在函数中使用它?
我试着用
implicit def wrapper(p: Pair[String, Double])=new runtime.RichDouble(p._2)
Run Code Online (Sandbox Code Playgroud)
隐式地将对的Double转换为扩展有序特征的RichDouble,但这不起作用.