Skip to content
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

Merged
merged 5 commits into from
Aug 9, 2021
Merged

Deprecate TestLifecycleOwner #433

merged 5 commits into from
Aug 9, 2021

Conversation

ZacSweers
Copy link
Collaborator

@@ -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")
Copy link
Collaborator Author

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();

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.

Copy link
Collaborator Author

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;

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.

Copy link
Collaborator Author

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

Comment on lines 48 to 51
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START);
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME);

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat!

Comment on lines 106 to 109
TestLifecycleOwner lifecycle = new TestLifecycleOwner();
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START);

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, good catch

@ZacSweers ZacSweers merged commit e5b4c32 into main Aug 9, 2021
@ZacSweers ZacSweers deleted the z/deprecate branch August 9, 2021 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants