My Espresso Idling Resource is not working - it compiles and runs but no longer waits long enough for the result to be returned from the 'net.
- Start with https://github.com/chiuki/espresso-samples/tree/master/idling-resource-okhttp
- Convert the main activity to Kotlin - test (which is still in java) still works with OKHttpIdlingResource
- Convert to anko coroutine call instead of retrofit.enqueue - test no longer works.
Here is the new code for MainActivity in its entirety
import android.app.Activity
import android.os.Bundle
import android.widget.TextView
import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.async
import org.jetbrains.anko.coroutines.experimental.bg
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
doCallAsync()
}
private fun doCallAsync() = async(UI) {
val user = bg { getUser() }
val name = user.await().name
val nameView = findViewById(R.id.name) as TextView
nameView.text = name;
}
private fun getUser(): User {
val retrofit = Retrofit.Builder()
.baseUrl("https://api.github.com/")
.addConverterFactory(MoshiConverterFactory.create())
.client(OkHttpProvider.getOkHttpInstance())
.build()
val service = retrofit.create(GitHubService::class.java)
val response = service.getUser("chiuki").execute().body()
return response!!
}
}