Merge "Fix crash when phone process has problem." into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
4f6b56277c
@@ -27,7 +27,9 @@ import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.any
|
||||
import org.mockito.kotlin.doReturn
|
||||
import org.mockito.kotlin.doThrow
|
||||
import org.mockito.kotlin.mock
|
||||
import org.mockito.kotlin.spy
|
||||
import org.mockito.kotlin.stub
|
||||
@@ -134,6 +136,15 @@ class VoNrRepositoryTest {
|
||||
assertThat(isVoNrEnabled).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isVoNrEnabledFlow_noPhoneProcess_noCrash() = runBlocking {
|
||||
mockTelephonyManager.stub { on { isVoNrEnabled } doThrow IllegalStateException("no Phone") }
|
||||
|
||||
val isVoNrEnabled = repository.isVoNrEnabledFlow(SUB_ID).firstWithTimeoutOrNull()
|
||||
|
||||
assertThat(isVoNrEnabled).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun setVoNrEnabled(): Unit = runBlocking {
|
||||
repository.setVoNrEnabled(SUB_ID, true)
|
||||
@@ -141,7 +152,20 @@ class VoNrRepositoryTest {
|
||||
verify(mockTelephonyManager).setVoNrEnabled(true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun setVoNrEnabled_noPhoneProcess_noCrash(): Unit = runBlocking {
|
||||
mockTelephonyManager.stub {
|
||||
on {
|
||||
setVoNrEnabled(any())
|
||||
} doThrow IllegalStateException("no Phone")
|
||||
}
|
||||
|
||||
repository.setVoNrEnabled(SUB_ID, true)
|
||||
|
||||
verify(mockTelephonyManager).setVoNrEnabled(true)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val SUB_ID = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user