Commit 762c27cb authored by Christian Sadilek's avatar Christian Sadilek
Browse files

Issue #8009: Handle all throwables in hasCamera check

parent b117c19d
......@@ -80,7 +80,7 @@ fun Context.hasCamera(): Boolean {
return try {
val cameraManager: CameraManager? = getSystemService()
cameraManager?.cameraIdList?.isNotEmpty() ?: false
} catch (e: Exception) {
} catch (_: Throwable) {
false
}
}
......
......@@ -31,6 +31,7 @@ import org.robolectric.Shadows.shadowOf
import org.robolectric.shadows.ShadowApplication
import org.robolectric.shadows.ShadowCameraCharacteristics
import org.robolectric.shadows.ShadowProcess
import java.lang.AssertionError
import java.lang.IllegalStateException
@RunWith(AndroidJUnit4::class)
......@@ -157,7 +158,18 @@ class ContextTest {
val context = spy(testContext)
val cameraManager: CameraManager = mock()
whenever(context.getSystemService(Context.CAMERA_SERVICE)).thenReturn(cameraManager)
whenever(cameraManager.cameraIdList).thenThrow(IllegalStateException("Test"))
assertFalse(context.hasCamera())
}
@Test
fun `hasCamera returns false if assertion is thrown`() {
val context = spy(testContext)
val cameraManager: CameraManager = mock()
whenever(context.getSystemService(Context.CAMERA_SERVICE)).thenReturn(cameraManager)
whenever(cameraManager.cameraIdList).thenThrow(AssertionError("Test"))
assertFalse(context.hasCamera())
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment