forked from mozilla-mobile/android-components
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue mozilla-mobile#5989: Create LocationService interface and make …
…MozillaLocationService implement it.
- Loading branch information
Showing
6 changed files
with
80 additions
and
27 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...nts/service/location/src/main/java/mozilla/components/service/location/LocationService.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,39 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.service.location | ||
|
||
/** | ||
* Interface describing a [LocationService] that returns a [Region]. | ||
*/ | ||
interface LocationService { | ||
/** | ||
* Determines the current [Region] of the user. | ||
*/ | ||
suspend fun fetchRegion(readFromCache: Boolean = true): Region? | ||
|
||
/** | ||
* A [Region] returned by the location service. | ||
* | ||
* The [Region] use region codes and names from the GENC dataset, which is for the most part | ||
* compatible with the ISO 3166 standard. While the API endpoint and [Region] class refers to | ||
* country, no claim about the political status of any region is made by this service. | ||
* | ||
* @param countryCode Country code; ISO 3166. | ||
* @param countryName Name of the country (English); ISO 3166. | ||
*/ | ||
data class Region( | ||
val countryCode: String, | ||
val countryName: String | ||
) | ||
|
||
companion object { | ||
/** | ||
* Creates a dummy [LocationService] implementation that always returns `null`. | ||
*/ | ||
fun dummy() = object : LocationService { | ||
override suspend fun fetchRegion(readFromCache: Boolean): Region? = null | ||
} | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
...service/location/src/test/java/mozilla/components/service/location/LocationServiceTest.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,20 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.service.location | ||
|
||
import junit.framework.TestCase.assertNull | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.Test | ||
|
||
class LocationServiceTest { | ||
@Test | ||
fun `dummy implementation returns null`() { | ||
runBlocking { | ||
assertNull(LocationService.dummy().fetchRegion(false)) | ||
assertNull(LocationService.dummy().fetchRegion(true)) | ||
assertNull(LocationService.dummy().fetchRegion(false)) | ||
} | ||
} | ||
} |
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