Last active
October 27, 2022 12:11
-
-
Save inderisonline/e432f3b666036a4f7aa0fc0a5e0c751c to your computer and use it in GitHub Desktop.
CurrentLocationCoroutineWrapperImplTest
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
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