Skip to content

Commit

Permalink
fixing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kmadsen committed Jan 28, 2023
1 parent 959b5ea commit 7fb60f8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 56 deletions.
3 changes: 1 addition & 2 deletions android-auto-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ dependencies {
// This example is used for development so it may depend on unstable versions.
// Examples based on final versions can be found in the examples repository.
// https://github.com/mapbox/mapbox-navigation-android-examples
implementation project(':libnavui-dropin')
// implementation("com.mapbox.navigation:ui-dropin:2.10.0")
implementation("com.mapbox.navigation:ui-dropin:2.10.0")
implementation("com.mapbox.search:mapbox-search-android:1.0.0-beta.43")

// Dependencies needed for this example.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,16 @@ class MapboxTripStarter internal constructor(
isLocationPermissionGranted.onEach { granted ->
onMapMatchingEnabled(mapboxNavigation, granted)
}
MapboxTripStarterType.ReplayRoute ->
replayRouteSession.getOptions().onEach { options ->
onReplayRouteEnabled(mapboxNavigation, options)
}
MapboxTripStarterType.ReplayHistory ->
replayHistorySession.getOptions().onEach { options ->
onReplayHistoryEnabled(mapboxNavigation, options)
}
MapboxTripStarterType.ReplayRoute -> {
replayHistorySession.onDetached(mapboxNavigation)
replayRouteSession.onAttached(mapboxNavigation)
replayRouteSession.getOptions()
}
MapboxTripStarterType.ReplayHistory -> {
replayRouteSession.onDetached(mapboxNavigation)
replayHistorySession.onAttached(mapboxNavigation)
replayHistorySession.getOptions()
}
}
}
}
Expand All @@ -186,36 +188,6 @@ class MapboxTripStarter internal constructor(
}
}

/**
* Internally called when the trip type has been set to replay route.
*
* @param mapboxNavigation
* @param options parameters for the [ReplayRouteSession]
*/
private fun onReplayRouteEnabled(
mapboxNavigation: MapboxNavigation,
options: ReplayRouteSessionOptions
) {
replayHistorySession.onDetached(mapboxNavigation)
replayRouteSession.setOptions(options)
replayRouteSession.onAttached(mapboxNavigation)
}

/**
* Internally called when the trip type has been set to replay history.
*
* @param mapboxNavigation
* @param options parameters for the [ReplayHistorySession]
*/
private fun onReplayHistoryEnabled(
mapboxNavigation: MapboxNavigation,
options: ReplayHistorySessionOptions
) {
replayRouteSession.onDetached(mapboxNavigation)
replayHistorySession.setOptions(options)
replayHistorySession.onAttached(mapboxNavigation)
}

/**
* Internally called when the trip session needs to be stopped.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.mapbox.navigation.core.directions.session.RoutesObserver
import com.mapbox.navigation.core.replay.history.ReplayHistorySession
import com.mapbox.navigation.core.replay.history.ReplayHistorySessionOptions
import com.mapbox.navigation.core.replay.route.ReplayRouteSession
import com.mapbox.navigation.core.replay.route.ReplayRouteSessionOptions
import com.mapbox.navigation.core.trip.session.TripSessionState
import com.mapbox.navigation.testing.LoggingFrontendTestRule
import com.mapbox.navigation.testing.MainCoroutineRule
Expand Down Expand Up @@ -44,12 +45,19 @@ class MapboxTripStarterTest {
@get:Rule
val coroutineRule = MainCoroutineRule()

private val replayRouteSession = mockk<ReplayRouteSession>(relaxed = true)
private var historyOptions = MutableStateFlow(ReplayHistorySessionOptions.Builder().build())
private var replayRouteOptions = MutableStateFlow(ReplayRouteSessionOptions.Builder().build())
private val replayRouteSession = mockk<ReplayRouteSession>(relaxed = true) {
every { getOptions() } returns replayRouteOptions
every { setOptions(any()) } answers {
replayRouteOptions.value = firstArg()
this@mockk
}
}
private var replayHistoryOptions = MutableStateFlow(ReplayHistorySessionOptions.Builder().build())
private val replayHistorySession = mockk<ReplayHistorySession>(relaxed = true) {
every { getOptions() } returns historyOptions
every { getOptions() } returns replayHistoryOptions
every { setOptions(any()) } answers {
historyOptions.value = firstArg()
replayHistoryOptions.value = firstArg()
}
}

Expand Down Expand Up @@ -192,20 +200,20 @@ class MapboxTripStarterTest {

val mapboxNavigation = mockMapboxNavigation()
sut.enableReplayRoute()
sut.onAttached(mapboxNavigation)
val nextOptions = sut.getReplayRouteSessionOptions().toBuilder()
val customOptions = sut.getReplayRouteSessionOptions().toBuilder()
.decodeMinDistance(Double.MAX_VALUE)
.build()
sut.enableReplayRoute(nextOptions)
sut.enableReplayRoute(customOptions)
sut.onAttached(mapboxNavigation)

verifyOrder {
replayRouteSession.setOptions(any())
replayRouteSession.setOptions(customOptions)
replayRouteSession.onAttached(mapboxNavigation)
}
verify(exactly = 0) {
mapboxNavigation.stopTripSession()
replayRouteSession.onDetached(mapboxNavigation)
replayRouteSession.setOptions(nextOptions)
replayRouteSession.onAttached(mapboxNavigation)
}
verify(exactly = 0) { mapboxNavigation.stopTripSession() }
}

@Test
Expand All @@ -219,7 +227,6 @@ class MapboxTripStarterTest {
sut.onDetached(mapboxNavigation)

verifyOrder {
replayRouteSession.onDetached(mapboxNavigation)
replayHistorySession.onDetached(mapboxNavigation)
replayRouteSession.onAttached(mapboxNavigation)
replayRouteSession.onDetached(mapboxNavigation)
Expand Down Expand Up @@ -283,17 +290,15 @@ class MapboxTripStarterTest {
every { PermissionsManager.areLocationPermissionsGranted(any()) } returns false

val mapboxNavigation = mockMapboxNavigation()
sut.enableReplayHistory()
sut.onAttached(mapboxNavigation)
val nextOptions = sut.getReplayHistorySessionOptions().toBuilder()
.enableSetRoute(false)
.build()
sut.enableReplayHistory(nextOptions)
sut.onAttached(mapboxNavigation)

verifyOrder {
replayHistorySession.setOptions(any())
replayHistorySession.onAttached(mapboxNavigation)
replayHistorySession.setOptions(nextOptions)
replayHistorySession.onAttached(mapboxNavigation)
}
verify(exactly = 0) {
mapboxNavigation.stopTripSession()
Expand Down

0 comments on commit 7fb60f8

Please sign in to comment.