Search in sources :

Example 86 with TargetApi

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));
}
Also used : Activity(android.app.Activity) TestSubscriber(rx.observers.TestSubscriber) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 87 with TargetApi

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);
}
Also used : PackageManager(android.content.pm.PackageManager) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 88 with TargetApi

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

Example 89 with TargetApi

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

Example 90 with TargetApi

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

Aggregations

TargetApi (android.annotation.TargetApi)1365 Intent (android.content.Intent)153 View (android.view.View)147 Test (org.junit.Test)119 SuppressLint (android.annotation.SuppressLint)115 Uri (android.net.Uri)70 ArrayList (java.util.ArrayList)68 Animator (android.animation.Animator)67 Point (android.graphics.Point)64 Window (android.view.Window)56 TextView (android.widget.TextView)56 IOException (java.io.IOException)56 ViewGroup (android.view.ViewGroup)53 Matchers.anyString (org.mockito.Matchers.anyString)53 SharedPreferences (android.content.SharedPreferences)44 File (java.io.File)44 Field (java.lang.reflect.Field)44 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)43 Bitmap (android.graphics.Bitmap)42 ImageView (android.widget.ImageView)40