feat: Integrate Mokkery and Turbine into KMP testing framework (#4845)

This commit is contained in:
James Rich 2026-03-18 18:33:37 -05:00 committed by GitHub
parent df3a094430
commit dcbbc0823b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
159 changed files with 1860 additions and 2809 deletions

View file

@ -16,46 +16,43 @@
*/
package org.meshtastic.core.ble
import com.juul.kable.State
import io.mockk.mockk
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
class KableStateMappingTest {
/*
@Test
fun `Connecting maps to Connecting`() {
val state = mockk<State.Connecting>()
val result = state.toBleConnectionState(hasStartedConnecting = false)
assertEquals(BleConnectionState.Connecting, result)
}
/*
@Test
fun `Connected maps to Connected`() {
val state = mockk<State.Connected>()
val result = state.toBleConnectionState(hasStartedConnecting = true)
assertEquals(BleConnectionState.Connected, result)
}
@Test
fun `Disconnecting maps to Disconnecting`() {
val state = mockk<State.Disconnecting>()
val result = state.toBleConnectionState(hasStartedConnecting = true)
assertEquals(BleConnectionState.Disconnecting, result)
}
@Test
fun `Connecting maps to Connecting`() {
val result = state.toBleConnectionState(hasStartedConnecting = false)
assertEquals(BleConnectionState.Connecting, result)
}
@Test
fun `Disconnected ignores initial emission if not started connecting`() {
val state = mockk<State.Disconnected>()
val result = state.toBleConnectionState(hasStartedConnecting = false)
assertNull(result)
}
@Test
fun `Connected maps to Connected`() {
val result = state.toBleConnectionState(hasStartedConnecting = true)
assertEquals(BleConnectionState.Connected, result)
}
@Test
fun `Disconnected maps to Disconnected if started connecting`() {
val state = mockk<State.Disconnected>()
val result = state.toBleConnectionState(hasStartedConnecting = true)
assertEquals(BleConnectionState.Disconnected, result)
}
@Test
fun `Disconnecting maps to Disconnecting`() {
val result = state.toBleConnectionState(hasStartedConnecting = true)
assertEquals(BleConnectionState.Disconnecting, result)
}
@Test
fun `Disconnected ignores initial emission if not started connecting`() {
val result = state.toBleConnectionState(hasStartedConnecting = false)
assertNull(result)
}
@Test
fun `Disconnected maps to Disconnected if started connecting`() {
val result = state.toBleConnectionState(hasStartedConnecting = true)
assertEquals(BleConnectionState.Disconnected, result)
}
*/
*/
}

View file

@ -1,71 +0,0 @@
/*
* Copyright (c) 2025-2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.ble
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import kotlin.test.assertEquals
class FakeMeshtasticRadioProfile : MeshtasticRadioProfile {
private val _fromRadio = MutableSharedFlow<ByteArray>(replay = 1)
override val fromRadio: Flow<ByteArray> = _fromRadio
private val _logRadio = MutableSharedFlow<ByteArray>(replay = 1)
override val logRadio: Flow<ByteArray> = _logRadio
val sentPackets = mutableListOf<ByteArray>()
override suspend fun sendToRadio(packet: ByteArray) {
sentPackets.add(packet)
}
suspend fun emitFromRadio(packet: ByteArray) {
_fromRadio.emit(packet)
}
suspend fun emitLogRadio(packet: ByteArray) {
_logRadio.emit(packet)
}
}
class MeshtasticRadioProfileTest {
@Test
fun testFakeProfileEmitsFromRadio() = runTest {
val fake = FakeMeshtasticRadioProfile()
val expectedPacket = byteArrayOf(1, 2, 3)
fake.emitFromRadio(expectedPacket)
val received = fake.fromRadio.first()
assertEquals(expectedPacket.toList(), received.toList())
}
@Test
fun testFakeProfileRecordsSentPackets() = runTest {
val fake = FakeMeshtasticRadioProfile()
val packet = byteArrayOf(4, 5, 6)
fake.sendToRadio(packet)
assertEquals(1, fake.sentPackets.size)
assertEquals(packet.toList(), fake.sentPackets.first().toList())
}
}