Skip to content

Commit

Permalink
removed route from the TripSession interface to clearly make Directio…
Browse files Browse the repository at this point in the history
…nsSession the source of truth
  • Loading branch information
LukasPaczos committed Sep 16, 2021
1 parent b2a7f74 commit 4155ade
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ class MapboxNavigation(
logger
)
historyRecorder.historyRecorderHandle = navigator.getHistoryRecorderHandle()
tripSession.route?.let {
directionsSession.routes.firstOrNull()?.let {
navigator.setRoute(
it,
tripSession.getRouteProgress()?.currentLegProgress?.legIndex ?: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.mapbox.navigation.utils.internal.MapboxTimer
* This class is responsible for refreshing the current direction route's traffic.
* This does not support alternative routes.
*
* If the route is successfully refreshed, this class will update the [TripSession.route]
* If the route is successfully refreshed, this class will update the [DirectionsSession].
*/
internal class RouteRefreshController(
private val routeRefreshOptions: RouteRefreshOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.mapbox.navigation.core.trip.session
import android.hardware.SensorEvent
import android.location.Location
import android.os.Looper
import androidx.annotation.VisibleForTesting
import com.mapbox.android.core.location.LocationEngineCallback
import com.mapbox.android.core.location.LocationEngineResult
import com.mapbox.api.directions.v5.models.BannerInstructions
Expand Down Expand Up @@ -53,8 +54,6 @@ import java.util.concurrent.CopyOnWriteArraySet
* @param navigator Native navigator
* @param threadController controller for main/io jobs
* @param logger interface for logging any events
*
* @property route should be set to start routing
*/
internal class MapboxTripSession(
override val tripService: TripService,
Expand All @@ -67,8 +66,8 @@ internal class MapboxTripSession(

private var updateRouteJob: Job? = null

override var route: DirectionsRoute? = null
private set
@VisibleForTesting
internal var route: DirectionsRoute? = null

override fun setRoute(route: DirectionsRoute?, legIndex: Int) {
val isSameUuid = route?.isSameUuid(this.route) ?: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.mapbox.navigator.FallbackVersionsObserver
internal interface TripSession {

val tripService: TripService
val route: DirectionsRoute?
fun setRoute(route: DirectionsRoute?, legIndex: Int)

fun getRawLocation(): Location?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ class MapboxNavigationTest {
every {
tripSession.registerFallbackVersionsObserver(capture(fallbackObserverSlot))
} just Runs
every { tripSession.route } returns null
every { directionsSession.routes } returns emptyList()
every { tripSession.getRouteProgress() } returns mockk()

mapboxNavigation = MapboxNavigation(navigationOptions)
Expand Down Expand Up @@ -927,7 +927,7 @@ class MapboxNavigationTest {
every {
tripSession.registerFallbackVersionsObserver(capture(fallbackObserverSlot))
} just Runs
every { tripSession.route } returns null
every { directionsSession.routes } returns emptyList()
every { tripSession.getRouteProgress() } returns mockk()

mapboxNavigation = MapboxNavigation(navigationOptions)
Expand Down Expand Up @@ -961,7 +961,7 @@ class MapboxNavigationTest {
val routeProgress: RouteProgress = mockk()
val legProgress: RouteLegProgress = mockk()
val index = 137
every { tripSession.route } returns route
every { directionsSession.routes } returns listOf(route)
every { tripSession.getRouteProgress() } returns routeProgress
every { routeProgress.currentLegProgress } returns legProgress
every { legProgress.legIndex } returns index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class RouteRefreshControllerTest {
every { legIndex } returns 0
}
}
every { tripSession.route } returns validRoute
every {
directionsSession.requestRouteRefresh(any(), any(), capture(routeRefreshCallbackSlot))
} returns requestId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class MapboxTripSessionTest {
@get:Rule
var coroutineRule = MainCoroutineRule()

private lateinit var tripSession: TripSession
private lateinit var tripSession: MapboxTripSession

private val tripService: TripService = mockk(relaxUnitFun = true) {
every { hasServiceStarted() } returns false
Expand Down Expand Up @@ -179,7 +179,7 @@ class MapboxTripSessionTest {
} answers {}
}

private fun buildTripSession(): TripSession {
private fun buildTripSession(): MapboxTripSession {
return MapboxTripSession(
tripService,
navigationOptions,
Expand Down Expand Up @@ -640,12 +640,6 @@ class MapboxTripSessionTest {
assertEquals(tripService, tripSession.tripService)
}

@Test
fun getRoute() {
tripSession.setRoute(route, legIndex)
assertEquals(route, tripSession.route)
}

@Test
fun setRoute() {
tripSession.setRoute(route, legIndex)
Expand Down

0 comments on commit 4155ade

Please sign in to comment.