-
Notifications
You must be signed in to change notification settings - Fork 9
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
Showing
9 changed files
with
97 additions
and
87 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 was deleted.
Oops, something went wrong.
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,21 @@ | ||
package com.permissionnanny | ||
|
||
import android.content.Context | ||
import android.content.pm.ApplicationInfo | ||
import android.content.pm.PackageManager | ||
|
||
/** | ||
* Utilities. | ||
*/ | ||
object Util { | ||
|
||
fun getApplicationInfo(context: Context, packageName: String): ApplicationInfo? { | ||
val pm = context.packageManager | ||
try { | ||
return pm.getApplicationInfo(packageName, 0) | ||
} catch (e: PackageManager.NameNotFoundException) { | ||
return null | ||
} | ||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,45 @@ | ||
package com.permissionnanny | ||
|
||
import android.content.Context | ||
import android.content.pm.ApplicationInfo | ||
import android.content.pm.PackageManager | ||
import org.hamcrest.Matchers.nullValue | ||
import org.hamcrest.Matchers.sameInstance | ||
import org.junit.Assert.assertThat | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.mockito.BDDMockito.given | ||
import org.mockito.Matchers.anyInt | ||
import org.mockito.Matchers.anyString | ||
import org.mockito.Mock | ||
|
||
class UtilTest : NannyAppTestCase() { | ||
|
||
private var applicationInfo = ApplicationInfo() | ||
@Mock private lateinit var context: Context | ||
@Mock private lateinit var packageManager: PackageManager | ||
|
||
@Before | ||
fun setUp() { | ||
given(context.packageManager).willReturn(packageManager) | ||
} | ||
|
||
@Test | ||
fun getApplicationInfo() { | ||
given(packageManager.getApplicationInfo("a", 0)).willReturn(applicationInfo) | ||
|
||
val actual = Util.getApplicationInfo(context, "a") | ||
|
||
assertThat(actual, sameInstance(applicationInfo)) | ||
} | ||
|
||
@Test | ||
fun getApplicationInfo_shouldReturnNull_whenQueryThrows() { | ||
given(packageManager.getApplicationInfo(anyString(), anyInt())) | ||
.willThrow(PackageManager.NameNotFoundException()) | ||
|
||
val actual = Util.getApplicationInfo(context, "a") | ||
|
||
assertThat(actual, nullValue()) | ||
} | ||
} |
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