Search in sources :

Example 96 with TestSubscriber

use of rx.observers.TestSubscriber in project RxPermissions by tbruyelle.

the class RxPermissionsTest method subscription_denied.

@Test
@TargetApi(Build.VERSION_CODES.M)
public void subscription_denied() {
    TestSubscriber<Boolean> sub = new TestSubscriber<>();
    String permission = Manifest.permission.READ_PHONE_STATE;
    when(mRxPermissions.isGranted(permission)).thenReturn(false);
    int[] result = new int[] { PackageManager.PERMISSION_DENIED };
    trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub);
    mRxPermissions.onRequestPermissionsResult(new String[] { permission }, result);
    sub.assertNoErrors();
    sub.assertTerminalEvent();
    sub.assertUnsubscribed();
    sub.assertReceivedOnNext(singletonList(false));
}
Also used : TestSubscriber(rx.observers.TestSubscriber) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 97 with TestSubscriber

use of rx.observers.TestSubscriber in project RxPermissions by tbruyelle.

the class RxPermissionsTest method subscription_revoked.

@Test
@TargetApi(Build.VERSION_CODES.M)
public void subscription_revoked() {
    TestSubscriber<Boolean> sub = new TestSubscriber<>();
    String permission = Manifest.permission.READ_PHONE_STATE;
    when(mRxPermissions.isRevoked(permission)).thenReturn(true);
    trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub);
    sub.assertNoErrors();
    sub.assertTerminalEvent();
    sub.assertUnsubscribed();
    sub.assertReceivedOnNext(singletonList(false));
}
Also used : TestSubscriber(rx.observers.TestSubscriber) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 98 with TestSubscriber

use of rx.observers.TestSubscriber in project RxPermissions by tbruyelle.

the class RxPermissionsTest method eachSubscription_trigger_granted.

@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscription_trigger_granted() {
    TestSubscriber<Permission> sub = new TestSubscriber<>();
    String permission = Manifest.permission.READ_PHONE_STATE;
    when(mRxPermissions.isGranted(permission)).thenReturn(false);
    int[] result = new int[] { PackageManager.PERMISSION_GRANTED };
    PublishSubject<Object> trigger = PublishSubject.create();
    trigger.compose(mRxPermissions.ensureEach(permission)).subscribe(sub);
    trigger.onNext(null);
    mRxPermissions.onRequestPermissionsResult(new String[] { permission }, result);
    sub.assertNoErrors();
    sub.assertNoTerminalEvent();
    sub.assertReceivedOnNext(singletonList(new Permission(permission, true)));
}
Also used : TestSubscriber(rx.observers.TestSubscriber) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 99 with TestSubscriber

use of rx.observers.TestSubscriber in project RxPermissions by tbruyelle.

the class RxPermissionsTest method subscription_preM.

@Test
@TargetApi(Build.VERSION_CODES.M)
public void subscription_preM() {
    TestSubscriber<Boolean> sub = new TestSubscriber<>();
    String permission = Manifest.permission.READ_PHONE_STATE;
    when(mRxPermissions.isGranted(permission)).thenReturn(true);
    trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub);
    sub.assertNoErrors();
    sub.assertTerminalEvent();
    sub.assertUnsubscribed();
    sub.assertReceivedOnNext(singletonList(true));
}
Also used : TestSubscriber(rx.observers.TestSubscriber) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 100 with TestSubscriber

use of rx.observers.TestSubscriber in project RxPermissions by tbruyelle.

the class RxPermissionsTest method eachSubscription_preM.

@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscription_preM() {
    TestSubscriber<Permission> sub = new TestSubscriber<>();
    String permission = Manifest.permission.READ_PHONE_STATE;
    when(mRxPermissions.isGranted(permission)).thenReturn(true);
    trigger().compose(mRxPermissions.ensureEach(permission)).subscribe(sub);
    sub.assertNoErrors();
    sub.assertTerminalEvent();
    sub.assertUnsubscribed();
    sub.assertReceivedOnNext(singletonList(new Permission(permission, true)));
}
Also used : TestSubscriber(rx.observers.TestSubscriber) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Aggregations

TestSubscriber (rx.observers.TestSubscriber)238 Test (org.junit.Test)213 Intent (android.content.Intent)48 Environment (com.kickstarter.libs.Environment)43 Cursor (android.database.Cursor)36 Changes (com.pushtorefresh.storio.contentresolver.Changes)34 Project (com.kickstarter.models.Project)33 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)21 MockApiClient (com.kickstarter.services.MockApiClient)21 ApiClientType (com.kickstarter.services.ApiClientType)20 TargetApi (android.annotation.TargetApi)18 CurrentUserType (com.kickstarter.libs.CurrentUserType)18 StorIOSQLite (com.pushtorefresh.storio.sqlite.StorIOSQLite)18 StorIOException (com.pushtorefresh.storio.StorIOException)17 TestCollapserTimer (com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer)16 Matchers.anyString (org.mockito.Matchers.anyString)16 User (com.kickstarter.models.User)15 PutResult (com.pushtorefresh.storio.contentresolver.operations.put.PutResult)15 Uri (android.net.Uri)14 NonNull (android.support.annotation.NonNull)14