This repository has been archived by the owner on Sep 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d5853f
commit 670c565
Showing
9 changed files
with
422 additions
and
21 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
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
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
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
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
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,35 @@ | ||
/* | ||
* Licensed under Apache-2.0 | ||
* | ||
* Designed an developed by Aidan Follestad (afollestad) | ||
*/ | ||
|
||
package com.afollestad.assent | ||
|
||
/** @author Aidan Follestad (afollestad) */ | ||
internal class Queue<T> { | ||
|
||
private var data: MutableList<T> = mutableListOf() | ||
|
||
fun push(item: T) = data.add(item) | ||
|
||
fun poll() = if (data.isNotEmpty()) data[0] else null | ||
|
||
fun pop(): T { | ||
val result = poll() ?: throw IllegalStateException("Queue is empty, cannot pop.") | ||
data.removeAt(0) | ||
return result | ||
} | ||
|
||
fun size() = data.size | ||
|
||
fun isEmpty() = data.isEmpty() | ||
|
||
fun isNotEmpty() = data.isNotEmpty() | ||
|
||
fun clear() = data.clear() | ||
|
||
operator fun plusAssign(item: T) { | ||
push(item) | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
library/src/test/java/com/afollestad/assent/AssentResultTest.kt
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,57 @@ | ||
package com.afollestad.assent | ||
|
||
import android.content.pm.PackageManager.PERMISSION_DENIED | ||
import android.content.pm.PackageManager.PERMISSION_GRANTED | ||
import com.afollestad.assent.Permission.ACCESS_COARSE_LOCATION | ||
import com.afollestad.assent.Permission.CALL_PHONE | ||
import com.afollestad.assent.Permission.WRITE_EXTERNAL_STORAGE | ||
import org.assertj.core.api.Java6Assertions.assertThat | ||
import org.junit.Test | ||
|
||
class AssentResultTest { | ||
|
||
private val result = AssentResult( | ||
arrayOf(WRITE_EXTERNAL_STORAGE, ACCESS_COARSE_LOCATION), | ||
intArrayOf(PERMISSION_GRANTED, PERMISSION_DENIED) | ||
) | ||
|
||
@Test | ||
fun containsPermission_true() { | ||
assertThat(result.containsPermissions(WRITE_EXTERNAL_STORAGE)).isTrue() | ||
} | ||
|
||
@Test | ||
fun containsPermission_false() { | ||
assertThat(result.containsPermissions(CALL_PHONE)).isFalse() | ||
} | ||
|
||
@Test | ||
fun isAllGranted_true() { | ||
assertThat(result.isAllGranted(WRITE_EXTERNAL_STORAGE)).isTrue() | ||
} | ||
|
||
@Test | ||
fun isAllGranted_false_denied() { | ||
assertThat(result.isAllGranted(ACCESS_COARSE_LOCATION)).isFalse() | ||
} | ||
|
||
@Test(expected = IllegalArgumentException::class) | ||
fun isAllGranted_throws_notInSet() { | ||
result.isAllGranted(CALL_PHONE) | ||
} | ||
|
||
@Test | ||
fun isAllDenied_true() { | ||
assertThat(result.isAllDenied(ACCESS_COARSE_LOCATION)).isTrue() | ||
} | ||
|
||
@Test | ||
fun isAllDenied_false_granted() { | ||
assertThat(result.isAllDenied(WRITE_EXTERNAL_STORAGE)).isFalse() | ||
} | ||
|
||
@Test(expected = IllegalArgumentException::class) | ||
fun isAllDenied_throws_notInSet() { | ||
assertThat(result.isAllDenied(CALL_PHONE)).isFalse() | ||
} | ||
} |
Oops, something went wrong.