This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 475
/
BiometricUtilsTest.kt
50 lines (43 loc) · 1.86 KB
/
BiometricUtilsTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package mozilla.components.lib.auth
import android.os.Build
import androidx.biometric.BiometricManager
import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.support.test.mock
import mozilla.components.support.test.robolectric.testContext
import mozilla.components.support.test.whenever
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.Config
@RunWith(AndroidJUnit4::class)
class BiometricUtilsTest {
@Config(sdk = [Build.VERSION_CODES.LOLLIPOP])
@Test
fun `canUseFeature checks for SDK compatible`() {
assertFalse(testContext.canUseBiometricFeature())
}
@Test
fun `isHardwareAvailable is true based on AuthenticationStatus`() {
val manager: BiometricManager = mock {
whenever(canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK))
.thenReturn(BiometricManager.BIOMETRIC_SUCCESS)
.thenReturn(BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE)
.thenReturn(BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE)
}
assertTrue(BiometricUtils.isHardwareAvailable(manager))
assertFalse(BiometricUtils.isHardwareAvailable(manager))
assertFalse(BiometricUtils.isHardwareAvailable(manager))
}
@Test
fun `isEnrolled is true based on AuthenticationStatus`() {
val manager: BiometricManager = mock {
whenever(canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK))
.thenReturn(BiometricManager.BIOMETRIC_SUCCESS)
}
assertTrue(BiometricUtils.isEnrolled(manager))
}
}