Java Code Examples for io.reactivex.observers.TestObserver#assertTerminated()

The following examples show how to use io.reactivex.observers.TestObserver#assertTerminated() . 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: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 6 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscriptionCombined_severalPermissions_oneRevoked() {
    TestObserver<Permission> sub = new TestObserver<>();
    String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};
    when(mRxPermissions.isGranted(Matchers.<String>anyVararg())).thenReturn(false);
    when(mRxPermissions.isRevoked(Manifest.permission.CAMERA)).thenReturn(true);

    trigger().compose(mRxPermissions.ensureEachCombined(permissions)).subscribe(sub);
    mRxPermissions.onRequestPermissionsResult(
            new String[]{Manifest.permission.READ_PHONE_STATE},
            new int[]{PackageManager.PERMISSION_GRANTED});

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValues(new Permission(permissions[0] + ", " + permissions[1], false));
}
 
Example 2
Source File: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 6 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void subscription_severalPermissions_oneRevoked() {
    TestObserver<Boolean> sub = new TestObserver<>();
    String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};
    when(mRxPermissions.isGranted(Matchers.<String>anyVararg())).thenReturn(false);
    when(mRxPermissions.isRevoked(Manifest.permission.CAMERA)).thenReturn(true);

    trigger().compose(mRxPermissions.ensure(permissions)).subscribe(sub);
    mRxPermissions.onRequestPermissionsResult(
            new String[]{Manifest.permission.READ_PHONE_STATE},
            new int[]{PackageManager.PERMISSION_GRANTED});

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValue(false);
}
 
Example 3
Source File: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 6 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscriptionCombined_severalPermissions_oneAlreadyGranted() {
    TestObserver<Permission> sub = new TestObserver<>();
    String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};
    when(mRxPermissions.isGranted(Matchers.<String>anyVararg())).thenReturn(false);
    when(mRxPermissions.isGranted(Manifest.permission.CAMERA)).thenReturn(true);

    trigger().compose(mRxPermissions.ensureEachCombined(permissions)).subscribe(sub);
    mRxPermissions.onRequestPermissionsResult(
            new String[]{Manifest.permission.READ_PHONE_STATE},
            new int[]{PackageManager.PERMISSION_GRANTED});

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValues(new Permission(permissions[0] + ", " + permissions[1], true));
    ArgumentCaptor<String[]> requestedPermissions = ArgumentCaptor.forClass(String[].class);
    verify(mRxPermissions).requestPermissionsFromFragment(requestedPermissions.capture());
    assertEquals(1, requestedPermissions.getValue().length);
    assertEquals(Manifest.permission.READ_PHONE_STATE, requestedPermissions.getValue()[0]);
}
 
Example 4
Source File: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 6 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscription_severalPermissions_oneAlreadyGranted() {
    TestObserver<Permission> sub = new TestObserver<>();
    String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};
    when(mRxPermissions.isGranted(Matchers.<String>anyVararg())).thenReturn(false);
    when(mRxPermissions.isGranted(Manifest.permission.CAMERA)).thenReturn(true);

    trigger().compose(mRxPermissions.ensureEach(permissions)).subscribe(sub);
    mRxPermissions.onRequestPermissionsResult(
            new String[]{Manifest.permission.READ_PHONE_STATE},
            new int[]{PackageManager.PERMISSION_GRANTED});

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValues(new Permission(permissions[0], true), new Permission(permissions[1], true));
    ArgumentCaptor<String[]> requestedPermissions = ArgumentCaptor.forClass(String[].class);
    verify(mRxPermissions).requestPermissionsFromFragment(requestedPermissions.capture());
    assertEquals(1, requestedPermissions.getValue().length);
    assertEquals(Manifest.permission.READ_PHONE_STATE, requestedPermissions.getValue()[0]);
}
 
