Skip to content

Commit

Permalink
chore: comments from the Code Review
Browse files Browse the repository at this point in the history
  • Loading branch information
kikoso committed Aug 4, 2023
1 parent 6948f0e commit bab3830
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,20 @@ _Old_

</details>

## Usage guide

The full documentation can be found here [Google Maps Platform documentation][devsite-guide].

For a quick snippet on the StreetViewUtil class, keep reading.

The StreetViewUtil class provides functionality to check whether a location is supported in StreetView. To call it, use the following snippet:

```kotlin
StreetViewUtils.fetchStreetViewData(LatLng(8.1425918, 11.5386121), BuildConfig.MAPS_API_KEY)
```

`fetchStreetViewData` will return `NOT_FOUND`, `OK` or `ZERO_RESULTS`, depending on the response.

## Support

Encounter an issue while using this library?
Expand Down
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.robolectric:robolectric:4.10.3'
testImplementation 'net.sf.kxml:kxml2:2.3.0'
testImplementation "io.mockk:mockk:1.13.4"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class StreetViewUtils {
* @param apiKey Maps API Key
* @return A boolean value specifying if the location is available on Street View or not.
*/
suspend fun fetchStreetViewData(latLng: LatLng, apiKey: String): Boolean {
suspend fun fetchStreetViewData(latLng: LatLng, apiKey: String): Status {
val urlString =
"https://maps.googleapis.com/maps/api/streetview/metadata?location=${latLng.latitude},${latLng.longitude}&key=$apiKey"

Expand All @@ -56,9 +56,7 @@ class StreetViewUtils {
val responseString = bufferedReader.use { it.readText() }
bufferedReader.close()
inputStream.close()

val response: ResponseStreetView = deserializeResponse(responseString)
response.status == Status.OK
deserializeResponse(responseString).status
} else {
throw IOException("HTTP Error: $responseCode")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.google.maps.android

import com.google.android.gms.maps.model.LatLng
import io.mockk.coEvery
import io.mockk.mockkObject
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test

class StreetViewUtilsTest {

lateinit var latLng : LatLng

val apiKey = "AN_API_KEY"

@Before
fun setUp() {
latLng = LatLng(37.7749, -122.4194) // San Francisco coordinates

// Mock the network behavior using MockK
mockkObject(StreetViewUtils)
coEvery { StreetViewUtils.fetchStreetViewData(any(), any()) } returns Status.NOT_FOUND
coEvery { StreetViewUtils.fetchStreetViewData(latLng, apiKey) } returns Status.OK
}

@Test
fun testLocationFoundOnStreetView() = runBlocking {
val status = StreetViewUtils.fetchStreetViewData(latLng, apiKey)
assertEquals(Status.OK, status)
}

@Test
fun testLocationNotFoundOnStreetView() = runBlocking {
val status = StreetViewUtils.fetchStreetViewData(LatLng(10.0, 20.0), apiKey)
assertEquals(Status.NOT_FOUND, status)
}
}

0 comments on commit bab3830

Please sign in to comment.