Java Code Examples for io.reactivex.Observable#never()

The following examples show how to use io.reactivex.Observable#never() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObservableGroupTest.java    From RxGroups with Apache License 2.0 6 votes vote down vote up
@Test public void shouldSeparateObservablesByGroupId() {
  ObservableGroup group = observableManager.newGroup();
  ObservableGroup group2 = observableManager.newGroup();
  Observable<String> observable1 = Observable.never();
  Observable<String> observable2 = Observable.never();

  observable1.compose(group.transform(barObserver)).subscribe(barObserver);
  assertThat(group.hasObservables(barObserver)).isEqualTo(true);
  assertThat(group.hasObservables(fooObserver)).isEqualTo(false);
  assertThat(group2.hasObservables(barObserver)).isEqualTo(false);
  assertThat(group2.hasObservables(fooObserver)).isEqualTo(false);

  observable2.compose(group2.transform(fooObserver)).subscribe(fooObserver);
  assertThat(group.hasObservables(barObserver)).isEqualTo(true);
  assertThat(group.hasObservables(fooObserver)).isEqualTo(false);
  assertThat(group2.hasObservables(barObserver)).isEqualTo(false);
  assertThat(group2.hasObservables(fooObserver)).isEqualTo(true);
}
 
Example 2
Source File: ObservableGroupTest.java    From RxGroups with Apache License 2.0 6 votes vote down vote up
@Test public void shouldClearObservablesByGroupId() {
  ObservableGroup group = observableManager.newGroup();
  ObservableGroup group2 = observableManager.newGroup();
  Observable<String> observable1 = Observable.never();
  Observable<String> observable2 = Observable.never();

  observable1.compose(group.transform(fooObserver)).subscribe(fooObserver);
  observable2.compose(group2.transform(fooObserver)).subscribe(fooObserver);

  observableManager.destroy(group);

  assertThat(group.hasObservables(fooObserver)).isEqualTo(false);
  assertThat(group2.hasObservables(fooObserver)).isEqualTo(true);
  assertThat(group.subscription(fooObserver)).isNull();
  assertThat(group2.subscription(fooObserver).isCancelled()).isEqualTo(false);

  observableManager.destroy(group2);
  assertThat(group.hasObservables(fooObserver)).isEqualTo(false);
  assertThat(group2.hasObservables(fooObserver)).isEqualTo(false);
  assertThat(group.subscription(fooObserver)).isNull();
  assertThat(group2.subscription(fooObserver)).isNull();
}
 
Example 3
Source File: ObservableGroupTest.java    From RxGroups with Apache License 2.0 6 votes vote down vote up
@Test public void shouldClearObservablesWhenLocked() {
  ObservableGroup group = observableManager.newGroup();
  Observable<String> observable1 = Observable.never();
  Observable<String> observable2 = Observable.never();
  TestObserver<String> subscriber1 = new TestObserver<>();
  TestObserver<String> subscriber2 = new TestObserver<>();

  observable1.compose(group.transform(subscriber1)).subscribe(subscriber1);
  observable2.compose(group.transform(subscriber2)).subscribe(subscriber2);

  group.dispose();
  observableManager.destroy(group);

  assertThat(group.hasObservables(fooObserver)).isEqualTo(false);
  assertThat(group.hasObservables(barObserver)).isEqualTo(false);
}
 
Example 4
Source File: Modern_Testing.java    From Reactive-Programming-With-Java-9 with MIT License 5 votes vote down vote up
@Test
public void test_never() {
	Observable<String> observable = Observable.never();
	TestObserver<String> testObserver = new TestObserver<>();
	observable.subscribe(testObserver);

	testObserver.assertNoValues();
	testObserver.assertTerminated();
	// testObserver.assertComplete();
}
 
Example 5
Source File: ObservableGroupTest.java    From RxGroups with Apache License 2.0 5 votes vote down vote up
@Test public void shouldAddRequestByObserverTag() {
  ObservableGroup group = observableManager.newGroup();
  ObservableGroup group2 = observableManager.newGroup();
  Observable<String> sourceObservable = Observable.never();
  sourceObservable.compose(group.transform(fooObserver)).subscribe(fooObserver);

  assertThat(group.hasObservables(fooObserver)).isEqualTo(true);
  assertThat(group2.hasObservables(fooObserver)).isEqualTo(false);
  assertThat(group.hasObservables(barObserver)).isEqualTo(false);
}
 
Example 6
Source File: ObservableGroupTest.java    From RxGroups with Apache License 2.0 5 votes vote down vote up
@Test public void shouldNotBeCompleted() {
  ObservableGroup group = observableManager.newGroup();
  TestObserver<Object> subscriber = new TestObserver<>();
  Observable<String> sourceObservable = Observable.never();

  sourceObservable.compose(group.transform(fooObserver)).subscribe(fooObserver);
  subscriber.assertNotComplete();
}
 