Example 5
Source File: ObservableGroupTest.java    From RxGroups with Apache License 2.0 6 votes vote down vote up
@Test public void shouldAutoResubscribeAfterLockAndUnlock() {
  ObservableGroup group = observableManager.newGroup();
  TestObserver<String> testObserver = new TestObserver<>();
  PublishSubject<String> sourceObservable = PublishSubject.create();

  sourceObservable.compose(group.transform(testObserver)).subscribe(testObserver);
  group.lock();

  sourceObservable.onNext("Chespirito");
  sourceObservable.onComplete();

  group.unlock();

  testObserver.assertTerminated();
  testObserver.assertNoErrors();
  testObserver.assertValue("Chespirito");
  assertThat(group.hasObservables(fooObserver)).isEqualTo(false);
}
 
Example 6
Source File: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 5 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void subscription_preM() {
    TestObserver<Boolean> sub = new TestObserver<>();
    String permission = Manifest.permission.READ_PHONE_STATE;
    when(mRxPermissions.isGranted(permission)).thenReturn(true);

    trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub);

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValue(true);
}
 
Example 7
Source File: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 5 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void subscription_granted() {
    TestObserver<Boolean> sub = new TestObserver<>();
    String permission = Manifest.permission.READ_PHONE_STATE;
    when(mRxPermissions.isGranted(permission)).thenReturn(false);
    int[] result = new int[]{PackageManager.PERMISSION_GRANTED};

    trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub);
    mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result);

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValue(true);
}
 
Example 8
Source File: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 5 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscription_granted() {
    TestObserver<Permission> sub = new TestObserver<>();
    String permission = Manifest.permission.READ_PHONE_STATE;
    when(mRxPermissions.isGranted(permission)).thenReturn(false);
    int[] result = new int[]{PackageManager.PERMISSION_GRANTED};

    trigger().compose(mRxPermissions.ensureEach(permission)).subscribe(sub);
    mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result);

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValue(new Permission(permission, true));
}
 
Example 9
Source File: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 5 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscription_severalPermissions_oneDenied() {
    TestObserver<Permission> sub = new TestObserver<>();
    String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};
    when(mRxPermissions.isGranted(Matchers.<String>anyVararg())).thenReturn(false);
    int[] result = new int[]{PackageManager.PERMISSION_GRANTED, PackageManager.PERMISSION_DENIED};

    trigger().compose(mRxPermissions.ensureEach(permissions)).subscribe(sub);
    mRxPermissions.onRequestPermissionsResult(permissions, result);

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValues(new Permission(permissions[0], true), new Permission(permissions[1], false));
}
 
Example 10
Source File: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 5 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscription_preM() {
    TestObserver<Permission> sub = new TestObserver<>();
    String permission = Manifest.permission.READ_PHONE_STATE;
    when(mRxPermissions.isGranted(permission)).thenReturn(true);

    trigger().compose(mRxPermissions.ensureEach(permission)).subscribe(sub);

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValue(new Permission(permission, true));
}
 
Example 11
Source File: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 5 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscriptionCombined_preM() {
    TestObserver<Permission> sub = new TestObserver<>();
    String permission = Manifest.permission.READ_PHONE_STATE;
    when(mRxPermissions.isGranted(permission)).thenReturn(true);

    trigger().compose(mRxPermissions.ensureEachCombined(permission)).subscribe(sub);

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValue(new Permission(permission, true));
}
 
Example 12
Source File: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 5 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void subscription_alreadyGranted() {
    TestObserver<Boolean> sub = new TestObserver<>();
    String permission = Manifest.permission.READ_PHONE_STATE;
    when(mRxPermissions.isGranted(permission)).thenReturn(true);

    trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub);

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValue(true);
}
 
Example 13
Source File: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 5 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void subscription_severalPermissions_oneDenied() {
    TestObserver<Boolean> sub = new TestObserver<>();
    String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};
    when(mRxPermissions.isGranted(Matchers.<String>anyVararg())).thenReturn(false);
    int[] result = new int[]{PackageManager.PERMISSION_GRANTED, PackageManager.PERMISSION_DENIED};

    trigger().compose(mRxPermissions.ensure(permissions)).subscribe(sub);
    mRxPermissions.onRequestPermissionsResult(permissions, result);

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValue(false);
}
 
