@RunWith(PowerMockRunner::class) @PowerMockRunnerDelegate(JUnitPlatform::class) class UIExtUnitTest : Spek({ describe("When using UI Ext") { val context = mock(Context::class.java) given("You are retrieving the Settings Intent") { val packageName = "TEST_PACKAGE" val intentFlags = Intent().apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY) addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) } beforeEach { `when`(context.packageName).thenReturn(packageName) } it("The flags should be set to newTask, noHistory, excludeFromRecents") { val intent = context.getAppSettingsIntent() assertEquals(intent.flags, intentFlags.flags) } it("The correct action should be set") { val intent = context.getAppSettingsIntent() assertEquals(intent.action, Settings.ACTION_APPLICATION_DETAILS_SETTINGS) } it("The uri should be set to package:packageName") { val intent = context.getAppSettingsIntent() assertEquals(intent.data, Uri.parse("package:" + packageName)) } it("The category should be set to default") { val intent = context.getAppSettingsIntent() assertTrue(intent.categories.contains(Intent.CATEGORY_DEFAULT)) } } given("You're checking if a single permission is granted"){ it("Should result in false if not granted"){ val grantResult = intArrayOf(PackageManager.PERMISSION_DENIED) assertFalse(permissionGranted(grantResult)) } it("Should result in true if not granted"){ val grantResult = intArrayOf(PackageManager.PERMISSION_GRANTED) assertTrue(permissionGranted(grantResult)) } } } })