-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add Single.doOnSuccess() #3417
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
Merged
abersnaze
merged 1 commit into
ReactiveX:1.x
from
artem-zinnatullin:single-do-on-success
Oct 9, 2015
Merged
Add Single.doOnSuccess() #3417
Changes from all commits
Commits
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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
import static org.junit.Assert.assertSame; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
import static org.mockito.Matchers.eq; | ||
import static org.mockito.Mockito.doThrow; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
@@ -570,4 +571,81 @@ public void shouldPassErrorFromCallable() throws Exception { | |
|
||
verify(callable).call(); | ||
} | ||
|
||
@Test | ||
public void doOnSuccessShouldInvokeAction() { | ||
Action1<String> action = mock(Action1.class); | ||
|
||
TestSubscriber<String> testSubscriber = new TestSubscriber<String>(); | ||
|
||
Single | ||
.just("value") | ||
.doOnSuccess(action) | ||
.subscribe(testSubscriber); | ||
|
||
testSubscriber.assertValue("value"); | ||
testSubscriber.assertNoErrors(); | ||
|
||
verify(action).call(eq("value")); | ||
} | ||
|
||
@Test | ||
public void doOnSuccessShouldPassErrorFromActionToSubscriber() { | ||
Action1<String> action = mock(Action1.class); | ||
|
||
Throwable error = new IllegalStateException(); | ||
doThrow(error).when(action).call(eq("value")); | ||
|
||
TestSubscriber<String> testSubscriber = new TestSubscriber<String>(); | ||
|
||
Single | ||
.just("value") | ||
.doOnSuccess(action) | ||
.subscribe(testSubscriber); | ||
|
||
testSubscriber.assertNoValues(); | ||
testSubscriber.assertError(error); | ||
|
||
verify(action).call(eq("value")); | ||
} | ||
|
||
@Test | ||
public void doOnSuccessShouldNotCallActionIfSingleThrowsError() { | ||
Action1<Object> action = mock(Action1.class); | ||
|
||
Throwable error = new IllegalStateException(); | ||
|
||
TestSubscriber<Object> testSubscriber = new TestSubscriber<Object>(); | ||
|
||
Single | ||
.error(error) | ||
.doOnSuccess(action) | ||
.subscribe(testSubscriber); | ||
|
||
testSubscriber.assertNoValues(); | ||
testSubscriber.assertError(error); | ||
|
||
verifyZeroInteractions(action); | ||
} | ||
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. Could you also test what happens if the 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. See |
||
|
||
@Test | ||
public void doOnSuccessShouldNotSwallowExceptionThrownByAction() { | ||
Action1<String> action = mock(Action1.class); | ||
|
||
Throwable exceptionFromAction = new IllegalStateException(); | ||
|
||
doThrow(exceptionFromAction).when(action).call(eq("value")); | ||
|
||
TestSubscriber<String> testSubscriber = new TestSubscriber<String>(); | ||
|
||
Single | ||
.just("value") | ||
.doOnSuccess(action) | ||
.subscribe(testSubscriber); | ||
|
||
testSubscriber.assertNoValues(); | ||
testSubscriber.assertError(exceptionFromAction); | ||
|
||
verify(action).call(eq("value")); | ||
} | ||
} |
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.
This should start out as experimental unless the RxJava contributors want to fast-track this.
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 didn't add
@Experimental
here and in the other PRs because whole classSingle
is marked with@Experimental
. Do you think we should mark these basic operators too?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.
Yep, this is a bit of a conflict because #3401 gets merged first, this would also become beta without any votes.
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.
Okay, no problem. I'll mark it as @experimental.
чт, 8 Окт 2015, 12:44, David Karnok notifications@github.com:
@artem_zin
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.
Added
@Experimental