Search in sources :

Example 31 with TestObserver

use of io.reactivex.observers.TestObserver in project RxPermissions by tbruyelle.

the class RxPermissionsTest method eachSubscriptionCombined_denied.

@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscriptionCombined_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.ensureEachCombined(permission)).subscribe(sub);
    mRxPermissions.onRequestPermissionsResult(new String[] { permission }, result);
    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValue(new Permission(permission, false));
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 32 with TestObserver

use of io.reactivex.observers.TestObserver in project RxPermissions by tbruyelle.

the class RxPermissionsTest method subscription_alreadyGranted.

@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);
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 33 with TestObserver

use of io.reactivex.observers.TestObserver in project RxPermissions by tbruyelle.

the class RxPermissionsTest method shouldShowRequestPermissionRationale_allDenied_noRationale.

@Test
@TargetApi(Build.VERSION_CODES.M)
public void shouldShowRequestPermissionRationale_allDenied_noRationale() {
    when(mRxPermissions.isMarshmallow()).thenReturn(true);
    Activity activity = mock(Activity.class);
    TestObserver<Boolean> sub = new TestObserver<>();
    mRxPermissions.shouldShowRequestPermissionRationale(activity, new String[] { "p1", "p2" }).subscribe(sub);
    sub.assertComplete();
    sub.assertNoErrors();
    sub.assertValue(false);
}
Also used : Activity(android.app.Activity) Matchers.anyString(org.mockito.Matchers.anyString) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 34 with TestObserver

use of io.reactivex.observers.TestObserver in project RxPermissions by tbruyelle.

the class RxPermissionsTest method eachSubscription_denied.

@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));
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 35 with TestObserver

use of io.reactivex.observers.TestObserver in project RxPermissions by tbruyelle.

the class RxPermissionsTest method eachSubscriptionCombined_revoked.

@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));
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Aggregations

TestObserver (io.reactivex.observers.TestObserver)158 Test (org.junit.Test)128 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)31 TargetApi (android.annotation.TargetApi)21 Matchers.anyString (org.mockito.Matchers.anyString)21 StorIOException (com.pushtorefresh.storio3.StorIOException)19 TestException (io.reactivex.exceptions.TestException)19 Observable (io.reactivex.Observable)12 BaseTest (io.rx_cache2.internal.common.BaseTest)12 Completable (io.reactivex.Completable)11 Disposable (io.reactivex.disposables.Disposable)11 InOrder (org.mockito.InOrder)10 TestScheduler (io.reactivex.schedulers.TestScheduler)9 StorIOSQLite (com.pushtorefresh.storio3.sqlite.StorIOSQLite)8 EpisodeHeroNameQuery (com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery)7 Schedulers (io.reactivex.schedulers.Schedulers)6 Activity (android.app.Activity)5 Instrumentation (android.app.Instrumentation)5 ContentValues (android.content.ContentValues)5 Context (android.content.Context)5