-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Add assertValueAt(int, value) to TestObserver #5529
Conversation
There is an |
I personally make heavy use of the If this causes an overload problem, we'll have the same problem with |
Codecov Report
@@ Coverage Diff @@
## 2.x #5529 +/- ##
===========================================
+ Coverage 96.14% 96.2% +0.05%
- Complexity 5806 5821 +15
===========================================
Files 631 631
Lines 41285 41414 +129
Branches 5732 5740 +8
===========================================
+ Hits 39693 39841 +148
+ Misses 629 621 -8
+ Partials 963 952 -11
Continue to review full report at Codecov.
|
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.
LGTM, I would use that!
|
||
thrown.expect(AssertionError.class); | ||
thrown.expectMessage("Expected: 2 (class: Integer), Actual: 3 (class: Integer) (latch = 0, values = 3, errors = 0, completions = 1)"); | ||
ts.assertValueAt(2, 2); |
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.
Can you please compare something else than integers (String will be ok)?
Silly code change in assert method can break its logic but pass this test because both index and value are 2
:)
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.
Good call.
We need to find some kind of policy for adding new API methods or not. I'd say let's not get this in. Write a Kotlin extension functions 🙃 or use the If this gets in I also would like to have |
I'm pretty sure this method will be much more popular than Mr For simple equals comparisons (which I believe are 95+% of asserts on values) this variant is definitely better than
|
Independent additions are individually evaluated based on the merits, value, quality and maintenance requirements they pose. This PR is self contained and adds a convenience pair to an existing method. Plus, once merged in, there will be no need for further development on it. In contrast, all those |
Alright, you got me convinced now. If those shorthands were to be implemented one by one and also in an optimized way, would you consider PRs for that? |
Yes. |
@@ -403,6 +403,31 @@ public final U assertNever(Predicate<? super T> valuePredicate) { | |||
|
|||
/** | |||
* Asserts that this TestObserver/TestSubscriber received an onNext value at the given index | |||
* which is equal to the given value with respect to Objects.equals. |
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.
Objects
is a Java 8 component but ObjectHelper
is internal, thus maybe let's say "with respect to null-safe Object.equals()".
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.
Fixed the other javadoc I copied that from too :)
* @param index the position to assert on | ||
* @param value the value to expect | ||
* @return 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.
@since 2.1.3 - experimental
* @return this | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public final U assertValueAt(int index, T value) { |
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.
@Experimental
throw fail("No values"); | ||
} | ||
|
||
if (index >= values.size()) { |
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.
Use s
instead of values.size()
here.
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.
Nice catch.
Thanks for the reviews! |
CI is failing due to |
There has been an image change on Travis CI and JDK 7 is no longer supported. See #5531. |
Could you rebase the PR so the build settings can take effect? |
* 2.x: Try fixing Travis CI lack of java * Force dist: precise * Oracle JDK 8 is then
Thanks! |
I found myself frequently writing tests that want to check that an observable emitted a certain value second or third, but I don't care what the first or other values one, so
assertValues(Object...))
is more brittle.This PR implements an
assertValueAt(index, value)
method, similar toassertValue(value)
. Tests are also added.