Skip to content

Commit

Permalink
Add tests for permissions helper.
Browse files Browse the repository at this point in the history
Signed-off-by: Lentumunai-Mark <[email protected]>
  • Loading branch information
Lentumunai-Mark committed Oct 14, 2024
1 parent 2a45083 commit d234a00
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ dependencies { configuration ->

implementation 'androidx.multidex:multidex:2.0.1'

androidTestImplementation 'org.powermock:powermock-module-junit4:2.0.9'
androidTestImplementation 'org.powermock:powermock-api-mockito2:2.0.9'
androidTestImplementation 'org.mockito:mockito-core:5.12.0'
androidTestImplementation 'org.robolectric:robolectric:4.13'

customDependencies(this, configuration)
appPermissionsDependencies(configuration)
infoWindowDependencies(this, configuration)
Expand Down
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

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

library/src/test/java/io/ona/kujaku/helpers/PermissionsHelperTest.java#L36

The JUnit 4 test method name 'testOnPermissionsChecked_WhenAnyPermissionPermanentlyDenied' doesn't match '[a-z][a-zA-Z0-9]*'
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();
}
}

0 comments on commit d234a00

Please sign in to comment.