-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
128bf07
commit 00927ff
Showing
7 changed files
with
117 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
.../background/src/test/kotlin/com/masselis/tpmsadvanced/feature/background/usecase/Mocks.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.masselis.tpmsadvanced.feature.background.usecase | ||
|
||
import com.masselis.tpmsadvanced.core.database.QueryOne | ||
import com.masselis.tpmsadvanced.data.vehicle.model.Pressure | ||
import com.masselis.tpmsadvanced.data.vehicle.model.Pressure.CREATOR.bar | ||
import com.masselis.tpmsadvanced.data.vehicle.model.Temperature | ||
import com.masselis.tpmsadvanced.data.vehicle.model.Temperature.CREATOR.celsius | ||
import com.masselis.tpmsadvanced.data.vehicle.model.Vehicle | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import kotlinx.coroutines.flow.flowOf | ||
import java.util.UUID | ||
|
||
internal inline fun <reified T : Any> mockQueryOne(value: T) = mockk<QueryOne<T>> { | ||
every { execute() } returns value | ||
every { asFlow(any()) } returns flowOf(value) | ||
every { asChillFlow(any()) } returns flowOf(value) | ||
} | ||
|
||
internal fun mockVehicle( | ||
uuid: UUID = UUID.randomUUID(), | ||
kind: Vehicle.Kind = Vehicle.Kind.CAR, | ||
name: String = "MOCK", | ||
lowPressure: Pressure = 1f.bar, | ||
highPressure: Pressure = 5f.bar, | ||
lowTemp: Temperature = 15f.celsius, | ||
normalTemp: Temperature = 25f.celsius, | ||
highTemp: Temperature = 45f.celsius, | ||
isBackgroundMonitor: Boolean = false, | ||
) = Vehicle( | ||
uuid, kind, name, lowPressure, highPressure, lowTemp, normalTemp, highTemp, isBackgroundMonitor | ||
) |
70 changes: 70 additions & 0 deletions
70
...tlin/com/masselis/tpmsadvanced/feature/background/usecase/VehiclesToMonitorUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.masselis.tpmsadvanced.feature.background.usecase | ||
|
||
import app.cash.turbine.test | ||
import com.masselis.tpmsadvanced.core.feature.usecase.CurrentVehicleUseCase | ||
import com.masselis.tpmsadvanced.data.vehicle.interfaces.VehicleDatabase | ||
import com.masselis.tpmsadvanced.data.vehicle.model.Vehicle | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Before | ||
import org.junit.Test | ||
import kotlin.test.assertEquals | ||
|
||
|
||
internal class VehiclesToMonitorUseCaseTest { | ||
|
||
private lateinit var currentVehicleUseCase: CurrentVehicleUseCase | ||
private lateinit var vehicleDatabase: VehicleDatabase | ||
|
||
@Before | ||
fun setup() { | ||
currentVehicleUseCase = mockk() | ||
vehicleDatabase = mockk { | ||
every { selectUuidIsDeleting() } returns mockk { | ||
every { asFlow() } returns flowOf(emptyList()) | ||
} | ||
every { selectAll() } returns mockk { | ||
every { asFlow() } returns flowOf(emptyList()) | ||
} | ||
} | ||
} | ||
|
||
private fun test() = VehiclesToMonitorUseCase(currentVehicleUseCase, vehicleDatabase) | ||
|
||
@Test | ||
fun `no background monitor`() = runTest { | ||
test().ignoredAndMonitored().test { | ||
assertEquals(emptyList<Vehicle>() to emptyList(), awaitItem()) | ||
} | ||
} | ||
|
||
@Test | ||
fun `add vehicle to monitor`() = runTest { | ||
val vehicle = mockVehicle() | ||
every { vehicleDatabase.selectByUuid(vehicle.uuid) } returns mockQueryOne(vehicle) | ||
with(test()) { | ||
ignoredAndMonitored().test { | ||
assertEquals(emptyList<Vehicle>() to emptyList(), awaitItem()) | ||
enableManual(vehicle.uuid) | ||
assertEquals(emptyList<Vehicle>() to listOf(vehicle), awaitItem()) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `add vehicle to monitor and remove it`() = runTest { | ||
val vehicle = mockVehicle() | ||
every { vehicleDatabase.selectByUuid(vehicle.uuid) } returns mockQueryOne(vehicle) | ||
with(test()) { | ||
ignoredAndMonitored().test { | ||
assertEquals(emptyList<Vehicle>() to emptyList(), awaitItem()) | ||
enableManual(vehicle.uuid) | ||
assertEquals(emptyList<Vehicle>() to listOf(vehicle), awaitItem()) | ||
disableManual(vehicle.uuid) | ||
assertEquals(emptyList<Vehicle>() to emptyList(), awaitItem()) | ||
} | ||
} | ||
} | ||
} |