Skip to content

Commit

Permalink
Adjust test stubs to match previous behavior
Browse files Browse the repository at this point in the history
Previously `anyOrNull()` matcher was used, which covered stubbing the method for all ints. Now it stubs only the method for only the specified `requestCode` which results into method not stubbed when `requestPermissions` is called from `CoperFragment#requestPermissionsAsync`.
  • Loading branch information
kyrillosgait committed Sep 29, 2023
1 parent 3018f14 commit dd7e4c5
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions library/src/test/java/com/vinted/coper/CoperImplTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -744,11 +744,35 @@ class CoperImplTest {
fun request_requestCodeIsNotOfCoperFragment_throwException() = runTest {
val requestedPermission = "requested_permission"

executePermissionRequest(
permissionsToRequest = listOf(requestedPermission),
permissionResult = listOf(PermissionChecker.PERMISSION_DENIED),
requestCode = 0
)
val coperFragment = fixture.getFragmentSafely()

whenever(
coperFragment.requestPermissions(
listOf(requestedPermission).toTypedArray(),
0,
)
).then {
coperFragment.onRequestPermissionResult(
permissions = listOf(requestedPermission),
permissionsResult = listOf(PermissionChecker.PERMISSION_DENIED),
requestCode = 0,
)
}

whenever(
coperFragment.requestPermissions(
listOf(requestedPermission).toTypedArray(),
CoperFragment.REQUEST_CODE
)
).then {
coperFragment.onRequestPermissionResult(
permissions = listOf(requestedPermission),
permissionsResult = listOf(PermissionChecker.PERMISSION_DENIED),
requestCode = 0,
)
}

fixture.request(*listOf(requestedPermission).toTypedArray())
}

private suspend fun executePermissionRequest(
Expand Down

0 comments on commit dd7e4c5

Please sign in to comment.