This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Test.java | |
public class Test { | |
public String foo() { | |
return null; | |
} | |
} | |
// Main.kt | |
fun main() { | |
print(Test().foo().toString()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void d_shouldLoadContactsIfPermissionWasGranted() throws Exception { | |
for (Contact contact : TEST_CONTACTS) { | |
onView(withText(contact.name)).check(matches(isDisplayed())); | |
onView(withText(contact.phoneNumber)).check(matches(isDisplayed())); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void onGrantPermission(View view) { | |
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_CONTACTS)) { | |
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CONTACTS}, | |
REQ_CODE_PERMISSIONS_READ_CONTACTS); | |
} else { | |
goToSettings(); | |
} | |
} | |
private void goToSettings() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_CONTACTS)) { | |
permissionDeniedRationaleView.setText(R.string.permission_denied_rationale_short); | |
} else { | |
permissionDeniedRationaleView.setText(R.string.permission_denied_rationale_long); | |
} | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void grantPermission(UiDevice device, String permissionTitle) throws UiObjectNotFoundException { | |
UiObject permissionEntry = device.findObject(new UiSelector().text(permissionTitle)); | |
permissionEntry.click(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void openPermissions(UiDevice device) throws UiObjectNotFoundException { | |
UiObject permissions = device.findObject(new UiSelector().text(TEXT_PERMISSIONS)); | |
permissions.click(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void denyCurrentPermissionPermanently(UiDevice device) throws UiObjectNotFoundException { | |
UiObject neverAskAgainCheckbox = device.findObject(new UiSelector().text(TEXT_NEVER_ASK_AGAIN)); | |
neverAskAgainCheckbox.click(); | |
denyCurrentPermission(device); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void c_shouldDisplayLongRationaleIfPermissionWasDeniedPermanently() throws Exception { | |
denyCurrentPermissionPermanently(device); | |
onView(withText(R.string.permission_denied_rationale_long)).check(matches(isDisplayed())); | |
onView(withText(R.string.grant_permission)).check(matches(isDisplayed())); | |
// will grant the permission for the next test | |
onView(withText(R.string.grant_permission)).perform(click()); | |
openPermissions(device); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, | |
@NonNull int[] grantResults) { | |
if (requestCode == REQ_CODE_PERMISSIONS_READ_CONTACTS && grantResults.length > 0) { | |
int grantResult = grantResults[0]; | |
if (grantResult == PackageManager.PERMISSION_GRANTED) { | |
loadContacts(); | |
} else { | |
isPermissionAlreadyDenied = true; | |
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_CONTACTS)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void b_shouldDisplayShortRationaleIfPermissionWasDenied() throws Exception { | |
denyCurrentPermission(device); | |
onView(withText(R.string.permission_denied_rationale_short)).check(matches(isDisplayed())); | |
onView(withText(R.string.grant_permission)).check(matches(isDisplayed())); | |
} |
NewerOlder