This repository has been archived by the owner on Mar 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
Add deliverLatestToView to rx2/RxTiPresenterUtils #137
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ | |
|
||
import static org.mockito.Mockito.*; | ||
|
||
import io.reactivex.Observable; | ||
import io.reactivex.observers.TestObserver; | ||
import io.reactivex.subjects.PublishSubject; | ||
import net.grandcentrix.thirtyinch.TiPresenter; | ||
import net.grandcentrix.thirtyinch.TiView; | ||
import org.junit.*; | ||
|
@@ -57,4 +59,116 @@ public void testIsViewReady_DisposeBeforeAttachView_ShouldRemoveCallback() throw | |
mPresenter.attachView(mView); | ||
test.assertValue(false); | ||
} | ||
} | ||
|
||
@Test | ||
public void testDeliverLatestToView_ViewNotReady() throws Exception { | ||
mPresenter.create(); | ||
|
||
TestObserver<Integer> testObserver = new TestObserver<>(); | ||
Observable.just(1, 2, 3) | ||
.compose(RxTiPresenterUtils.<Integer>deliverLatestToView(mPresenter)) | ||
.subscribe(testObserver); | ||
|
||
mPresenter.attachView(mView); | ||
|
||
testObserver.assertNotComplete(); | ||
testObserver.assertNoErrors(); | ||
testObserver.assertValuesOnly(3); | ||
} | ||
|
||
@Test | ||
public void testDeliverLatestToView_ViewReady() throws Exception { | ||
mPresenter.create(); | ||
mPresenter.attachView(mView); | ||
|
||
TestObserver<Integer> testObserver = new TestObserver<>(); | ||
Observable.just(1, 2, 3) | ||
.compose(RxTiPresenterUtils.<Integer>deliverLatestToView(mPresenter)) | ||
.subscribe(testObserver); | ||
|
||
testObserver.assertNotComplete(); | ||
testObserver.assertNoErrors(); | ||
testObserver.assertValuesOnly(1, 2, 3); | ||
} | ||
|
||
@Test | ||
public void testDeliverLatestToView_ViewNeverReady() throws Exception { | ||
mPresenter.create(); | ||
|
||
TestObserver<Integer> testObserver = new TestObserver<>(); | ||
Observable.just(1, 2, 3) | ||
.compose(RxTiPresenterUtils.<Integer>deliverLatestToView(mPresenter)) | ||
.subscribe(testObserver); | ||
|
||
testObserver.assertNotComplete(); | ||
testObserver.assertNoErrors(); | ||
testObserver.assertEmpty(); | ||
} | ||
|
||
@Test | ||
public void testDeliverLatestToView_ViewComesAndGoes() throws Exception { | ||
mPresenter.create(); | ||
|
||
PublishSubject<Integer> source = PublishSubject.create(); | ||
TestObserver<Integer> testObserver = new TestObserver<>(); | ||
|
||
source | ||
.compose(RxTiPresenterUtils.<Integer>deliverLatestToView(mPresenter)) | ||
.subscribe(testObserver); | ||
|
||
source.onNext(1); | ||
source.onNext(2); | ||
mPresenter.attachView(mView); | ||
source.onNext(3); | ||
mPresenter.detachView(); | ||
source.onNext(4); | ||
source.onNext(5); | ||
mPresenter.attachView(mView); | ||
source.onNext(6); | ||
|
||
testObserver.assertNotComplete(); | ||
testObserver.assertNoErrors(); | ||
testObserver.assertValuesOnly(2, 3, 5, 6); | ||
} | ||
|
||
@Test | ||
public void testDeliverLatestToView_SingleItemViewComesAndGoes() throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add this test to rx1 as well. I'm actually not sure this is working. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For that I've created a new issue. See #138 |
||
mPresenter.create(); | ||
|
||
PublishSubject<Integer> source = PublishSubject.create(); | ||
TestObserver<Integer> testObserver = new TestObserver<>(); | ||
|
||
source | ||
.compose(RxTiPresenterUtils.<Integer>deliverLatestToView(mPresenter)) | ||
.subscribe(testObserver); | ||
|
||
source.onNext(1); | ||
source.onNext(2); | ||
mPresenter.attachView(mView); | ||
mPresenter.detachView(); | ||
mPresenter.attachView(mView); | ||
mPresenter.detachView(); | ||
mPresenter.attachView(mView); | ||
|
||
testObserver.assertNotComplete(); | ||
testObserver.assertNoErrors(); | ||
testObserver.assertValuesOnly(2, 2, 2); | ||
} | ||
|
||
@Test | ||
public void testDeliverLatestToView_Empty() throws Exception { | ||
mPresenter.create(); | ||
|
||
TestObserver<Integer> testObserver = new TestObserver<>(); | ||
Observable.<Integer>empty() | ||
.compose(RxTiPresenterUtils.<Integer>deliverLatestToView(mPresenter)) | ||
.subscribe(testObserver); | ||
|
||
mPresenter.attachView(mView); | ||
|
||
testObserver.assertNotComplete(); | ||
testObserver.assertNoErrors(); | ||
testObserver.assertEmpty(); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 must admit, when I wrote the
rx1
version I copied most of the docs.Actually the main thread restriction is not true it's only recommended to make sure the view is always non null. Attach/Detach happens on the main thread. When code executes on any other thread it's not guaranteed that those actions happen before the view attach/detach state changes. So it may happen that the emission of
T
happens after the view got detached.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 happy to rewrite the comment. The behaviour should be clear from the tests anyway, I hope.