2.x: Test static from methods and add Maybe.fromSingle & fromCompletable#4685
2.x: Test static from methods and add Maybe.fromSingle & fromCompletable#4685akarnokd merged 1 commit intoReactiveX:2.xfrom vanniktech:test_coverage
Conversation
vanniktech
commented
Oct 9, 2016
- add Maybe.fromSingle by reusing MaybeFromSingle
- add Maybe.fromCompletable by resuing MaybeFromCompletable
- remove anonymous classes in various operators
- add tests for
- Completable.fromAction()
- Completable.fromCallable()
- Completable.fromObservable()
- Completable.fromPublisher()
- Completable.fromRunnable()
- Completable.fromSingle()
- Maybe.fromAction()
- Maybe.fromCallable()
- Maybe.fromCompletable()
- Maybe.fromRunnable()
- Maybe.fromSingle()
- Single.fromCallable()
| observable.subscribe(new CompletableFromObservableObserver<T>(s)); | ||
| } | ||
|
|
||
| static class CompletableFromObservableObserver<T> implements Observer<T> { |
There was a problem hiding this comment.
sorry, didn't see the enclosing package.
| public void onError(Throwable e) { | ||
| s.onError(e); | ||
| } | ||
| static class CompletableFromSingleObserver<T> implements SingleObserver<T> { |
| Completable.fromRunnable(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
|
|
There was a problem hiding this comment.
I'd increment a counter and assert its 1.
There was a problem hiding this comment.
Can also test calling twice increments twice. And that it calls lazily (not on creation).
Current coverage is 82.10% (diff: 100%)@@ 2.x #4685 diff @@
==========================================
Files 565 565
Lines 37426 37436 +10
Methods 0 0
Messages 0 0
Branches 5746 5746
==========================================
+ Hits 30702 30736 +34
+ Misses 4644 4614 -30
- Partials 2080 2086 +6
|
| * @return the new Maybe instance | ||
| * @throws NullPointerException if completable is null | ||
| */ | ||
| @SchedulerSupport(SchedulerSupport.NONE) |
There was a problem hiding this comment.
final isn't needed. This should be CompletableSource otherwise it's redundant with toMaybe().
There was a problem hiding this comment.
Yeah I copied the signature from the method above and that one is using final. Not everything is consistent though. I'll change it though
| * @return the new Maybe instance | ||
| * @throws NullPointerException if single is null | ||
| */ | ||
| @SchedulerSupport(SchedulerSupport.NONE) |
| Completable.fromAction(new Action() { | ||
| @Override | ||
| public void run() throws Exception { | ||
|
|
There was a problem hiding this comment.
And make sure second subscription increments again
| Completable.fromCallable(new Callable<Object>() { | ||
| @Override | ||
| public Object call() throws Exception { | ||
| return null; |
There was a problem hiding this comment.
Assert with counter. You could return it's value and assert you only get 1 and that a subsequent call gets 2
| Completable.fromRunnable(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
|
|
There was a problem hiding this comment.
Can also test calling twice increments twice. And that it calls lazily (not on creation).
| Maybe.fromAction(new Action() { | ||
| @Override | ||
| public void run() throws Exception { | ||
|
|
| Completable.fromCallable(new Callable<Object>() { | ||
| @Override | ||
| public Object call() throws Exception { | ||
| return null; |
| Maybe.fromRunnable(new Runnable() { | ||
| @Override | ||
| public void run() { | ||
|
|
|
Anything missing here? I updated this PR on Sunday with the requested changes. |