Call unmockAll after each test

This commit is contained in:
Maxime NATUREL 2022-06-13 11:35:44 +02:00
parent a1aa337edb
commit 162fd0a840

View File

@ -31,8 +31,7 @@ import io.mockk.mockkConstructor
import io.mockk.mockkStatic import io.mockk.mockkStatic
import io.mockk.runs import io.mockk.runs
import io.mockk.slot import io.mockk.slot
import io.mockk.unmockkConstructor import io.mockk.unmockkAll
import io.mockk.unmockkStatic
import io.mockk.verify import io.mockk.verify
import io.mockk.verifyOrder import io.mockk.verifyOrder
import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldBeEqualTo
@ -47,8 +46,15 @@ private const val AN_ACCURACY = 5.0f
class LocationTrackerTest { class LocationTrackerTest {
private val fakeHandler = FakeHandler() private val fakeHandler = FakeHandler()
private val fakeLocationManager = FakeLocationManager()
private val fakeContext = FakeContext().also {
it.givenService(Context.LOCATION_SERVICE, android.location.LocationManager::class.java, fakeLocationManager.instance)
}
init { private lateinit var locationTracker: LocationTracker
@Before
fun setUp() {
mockkConstructor(Debouncer::class) mockkConstructor(Debouncer::class)
every { anyConstructed<Debouncer>().cancelAll() } just runs every { anyConstructed<Debouncer>().cancelAll() } just runs
val runnable = slot<Runnable>() val runnable = slot<Runnable>()
@ -58,24 +64,13 @@ class LocationTrackerTest {
} }
mockkStatic("im.vector.app.core.utils.HandlerKt") mockkStatic("im.vector.app.core.utils.HandlerKt")
every { createBackgroundHandler(any()) } returns fakeHandler.instance every { createBackgroundHandler(any()) } returns fakeHandler.instance
} locationTracker = LocationTracker(fakeContext.instance)
private val fakeLocationManager = FakeLocationManager()
private val fakeContext = FakeContext().also {
it.givenService(Context.LOCATION_SERVICE, android.location.LocationManager::class.java, fakeLocationManager.instance)
}
private val locationTracker = LocationTracker(fakeContext.instance)
@Before
fun setUp() {
fakeLocationManager.givenRemoveUpdates(locationTracker) fakeLocationManager.givenRemoveUpdates(locationTracker)
} }
@After @After
fun tearDown() { fun tearDown() {
unmockkStatic("im.vector.app.core.utils.HandlerKt") unmockkAll()
unmockkConstructor(Debouncer::class)
} }
@Test @Test