Skip to content

Commit

Permalink
Merge pull request #242 from googlesamples/grantPermissionRule
Browse files Browse the repository at this point in the history
Use GrantPermissionRule in IntentsBasicSample.
  • Loading branch information
brettchabot authored Jan 22, 2019
2 parents 383bcbe + 01c20d3 commit 8b41c0a
Showing 1 changed file with 3 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import androidx.test.rule.ActivityTestRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import androidx.test.rule.GrantPermissionRule;
import com.google.common.collect.Iterables;

import org.junit.Before;
Expand All @@ -74,6 +75,8 @@ public class DialerActivityTest {
}
}

@Rule public GrantPermissionRule grantPermissionRule = GrantPermissionRule.grant("android.permission.CALL_PHONE");

/**
* A JUnit {@link Rule @Rule} to init and release Espresso Intents before and after each
* test run.
Expand All @@ -95,17 +98,6 @@ public void stubAllExternalIntents() {
intending(not(isInternal())).respondWith(new ActivityResult(Activity.RESULT_OK, null));
}

@Before
public void grantPhonePermission() {
// In M+, trying to call a number will trigger a runtime dialog. Make sure
// the permission is granted before running this test.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
getInstrumentation().getUiAutomation().executeShellCommand(
"pm grant " + getApplicationContext().getPackageName()
+ " android.permission.CALL_PHONE");
}
}

@Test
public void typeNumber_ValidInput_InitiatesCall() {
// Types a phone number into the dialer edit text field and presses the call button.
Expand Down

0 comments on commit 8b41c0a

Please sign in to comment.