-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix a misleading documentation of Observable.singleElement() #5668
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
Fix a misleading documentation of Observable.singleElement() #5668
Conversation
* Returns a Maybe that emits the single item emitted by this Observable if this Observable | ||
* emits only a single item, otherwise if this Observable emits more than one item or no items, an | ||
* {@code IllegalArgumentException} or {@code NoSuchElementException} is signalled respectively. | ||
* Returns a Maybe that emits the single item emitted by this Observable or completes if this Observable is empty. |
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 problem with two sentences is that most IDEs and the Javadoc method listing shows only the first sentence. Could you rewrite it that all relevant behavior is in the same sentence?
Codecov Report
@@ Coverage Diff @@
## 2.x #5668 +/- ##
============================================
- Coverage 96.22% 96.21% -0.01%
- Complexity 5814 5816 +2
============================================
Files 633 633
Lines 41553 41553
Branches 5752 5752
============================================
- Hits 39984 39980 -4
+ Misses 628 626 -2
- Partials 941 947 +6
Continue to review full report at Codecov.
|
Here is the standard link for the marble:
|
Thanks, updated the JavaDoc to include the Marble diagram :) |
@@ -282,6 +282,7 @@ public void testSingleWithEmpty() { | |||
|
|||
InOrder inOrder = inOrder(observer); | |||
inOrder.verify(observer).onComplete(); | |||
inOrder.verify(observer, never()).onError(any(Throwable.class)); |
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 is actually covered by verifyNoMoreInteractions
but being explicit here doesn't hurt.
Fix a misleading documentation of Observable.singleElement() (ReactiveX#5668)
This PR improves the documentation of
Observable.singleElement()
, as mentioned in #5317.An appropriate unit test to verify the
empty
behaviour already exist (ObservableSingleTest. testSingleWithEmpty()
), I just added one more check there to make it very explicit that an error is not thrown.As a side note, I'm attaching an updated Marble diagram for the method that includes all 3 states of the resulting Maybe (empty, success, error). I believe this is listed in #5319.