Can someone help me write the unit test for getCurrentLocation
method?
override suspend fun getCurrentLocation(locationPriority: Int) =
suspendCancellableCoroutine { cont ->
fusedLocationProviderClient.getCurrentLocation(
locationPriority,
cancellationToken,
).apply {
addOnSuccessListener { location: Location? ->
if (location == null) {
cont.resumeWithException(CurrentLocationException.CurrentLocationNotFoundException())
} else {
cont.resume(location)
}
}
addOnFailureListener {
cont.resumeWithException(
CurrentLocationException.UnknownCurrentLocationException(
it
)
)
}
addOnCanceledListener {
cont.resumeWithException(CurrentLocationException.CurrentLocationCancelledException())
}
}
}
private val cancellationToken = object : CancellationToken() {
override fun onCanceledRequested(p0: OnTokenCanceledListener) =
CancellationTokenSource().token
override fun isCancellationRequested() = false
}