Skip to content

Commit

Permalink
Merge pull request #977 from benjchristensen/dematerialize
Browse files Browse the repository at this point in the history
Dematerialize - handle non-materialized terminal events
  • Loading branch information
benjchristensen committed Mar 20, 2014
2 parents c10af94 + 75b0124 commit bcded86
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ public Subscription onSubscribe(final Observer<? super T> observer) {
return sequence.subscribe(new Observer<Notification<? extends T>>() {
@Override
public void onCompleted() {
observer.onCompleted();
}

@Override
public void onError(Throwable e) {
observer.onError(e);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@
*/
package rx.operators;

import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
import static rx.operators.OperationDematerialize.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static rx.operators.OperationDematerialize.dematerialize;

import org.junit.Test;

import rx.Notification;
import rx.Observable;
import rx.Observer;
import rx.observers.TestSubscriber;

public class OperationDematerializeTest {

Expand Down Expand Up @@ -71,4 +75,35 @@ public void testDematerialize3() {
verify(observer, times(0)).onCompleted();
verify(observer, times(0)).onNext(any(Integer.class));
}

@Test
public void testErrorPassThru() {
Exception exception = new Exception("test");
Observable<Integer> observable = Observable.error(exception);
Observable<Integer> dematerialize = observable.dematerialize();

Observer<Integer> observer = mock(Observer.class);
dematerialize.subscribe(observer);

verify(observer, times(1)).onError(exception);
verify(observer, times(0)).onCompleted();
verify(observer, times(0)).onNext(any(Integer.class));
}

@Test
public void testCompletePassThru() {
Observable<Integer> observable = Observable.empty();
Observable<Integer> dematerialize = observable.dematerialize();

Observer<Integer> observer = mock(Observer.class);
TestSubscriber<Integer> ts = new TestSubscriber<Integer>(observer);
dematerialize.subscribe(ts);

System.out.println(ts.getOnErrorEvents());

verify(observer, never()).onError(any(Throwable.class));
verify(observer, times(1)).onCompleted();
verify(observer, times(0)).onNext(any(Integer.class));
}

}

0 comments on commit bcded86

Please sign in to comment.