Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Add test for #87
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Gutierrez committed Sep 5, 2016
1 parent a2811ab commit 2fa3692
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions dexter/src/test/java/com/karumi/dexter/DexterInstanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ public void onCheckPermissionMoreThanOnceThenThrowException() {
thenPermissionRationaleIsShown(2);
}

@Test public void onPermissionFailedByRuntimeExceptionThenNotifiesListener() {
givenARuntimeExceptionIsThrownWhenPermissionIsChecked(ANY_PERMISSION);
givenShouldShowRationaleForPermission(ANY_PERMISSION);

whenCheckPermission(permissionListener, ANY_PERMISSION);
dexter.onPermissionRequestDenied(Collections.singletonList(ANY_PERMISSION));

thenPermissionIsDenied(ANY_PERMISSION);
}

private void givenPermissionIsAlreadyDenied(String permission) {
givenPermissionIsChecked(permission, PackageManager.PERMISSION_DENIED);
}
Expand Down Expand Up @@ -165,6 +175,11 @@ private PermissionListener givenARetryCheckPermissionOnDeniedPermissionListener(
new CheckPermissionWithOnActivityReadyInBackground());
}

private void givenARuntimeExceptionIsThrownWhenPermissionIsChecked(String permission) {
when(androidPermissionService.checkSelfPermission(activity, permission)).thenThrow(
new RuntimeException());
}

private void whenCheckPermission(PermissionListener permissionListener, String permission) {
dexter.checkPermission(permissionListener, permission, THREAD);
dexter.onActivityReady(activity);
Expand Down

0 comments on commit 2fa3692

Please sign in to comment.