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

Adding TestLifecycleScopeProvider. #48

Merged
merged 3 commits into from Mar 13, 2017
Merged

Conversation

tonycosentini
Copy link
Contributor

#45

This isn't quite ready for merging, but I wanted to open a PR to discuss the API for TestLifecycleScopeProvider.


@Override
public Object peekLifecycle() {
return lifecycleSubject.getValue();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this block or return null?

Copy link
Collaborator

Choose a reason for hiding this comment

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

returns null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍🏻 perfect

return TestLifecycle.STOPPED;
case STOPPED:
throw new LifecycleEndedException();
default:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be removed and just throw at the end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's worth having a distinction between the lifecycle actually ending versus some random unknown event.

(Side note: I wish Java had exhaustive switches - can just avoid this entirely.)

*/
public final class TestLifecycleScopeProvider implements LifecycleScopeProvider {

private final BehaviorSubject<TestLifecycle> lifecycleSubject = BehaviorSubject.create();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be worthwhile to have a constructor that initializes this with an event?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I can make an UNKNOWN event types. It adds a bit of complexity for the corresponding event function, but it's better than having a subject with nothing.

@ZacSweers
Copy link
Collaborator

Since this doesn't actually require any test dependencies, what would you think of just including it in the main artifact? Similar to how RxJava includes test tools

@tonycosentini
Copy link
Contributor Author

Since this doesn't actually require any test dependencies, what would you think of just including it in the main artifact? Similar to how RxJava includes test tools

I think that's fine if this is the only test utility (+ moving the one that exists internally for ScopeProvider), but if it grows to be pretty big it might become a pain.

@ZacSweers
Copy link
Collaborator

I think I'd rather keep it simple for now and separate it if need be. Between kotlin, android, and the main artifact we already have a few.

lifecycleSubject.onNext(TestLifecycle.STOPPED);
}

private enum TestLifecycle {
enum TestLifecycle {
UNINITIALIZED,
Copy link
Collaborator

@ZacSweers ZacSweers Mar 13, 2017

Choose a reason for hiding this comment

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

I don't think we want to promote this. peekLifecycle() expects null if not started, and autodispose should handle the LifecycleNotStartedException throwing under the hood in accordance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, misinterpreted your comment above.

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

/**
* @return a new {@link TestLifecycleScopeProvider} instance.
*/
public static TestLifecycleScopeProvider create() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want overloads for initial state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

* @return a new {@link TestLifecycleScopeProvider} instance with {@param initialValue} as its initial lifecycle
* event.
*/
public static TestLifecycleScopeProvider createInitial(TestLifecycle initialValue) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we keep an empty create() still?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's still useful, I can see a lot of cases where you want to create one without necessarily putting it in a started state.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh oops, I thought you'd replaced it with this, didn't see you'd just added this :P. LGTM

Copy link
Collaborator

@ZacSweers ZacSweers left a comment

Choose a reason for hiding this comment

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

One minor nit. Also - are you going to add the TestScopeProvider implementation on this PR?

@tonycosentini
Copy link
Contributor Author

I was planning on just porting the one you wrote in another PR if that works.

@ZacSweers
Copy link
Collaborator

That's fine

@tonycosentini tonycosentini merged commit 3e2c0c3 into master Mar 13, 2017
@ZacSweers ZacSweers mentioned this pull request Mar 13, 2017
@ZacSweers ZacSweers mentioned this pull request May 7, 2017
@ZacSweers ZacSweers deleted the tc_add_test_module branch June 13, 2020 22:21
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.

None yet

2 participants