OperationDefaultIfEmpty { public static <T> OnSubscribeFunc<T> defaultIfEmpty( Observable<? extends T> source, T defaultValue) { return new DefaultIfEmpty<T>(source, defaultValue); }  static OnSubscribeFunc<T> defaultIfEmpty(
            Observable<? extends T> source, T defaultValue);  }
@Test public void testDefaultIfEmpty() { Observable<Integer> source = Observable.from(1, 2, 3); Observable<Integer> observable = Observable.create(defaultIfEmpty( source, 10)); @SuppressWarnings("unchecked") Observer<Integer> observer = mock(Observer.class); observable.subscribe(observer); verify(observer, never()).onNext(10); verify(observer, times(1)).onNext(1); verify(observer, times(1)).onNext(2); verify(observer, times(1)).onNext(3); verify(observer, never()).onError( org.mockito.Matchers.any(Throwable.class)); verify(observer, times(1)).onCompleted(); }
@Test public void testDefaultIfEmptyWithEmpty() { Observable<Integer> source = Observable.empty(); Observable<Integer> observable = Observable.create(defaultIfEmpty( source, 10)); @SuppressWarnings("unchecked") Observer<Integer> observer = mock(Observer.class); observable.subscribe(observer); verify(observer, times(1)).onNext(10); verify(observer, never()).onError( org.mockito.Matchers.any(Throwable.class)); verify(observer, times(1)).onCompleted(); }