mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat: Integrate Mokkery and Turbine into KMP testing framework (#4845)
This commit is contained in:
parent
df3a094430
commit
dcbbc0823b
159 changed files with 1860 additions and 2809 deletions
|
|
@ -16,9 +16,11 @@
|
|||
*/
|
||||
package org.meshtastic.core.network.radio
|
||||
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import dev.mokkery.MockMode
|
||||
import dev.mokkery.every
|
||||
import dev.mokkery.everySuspend
|
||||
import dev.mokkery.matcher.any
|
||||
import dev.mokkery.mock
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
|
@ -42,11 +44,11 @@ import org.meshtastic.core.repository.RadioInterfaceService
|
|||
class BleRadioInterfaceTest {
|
||||
|
||||
private val testScope = TestScope()
|
||||
private val scanner: BleScanner = mockk()
|
||||
private val bluetoothRepository: BluetoothRepository = mockk()
|
||||
private val connectionFactory: BleConnectionFactory = mockk()
|
||||
private val connection: BleConnection = mockk()
|
||||
private val service: RadioInterfaceService = mockk(relaxed = true)
|
||||
private val scanner: BleScanner = mock()
|
||||
private val bluetoothRepository: BluetoothRepository = mock()
|
||||
private val connectionFactory: BleConnectionFactory = mock()
|
||||
private val connection: BleConnection = mock()
|
||||
private val service: RadioInterfaceService = mock(MockMode.autofill)
|
||||
private val address = "00:11:22:33:44:55"
|
||||
|
||||
private val connectionStateFlow = MutableSharedFlow<BleConnectionState>(replay = 1)
|
||||
|
|
@ -63,12 +65,12 @@ class BleRadioInterfaceTest {
|
|||
|
||||
@Test
|
||||
fun `connect attempts to scan and connect via init`() = runTest {
|
||||
val device: BleDevice = mockk()
|
||||
val device: BleDevice = mock()
|
||||
every { device.address } returns address
|
||||
every { device.name } returns "Test Device"
|
||||
|
||||
every { scanner.scan(any(), any()) } returns flowOf(device)
|
||||
coEvery { connection.connectAndAwait(any(), any(), any()) } returns BleConnectionState.Connected
|
||||
everySuspend { connection.connectAndAwait(any(), any(), any()) } returns BleConnectionState.Connected
|
||||
|
||||
val bleInterface =
|
||||
BleRadioInterface(
|
||||
|
|
|
|||
|
|
@ -16,15 +16,18 @@
|
|||
*/
|
||||
package org.meshtastic.core.network.radio
|
||||
|
||||
import io.mockk.confirmVerified
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import dev.mokkery.MockMode
|
||||
import dev.mokkery.matcher.any
|
||||
import dev.mokkery.mock
|
||||
import dev.mokkery.verify
|
||||
import dev.mokkery.verify.VerifyMode
|
||||
import dev.mokkery.verifyNoMoreCalls
|
||||
import org.junit.Test
|
||||
import org.meshtastic.core.repository.RadioInterfaceService
|
||||
|
||||
class StreamInterfaceTest {
|
||||
|
||||
private val service: RadioInterfaceService = mockk(relaxed = true)
|
||||
private val service: RadioInterfaceService = mock(MockMode.autofill)
|
||||
|
||||
// Concrete implementation for testing
|
||||
private class TestStreamInterface(service: RadioInterfaceService) : StreamInterface(service) {
|
||||
|
|
@ -75,7 +78,7 @@ class StreamInterfaceTest {
|
|||
|
||||
verify { service.handleFromRadio(byteArrayOf(0x11)) }
|
||||
verify { service.handleFromRadio(byteArrayOf(0x22)) }
|
||||
confirmVerified(service)
|
||||
verifyNoMoreCalls(service)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -98,6 +101,6 @@ class StreamInterfaceTest {
|
|||
header.forEach { streamInterface.testReadChar(it) }
|
||||
|
||||
// Should ignore and reset, not expecting handleFromRadio
|
||||
verify(exactly = 0) { service.handleFromRadio(any()) }
|
||||
verify(mode = VerifyMode.exactly(0)) { service.handleFromRadio(any()) }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,16 +16,9 @@
|
|||
*/
|
||||
package org.meshtastic.core.network
|
||||
|
||||
import com.fazecast.jSerialComm.SerialPort
|
||||
import io.mockk.mockk
|
||||
import org.meshtastic.core.repository.RadioInterfaceService
|
||||
import org.meshtastic.core.repository.RadioTransport
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class SerialTransportTest {
|
||||
/*
|
||||
|
||||
private val mockService: RadioInterfaceService = mockk(relaxed = true)
|
||||
|
||||
@Test
|
||||
|
|
@ -53,4 +46,6 @@ class SerialTransportTest {
|
|||
assertFalse(connected, "Connecting to an invalid port should return false")
|
||||
transport.close()
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue