use of android.annotation.TargetApi 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);
TestSubscriber<Boolean> sub = new TestSubscriber<>();
mRxPermissions.shouldShowRequestPermissionRationale(activity, new String[] { "p1", "p2" }).subscribe(sub);
sub.assertCompleted();
sub.assertNoErrors();
sub.assertReceivedOnNext(Collections.singletonList(false));
}
use of android.annotation.TargetApi in project RxPermissions by tbruyelle.
the class RxPermissionsTest method isRevoked_true.
@Test
@TargetApi(Build.VERSION_CODES.M)
public void isRevoked_true() {
// unmock isRevoked
doCallRealMethod().when(mRxPermissions).isRevoked(anyString());
doReturn(true).when(mRxPermissions).isMarshmallow();
PackageManager pm = mock(PackageManager.class);
when(mActivity.getPackageManager()).thenReturn(pm);
when(pm.isPermissionRevokedByPolicy(eq("p"), anyString())).thenReturn(true);
boolean revoked = mRxPermissions.isRevoked("p");
assertTrue(revoked);
}
use of android.annotation.TargetApi 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 android.annotation.TargetApi 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 android.annotation.TargetApi 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)));
}
Aggregations