Skip to content

Instantly share code, notes, and snippets.

@inderisonline
Last active October 27, 2022 12:11
Show Gist options
  • Save inderisonline/e432f3b666036a4f7aa0fc0a5e0c751c to your computer and use it in GitHub Desktop.
Save inderisonline/e432f3b666036a4f7aa0fc0a5e0c751c to your computer and use it in GitHub Desktop.
CurrentLocationCoroutineWrapperImplTest
class CurrentLocationCoroutineWrapperImplTest {
private val fusedLocationProviderClient: FusedLocationProviderClient = mockk(relaxed = true)
private lateinit var currentLocationCoroutineWrapperImpl: CurrentLocationCoroutineWrapperImpl
@Before
fun before() {
currentLocationCoroutineWrapperImpl =
CurrentLocationCoroutineWrapperImpl(fusedLocationProviderClient)
}
@Test
fun `getCurrentLocation with locationPriority success`() =
runTest {
val locationTaskMock: Task<Location> = mockk(relaxed = true)
val locationMock: Location = mockk()
every {
fusedLocationProviderClient.getCurrentLocation(
Priority.PRIORITY_HIGH_ACCURACY,
any()
)
} returns locationTaskMock
val slot = slot<OnSuccessListener<Location>>()
every { locationTaskMock.addOnSuccessListener(capture(slot)) } answers {
slot.captured.onSuccess(locationTaskMock.result)
locationTaskMock
}
every { locationTaskMock.result } returns locationMock
val result =
currentLocationCoroutineWrapperImpl.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY)
assertEquals(locationMock, result)
verify {
fusedLocationProviderClient.getCurrentLocation(
Priority.PRIORITY_HIGH_ACCURACY,
any()
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment