-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lentumunai-Mark <[email protected]>
- Loading branch information
1 parent
2a45083
commit d234a00
Showing
2 changed files
with
51 additions
and
0 deletions.
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
46 changes: 46 additions & 0 deletions
46
library/src/test/java/io/ona/kujaku/helpers/PermissionsHelperTest.java
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,46 @@ | ||
package io.ona.kujaku.helpers; | ||
|
||
import android.app.Activity; | ||
import android.app.AlertDialog; | ||
import android.content.Context; | ||
import android.content.DialogInterface; | ||
|
||
import com.karumi.dexter.MultiplePermissionsReport; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.MockitoAnnotations; | ||
import org.robolectric.Robolectric; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
|
||
import io.ona.kujaku.utils.KujakuMultiplePermissionListener; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
@Config(sdk = 28) | ||
public class PermissionsHelperTest { | ||
|
||
private Context mockContext; | ||
|
||
@Before | ||
public void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
// Use a real context | ||
mockContext = Robolectric.setupActivity(Activity.class).getApplicationContext(); | ||
} | ||
|
||
@Test | ||
public void testOnPermissionsChecked_WhenAnyPermissionPermanentlyDenied() { | ||
Check notice on line 36 in library/src/test/java/io/ona/kujaku/helpers/PermissionsHelperTest.java Codacy Production / Codacy Static Code Analysislibrary/src/test/java/io/ona/kujaku/helpers/PermissionsHelperTest.java#L36
|
||
MultiplePermissionsReport report = Mockito.mock(MultiplePermissionsReport.class); | ||
Mockito.when(report.isAnyPermissionPermanentlyDenied()).thenReturn(true); | ||
Mockito.when(report.areAllPermissionsGranted()).thenReturn(false); | ||
KujakuMultiplePermissionListener listener = new KujakuMultiplePermissionListener(mockContext); | ||
listener.onPermissionsChecked(report); | ||
|
||
// Check that the dialog was created with the expected properties | ||
Mockito.verify(report).isAnyPermissionPermanentlyDenied(); | ||
} | ||
} |