-
Notifications
You must be signed in to change notification settings - Fork 589
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added granted permissions cache in CheckerPermission. (#802)
- Loading branch information
1 parent
2af6539
commit ef2db2d
Showing
3 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
47 changes: 47 additions & 0 deletions
47
...dble/src/test/groovy/com/polidea/rxandroidble2/internal/util/CheckerPermissionTest.groovy
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.polidea.rxandroidble2.internal.util | ||
|
||
import android.content.Context | ||
import android.content.pm.PackageManager | ||
import spock.lang.Specification | ||
|
||
class CheckerPermissionTest extends Specification { | ||
|
||
String testPermissionString = "random.package.RANDOM_PERMISSION" | ||
def testPermissionArray = new String[] { testPermissionString } | ||
def mockContext = Mock Context | ||
CheckerPermission objectUnderTest | ||
|
||
def "should cache granted permissions"() { | ||
|
||
given: | ||
objectUnderTest = new CheckerPermission(mockContext) | ||
|
||
when: | ||
def result0 = objectUnderTest.isAnyPermissionGranted(testPermissionArray) | ||
def result1 = objectUnderTest.isAnyPermissionGranted(testPermissionArray) | ||
|
||
then: | ||
1 * mockContext.checkPermission(testPermissionString, _, _) >> PackageManager.PERMISSION_GRANTED | ||
|
||
and: | ||
result0 | ||
result1 | ||
} | ||
|
||
def "should call context each time if permission is not granted"() { | ||
|
||
given: | ||
objectUnderTest = new CheckerPermission(mockContext) | ||
|
||
when: | ||
def result0 = objectUnderTest.isAnyPermissionGranted(testPermissionArray) | ||
def result1 = objectUnderTest.isAnyPermissionGranted(testPermissionArray) | ||
|
||
then: | ||
2 * mockContext.checkPermission(testPermissionString, _, _) >> PackageManager.PERMISSION_DENIED | ||
|
||
and: | ||
!result0 | ||
!result1 | ||
} | ||
} |
This file contains 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