Deprecate TestLifecycleOwner #433
Conversation
| /** | ||
| * Extension that returns a [TestLifecycleOwner] for this [LifecycleRegistry]. | ||
| */ | ||
| @Deprecated("Switch to androidx.lifecycle.testing.TestLifecycleOwner") |
There was a problem hiding this comment.
Intentionally not using ERROR since there's no immediate replaceWith option
|
|
||
| // Spin it up | ||
| TestLifecycleOwner lifecycle = TestLifecycleOwner.create(); | ||
| TestLifecycleOwner lifecycle = new TestLifecycleOwner(); |
There was a problem hiding this comment.
The default initialState is Lifecycle.State.STARTED - you'll want to use new TestLifecycleOwner(LifecycleState.INITIALIZING) if you want to manually move through each lifecycle state.
Same for all other uses.
| import androidx.test.annotation.UiThreadTest; | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
| import autodispose2.androidx.lifecycle.test.TestLifecycleOwner; | ||
| import androidx.lifecycle.testing.TestLifecycleOwner; |
There was a problem hiding this comment.
I'm not sure if you care about sorting imports, but I would expect this to be sorted above the androidx.test imports.
There was a problem hiding this comment.
thanks, will let spotless clean this up
| lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE); | ||
| lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START); | ||
| lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME); |
There was a problem hiding this comment.
Note that handleLifecycleEvent(Lifecycle.Event.ON_RESUME) will catch the Lifecycle up through all events, so there's no technical reason to call handleLifecycleEvent multiple times in a row like this.
You might also consider using lifecycle.currentState = Lifecycle.State.RESUMED, which does the exact same thing.
| TestLifecycleOwner lifecycle = new TestLifecycleOwner(); | ||
| lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE); | ||
| lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START); |
There was a problem hiding this comment.
In this case, the default state of TestLifecycleOwner of STARTED means you can remove the ON_CREATE and ON_START calls here.
In favor of the androidx 1st party alternative - https://cs.android.com/androidx/platform/frameworks/support/+/androidx-master-dev:lifecycle/lifecycle-runtime-testing/src/main/java/androidx/lifecycle/testing/TestLifecycleOwner.kt
Description:
Related issue(s):