Example 7
Source File: ObservableGroupTest.java    From RxGroups with Apache License 2.0 5 votes vote down vote up
@Test public void shouldBeSubscribed() {
  ObservableGroup group = observableManager.newGroup();
  Observable<String> sourceObservable = Observable.never();
  sourceObservable.compose(group.transform(fooObserver)).subscribe(fooObserver);

  assertThat(group.subscription(fooObserver).isCancelled()).isEqualTo(false);
}
 
Example 8
Source File: BackendAConnector.java    From resilience4j-spring-boot-demo with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<String> methodWhichReturnsAStream() {
    return Observable.never();
}
 
Example 9
Source File: BackendBConnector.java    From resilience4j-spring-boot-demo with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<String> methodWhichReturnsAStream() {
    return Observable.never();
}
 
Example 10
Source File: DemoObservable_never.java    From Reactive-Programming-With-Java-9 with MIT License 4 votes vote down vote up
public static void main(String[] args) {
	// TODO Auto-generated method stub
	Observable<String> observable=Observable.never();
	observable.subscribe(item-> System.out.println("we got"+item));
}
 
Example 11
Source File: Presenter.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
private static Observable<PresenterEvent> setupNotificationAndIndicationBehaviour(RxBleConnection connection,
                                                                                  BluetoothGattCharacteristic characteristic,
                                                                                  Observable<Boolean> enableNotifyClicks,
                                                                                  Observable<Boolean> enablingNotifyClicks,
                                                                                  Observable<Boolean> disableNotifyClicks,
                                                                                  Observable<Boolean> enableIndicateClicks,
                                                                                  Observable<Boolean> enablingIndicateClicks,
                                                                                  Observable<Boolean> disableIndicateClicks) {
    // checking if characteristic will potentially need a compatibility mode notifications
    final NotificationSetupMode notificationSetupMode =
            characteristic.getDescriptor(clientCharacteristicConfigDescriptorUuid) == null
                    ? NotificationSetupMode.COMPAT
                    : NotificationSetupMode.DEFAULT;
    /*
     * wrapping observables for notifications and indications so they will emit FALSE and TRUE respectively.
     * this is needed because only one of them may be active at the same time and we need to differentiate
     * the clicks
     */
    final Observable<Boolean> enableNotifyClicksObservable = !hasProperty(characteristic, PROPERTY_NOTIFY)
            /*
             * if property for notifications is not available return Observable.never() dummy observable.
             * Observable.never() is needed because of the Observable.amb() below which repeats
             * the behaviour of Observable that first emits or terminates and it will be checking both
             * notifyClicks and indicateClicks
             */
            ? Observable.never()
            // only the first click to enableNotifyClicks is taken to account
            : enableNotifyClicks.take(1).map(aBoolean -> Boolean.FALSE);
    final Observable<Boolean> enableIndicateClicksObservable =
            !hasProperty(characteristic, PROPERTY_INDICATE)
                    ? Observable.never()
                    : enableIndicateClicks.take(1).map(aBoolean -> Boolean.TRUE);

    // checking which notify or indicate will be clicked first the other is unsubscribed on click
    return Observable.amb(asList(
            enableNotifyClicksObservable,
            enableIndicateClicksObservable)
    )
            .flatMap(isIndication -> {
                if (isIndication) { // if indication was clicked
                    return connection
                            // we setup indications
                            .setupIndication(characteristic, notificationSetupMode)
                            // use a convenience transformer for tearing down the notifications
                            .compose(takeUntil(enablingIndicateClicks, disableIndicateClicks))
                            // and wrap the emissions with a convenience function
                            .compose(transformToNotificationPresenterEvent(Type.INDICATE));
                } else { // if notification was clicked
                    return connection
                            .setupNotification(characteristic, notificationSetupMode)
                            .compose(takeUntil(enablingNotifyClicks, disableNotifyClicks))
                            .compose(transformToNotificationPresenterEvent(Type.NOTIFY));
                }
            })
            /*
             * whenever the notification or indication is finished (by the user or an error) repeat from
             * the clicks on notify / indicate
             */
            .compose(repeatAfterCompleted())
            // at the beginning inform the activity about whether compat mode is being used
            .startWith(new CompatibilityModeEvent(
                    hasProperty(characteristic, PROPERTY_NOTIFY | PROPERTY_INDICATE)
                            && notificationSetupMode == NotificationSetupMode.COMPAT
            ));
}
 
Example 12
Source File: RxBleConnectionMock.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<ConnectionParameters> observeConnectionParametersUpdates() {
    return Observable.never();
}