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));
}
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));
}
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)));
}
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));
}
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)));
}
Aggregations