-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate TestLifecycleOwner #433
Conversation
@@ -24,6 +24,7 @@ import io.reactivex.rxjava3.annotations.CheckReturnValue | |||
/** | |||
* Extension that returns a [TestLifecycleOwner] for this [LifecycleRegistry]. | |||
*/ | |||
@Deprecated("Switch to androidx.lifecycle.testing.TestLifecycleOwner") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentionally not using ERROR
since there's no immediate replaceWith option
@@ -43,11 +43,11 @@ public void observable_beforeCreate() { | |||
final PublishSubject<Integer> subject = PublishSubject.create(); | |||
|
|||
// Spin it up | |||
TestLifecycleOwner lifecycle = TestLifecycleOwner.create(); | |||
TestLifecycleOwner lifecycle = new TestLifecycleOwner(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat!
@@ -22,7 +22,7 @@ | |||
import androidx.lifecycle.Lifecycle; | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat!
TestLifecycleOwner lifecycle = new TestLifecycleOwner(); | ||
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE); | ||
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, the default state of TestLifecycleOwner
of STARTED
means you can remove the ON_CREATE
and ON_START
calls here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, good catch
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):