Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems to sets the fragment from a FragmentScenario to be used from DataBindingIdlingResource

I'm following this Google Codelab and at the page 8 (Task: End-to-End Testing with Data Binding), at step 8 (Write DataBindingIdlingResource) you have to create a file called DataBindingIdlingResource.kt.

class DataBindingIdlingResource : IdlingResource {
    [...]
}

private fun View.getBinding(): ViewDataBinding? = DataBindingUtil.getBinding(this)

/**
 * Sets the activity from an [ActivityScenario] to be used from [DataBindingIdlingResource].
 */
fun DataBindingIdlingResource.monitorActivity(
    activityScenario: ActivityScenario<out FragmentActivity>
) {
    activityScenario.onActivity {
        this.activity = it
    }
}

/**
 * Sets the fragment from a [FragmentScenario] to be used from [DataBindingIdlingResource].
 */
fun DataBindingIdlingResource.monitorFragment(fragmentScenario: FragmentScenario<out Fragment>) {
    fragmentScenario.onFragment {
        this.activity = it.requireActivity()
    }
}

The problem: is the last function fun DataBindingIdlingResource.monitorFragment because fragmentScenario.onFragment provides only onFragment(action: Nothing) and not onFragment {}.

How Can I solve this issue? Thanks.

like image 928
capo11 Avatar asked Oct 24 '25 02:10

capo11


1 Answers

I've solved it by changing the definition to

fun <T : Fragment> DataBindingIdlingResource.monitorFragment(fragmentScenario: FragmentScenario<T>) {
like image 95
moozg Avatar answered Oct 25 '25 15:10

moozg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!