-
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
0ad0a69
commit c8d44fb
Showing
2 changed files
with
67 additions
and
17 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
56 changes: 56 additions & 0 deletions
56
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,56 @@ | ||
package io.ona.kujaku.helpers; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
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 com.karumi.dexter.MultiplePermissionsReport; | ||
import io.ona.kujaku.utils.KujakuMultiplePermissionListener; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
public class PermissionsHelperTest { | ||
|
||
@Mock | ||
Context mockContext; | ||
|
||
@Before | ||
public void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
// Use a real context | ||
mockContext = Robolectric.setupActivity(Activity.class).getApplicationContext(); | ||
} | ||
|
||
@Test | ||
public void testOnPermissionsCheckedWhenAnyPermissionPermanentlyDenied() { | ||
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(); | ||
} | ||
|
||
@Test | ||
public void testOnPermissionsCheckedWhenAnyPermissionNotPermanentlyDenied() { | ||
MultiplePermissionsReport report = Mockito.mock(MultiplePermissionsReport.class); | ||
Mockito.when(report.isAnyPermissionPermanentlyDenied()).thenReturn(false); | ||
Mockito.when(report.areAllPermissionsGranted()).thenReturn(false); | ||
KujakuMultiplePermissionListener listener = new KujakuMultiplePermissionListener(mockContext); | ||
listener.onPermissionsChecked(report); | ||
|
||
boolean result = report.isAnyPermissionPermanentlyDenied(); | ||
|
||
// Use the result in your assertions or further logic | ||
assertFalse(result); | ||
} | ||
} |