Example 14
Source File: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 5 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscription_denied() {
    TestObserver<Permission> sub = new TestObserver<>();
    String permission = Manifest.permission.READ_PHONE_STATE;
    when(mRxPermissions.isGranted(permission)).thenReturn(false);
    int[] result = new int[]{PackageManager.PERMISSION_DENIED};

    trigger().compose(mRxPermissions.ensureEach(permission)).subscribe(sub);
    mRxPermissions.onRequestPermissionsResult(new String[]{permission}, result);

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValue(new Permission(permission, false));
}
 
Example 15
Source File: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 5 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void subscription_revoked() {
    TestObserver<Boolean> sub = new TestObserver<>();
    String permission = Manifest.permission.READ_PHONE_STATE;
    when(mRxPermissions.isRevoked(permission)).thenReturn(true);

    trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub);

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValue(false);
}
 
Example 16
Source File: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 5 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscription_revoked() {
    TestObserver<Permission> sub = new TestObserver<>();
    String permission = Manifest.permission.READ_PHONE_STATE;
    when(mRxPermissions.isRevoked(permission)).thenReturn(true);

    trigger().compose(mRxPermissions.ensureEach(permission)).subscribe(sub);

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValue(new Permission(permission, false));
}
 
Example 17
Source File: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 5 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscriptionCombined_revoked() {
    TestObserver<Permission> sub = new TestObserver<>();
    String permission = Manifest.permission.READ_PHONE_STATE;
    when(mRxPermissions.isRevoked(permission)).thenReturn(true);

    trigger().compose(mRxPermissions.ensureEachCombined(permission)).subscribe(sub);

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValue(new Permission(permission, false));
}
 
Example 18
Source File: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 5 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscriptionCombined_severalPermissions_oneDenied() {
    TestObserver<Permission> sub = new TestObserver<>();
    String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};
    when(mRxPermissions.isGranted(Matchers.<String>anyVararg())).thenReturn(false);
    int[] result = new int[]{PackageManager.PERMISSION_GRANTED, PackageManager.PERMISSION_DENIED};

    trigger().compose(mRxPermissions.ensureEachCombined(permissions)).subscribe(sub);
    mRxPermissions.onRequestPermissionsResult(permissions, result);

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValues(new Permission(permissions[0] + ", " + permissions[1], false));
}
 
Example 19
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 20
Source File: CancellationPropagationIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void serverCanCancelClientStreamImplicitly() {
    TestService svc = new TestService();
    serverRule.getServiceRegistry().addService(svc);

    RxNumbersGrpc.RxNumbersStub stub = RxNumbersGrpc.newRxStub(serverRule.getChannel());

    svc.setExplicitCancel(false);

    AtomicBoolean requestWasCanceled = new AtomicBoolean(false);
    AtomicBoolean requestDidProduce = new AtomicBoolean(false);

    Flowable<NumberProto.Number> request = Flowable
            .fromIterable(IntStream.range(0, NUMBER_OF_STREAM_ELEMENTS)::iterator)
            .delay(10, TimeUnit.MILLISECONDS)
            .map(CancellationPropagationIntegrationTest::protoNum)
            .doOnNext(x -> {
                requestDidProduce.set(true);
                System.out.println("Produced: " + x.getNumber(0));
            })
            .doOnCancel(() -> {
                requestWasCanceled.set(true);
                System.out.println("Client canceled");
            });

    TestObserver<NumberProto.Number> observer = request
            .as(stub::requestPressure)
            .doOnSuccess(number -> System.out.println(number.getNumber(0)))
            .doOnError(throwable -> System.out.println(throwable.getMessage()))
            .test();

    observer.awaitTerminalEvent(3, TimeUnit.SECONDS);
    observer.assertComplete();
    observer.assertTerminated();

    await().atMost(Duration.FIVE_HUNDRED_MILLISECONDS).untilTrue(requestWasCanceled);

    assertThat(requestWasCanceled.get()).isTrue();
    assertThat(requestDidProduce.get()).isTrue();

    errorRule.verifyNoError();
}