My understanding is that I can use the merge operator with 2 other Observables followed by the firstOrError operator to return the first Observable that returns a result.
I'm trying to run a test case but it doesn't seem to do what I thought it would do, so not sure if there's an issue with my test or I'm using the operators incorrectly, I appreciate if anyone could help me with that. If anyone know of a better way to achieve the same results that would be great too.
Here's my test case:
@Test
public void testMergeOperator() {
TestObserver<String> observer = new TestObserver<>();
Observable<String> foo = Observable.just("FOO");
Observable<String> bar = Observable.timer(2, SECONDS).just("BAR");
foo.publish(first -> Observable.merge(first, bar.takeUntil(first))
.firstOrError()
.toObservable())
.subscribe(observer);
assertEquals(1, observer.valueCount());
assertEquals("FOO", observer.values().get(0));
}
And I'm getting:
junit.framework.ComparisonFailure: Expected :FOO Actual :BAR
Aucun commentaire:
Enregistrer un commentaire