Skip to content

Commit 14d5963

Browse files
korshaknnabhishek1508
authored andcommitted
add tests
1 parent 0b03a78 commit 14d5963

File tree

11 files changed

+62
-8
lines changed

11 files changed

+62
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Mapbox welcomes participation and contributions from everyone.
1717
- Fixed an issue with `NavigationView` that caused unexpected camera movements when switching between navigation states. [#6487](https://github.com/mapbox/mapbox-navigation-android/pull/6487)
1818
- Supported changing `MapboxVoiceInstructionsPlayer` language in runtime via `updateLanguage` method. [#6491](https://github.com/mapbox/mapbox-navigation-android/pull/6491)
1919
- Deprecated `MapboxVoiceInstructionsPlayer` constructors that accept access token and introduced the ones without it. [#6491](https://github.com/mapbox/mapbox-navigation-android/pull/6491)
20-
- Updated `NavigationViewApi` and `MapboxAudioGuidance`. Introduced `currentVoiceInstructionsPlayer` which allows playing customers voice instructions. [#6475](https://github.com/mapbox/mapbox-navigation-android/pull/6475)
20+
- Introduced `NavigationViewApi.getCurrentVoiceInstructionsPlayer()` which can be used to play custom voice instructions. [#6475](https://github.com/mapbox/mapbox-navigation-android/pull/6475)
2121

2222
## Mapbox Navigation SDK 2.9.0-beta.2 - 14 October, 2022
2323
### Changelog

libnavui-dropin/api/current.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ package com.mapbox.navigation.dropin {
4848
method public abstract void startFreeDrive();
4949
method public abstract com.mapbox.bindgen.Expected<com.mapbox.navigation.dropin.NavigationViewApiError,kotlin.Unit> startRoutePreview();
5050
method public abstract com.mapbox.bindgen.Expected<com.mapbox.navigation.dropin.NavigationViewApiError,kotlin.Unit> startRoutePreview(java.util.List<com.mapbox.navigation.base.route.NavigationRoute> routes);
51-
property public abstract com.mapbox.navigation.ui.voice.api.MapboxVoiceInstructionsPlayer? currentVoiceInstructionsPlayer;
5251
}
5352

5453
public final class NavigationViewApiError extends java.lang.Throwable {

libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/NavigationViewApi.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ abstract class NavigationViewApi {
115115
abstract fun routeReplayEnabled(enabled: Boolean)
116116

117117
/**
118-
* Current instance of a voice instructions player.
118+
* Access the current instance of [MapboxVoiceInstructionsPlayer] created by [NavigationView].
119119
*/
120-
abstract val currentVoiceInstructionsPlayer: MapboxVoiceInstructionsPlayer?
120+
abstract fun getCurrentVoiceInstructionsPlayer(): MapboxVoiceInstructionsPlayer?
121121
}

libnavui-dropin/src/main/java/com/mapbox/navigation/dropin/navigationview/MapboxNavigationViewApi.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.mapbox.navigation.ui.app.internal.startActiveNavigation
2020
import com.mapbox.navigation.ui.app.internal.startArrival
2121
import com.mapbox.navigation.ui.app.internal.tripsession.TripSessionStarterAction
2222
import com.mapbox.navigation.ui.voice.api.MapboxAudioGuidance
23+
import com.mapbox.navigation.ui.voice.api.MapboxVoiceInstructionsPlayer
2324

2425
@ExperimentalPreviewMapboxNavigationAPI
2526
internal class MapboxNavigationViewApi(
@@ -101,8 +102,9 @@ internal class MapboxNavigationViewApi(
101102
}
102103
}
103104

104-
override val currentVoiceInstructionsPlayer
105-
get() = MapboxAudioGuidance.getRegisteredInstance().currentVoiceInstructionsPlayer
105+
override fun getCurrentVoiceInstructionsPlayer(): MapboxVoiceInstructionsPlayer? {
106+
return MapboxAudioGuidance.getRegisteredInstance().getCurrentVoiceInstructionsPlayer()
107+
}
106108

107109
@Throws(NavigationViewApiError::class)
108110
private fun checkDestination() {

libnavui-dropin/src/test/java/com/mapbox/navigation/dropin/navigationview/MapboxNavigationViewApiTest.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@ import com.mapbox.navigation.ui.app.internal.routefetch.RoutePreviewAction
1414
import com.mapbox.navigation.ui.app.internal.routefetch.RoutePreviewState
1515
import com.mapbox.navigation.ui.app.internal.routefetch.RoutesAction
1616
import com.mapbox.navigation.ui.app.internal.tripsession.TripSessionStarterAction
17+
import com.mapbox.navigation.ui.voice.api.MapboxAudioGuidance
18+
import com.mapbox.navigation.ui.voice.api.MapboxVoiceInstructionsPlayer
1719
import io.mockk.every
1820
import io.mockk.mockk
21+
import io.mockk.mockkObject
1922
import io.mockk.spyk
23+
import io.mockk.unmockkObject
2024
import io.mockk.verify
25+
import org.junit.After
2126
import org.junit.Assert.assertEquals
2227
import org.junit.Assert.assertFalse
28+
import org.junit.Assert.assertNull
2329
import org.junit.Assert.assertTrue
2430
import org.junit.Before
2531
import org.junit.Test
@@ -30,6 +36,7 @@ class MapboxNavigationViewApiTest {
3036
private lateinit var sut: MapboxNavigationViewApi
3137

3238
private lateinit var testStore: TestStore
39+
private var audioGuidance: MapboxAudioGuidance = mockk(relaxed = true)
3340

3441
@Before
3542
fun setUp() {
@@ -48,9 +55,18 @@ class MapboxNavigationViewApiTest {
4855
}
4956
}
5057
)
58+
59+
mockkObject(MapboxAudioGuidance.Companion)
60+
every { MapboxAudioGuidance.getRegisteredInstance() } returns audioGuidance
61+
5162
sut = MapboxNavigationViewApi(testStore)
5263
}
5364

65+
@After
66+
fun cleanUp() {
67+
unmockkObject(MapboxAudioGuidance.Companion)
68+
}
69+
5470
@Test
5571
@Suppress("MaxLineLength")
5672
fun `startFreeDrive should clear routes and preview routes and set FreeDrive NavigationState`() {
@@ -334,6 +350,16 @@ class MapboxNavigationViewApiTest {
334350
verify { testStore.dispatch(TripSessionStarterAction.EnableTripSession) }
335351
}
336352

353+
@Test
354+
fun `getCurrentVoiceInstructionsPlayer returns valid player instance`() {
355+
every { audioGuidance.getCurrentVoiceInstructionsPlayer() } returns null
356+
assertNull(sut.getCurrentVoiceInstructionsPlayer())
357+
358+
val player: MapboxVoiceInstructionsPlayer = mockk()
359+
every { audioGuidance.getCurrentVoiceInstructionsPlayer() } returns player
360+
assertEquals(player, sut.getCurrentVoiceInstructionsPlayer())
361+
}
362+
337363
private fun navigationRoute(vararg waypoints: Point): NavigationRoute {
338364
return mockk {
339365
every { routeOptions } returns mockk(relaxed = true) {

libnavui-voice/api/current.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ package com.mapbox.navigation.ui.voice.api {
3131
method public kotlinx.coroutines.flow.StateFlow<com.mapbox.navigation.ui.voice.api.MapboxAudioGuidanceState> stateFlow();
3232
method public void toggle();
3333
method public void unmute();
34-
property public final com.mapbox.navigation.ui.voice.api.MapboxVoiceInstructionsPlayer? currentVoiceInstructionsPlayer;
3534
field public static final com.mapbox.navigation.ui.voice.api.MapboxAudioGuidance.Companion Companion;
3635
}
3736

libnavui-voice/src/main/java/com/mapbox/navigation/ui/voice/api/MapboxAudioGuidance.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ internal constructor(
5252
/**
5353
* Current instance of a [VoiceInstructionsPlayer].
5454
*/
55-
val currentVoiceInstructionsPlayer get() = audioGuidanceServices.voiceInstructionsPlayer
55+
fun getCurrentVoiceInstructionsPlayer() = audioGuidanceServices.voiceInstructionsPlayer
5656

5757
/**
5858
* @see [MapboxNavigationApp]

libnavui-voice/src/main/java/com/mapbox/navigation/ui/voice/internal/impl/MapboxAudioGuidanceServices.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.mapbox.navigation.ui.voice.internal.MapboxVoiceInstructions
1212
class MapboxAudioGuidanceServices {
1313

1414
var voiceInstructionsPlayer: MapboxVoiceInstructionsPlayer? = null
15+
private set
1516

1617
fun mapboxAudioGuidanceVoice(
1718
mapboxNavigation: MapboxNavigation,

libnavui-voice/src/test/java/com/mapbox/navigation/ui/voice/api/MapboxAudioGuidanceTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,17 @@ class MapboxAudioGuidanceTest {
211211
}
212212
carAppAudioGuidance.onDetached(mapboxNavigation)
213213
}
214+
215+
@Test
216+
fun `getCurrentVoiceInstructionsPlayer returns valid player instance`() {
217+
val mapboxAudioGuidanceServices =
218+
testMapboxAudioGuidanceServices.mapboxAudioGuidanceServices
219+
220+
every { mapboxAudioGuidanceServices.voiceInstructionsPlayer } returns null
221+
assertNull(carAppAudioGuidance.getCurrentVoiceInstructionsPlayer())
222+
223+
val player: MapboxVoiceInstructionsPlayer = mockk()
224+
every { mapboxAudioGuidanceServices.voiceInstructionsPlayer } returns player
225+
assertEquals(player, carAppAudioGuidance.getCurrentVoiceInstructionsPlayer())
226+
}
214227
}

qa-test-app/src/main/java/com/mapbox/navigation/qa_test_app/view/customnavview/MapboxNavigationViewCustomizedActivity.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import com.mapbox.navigation.qa_test_app.view.base.DrawerActivity
8585
import com.mapbox.navigation.ui.base.lifecycle.UIBinder
8686
import com.mapbox.navigation.ui.base.lifecycle.UIComponent
8787
import com.mapbox.navigation.ui.maps.NavigationStyles
88+
import com.mapbox.navigation.ui.voice.model.SpeechAnnouncement
8889
import com.mapbox.navigation.utils.internal.toPoint
8990

9091
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class)
@@ -147,6 +148,13 @@ class MapboxNavigationViewCustomizedActivity : DrawerActivity() {
147148
binding.navigationView.api.routeReplayEnabled(isChecked)
148149
}
149150
)
151+
menuBinding.buttonVoiceInstruction.setOnClickListener {
152+
binding.navigationView.api.getCurrentVoiceInstructionsPlayer()?.play(
153+
SpeechAnnouncement.Builder("This is a test voice instruction").build()
154+
) {
155+
// no op
156+
}
157+
}
150158
initActivityOptions()
151159
initGeneralOptions()
152160
initMapOptions()

0 commit comments

Comments
 (0)