@@ -6,15 +6,22 @@ import com.mapbox.navigation.base.options.NavigationOptions
66import com.mapbox.navigation.core.MapboxNavigation
77import com.mapbox.navigation.core.TripSessionResetCallback
88import com.mapbox.navigation.core.directions.session.RoutesObserver
9+ import com.mapbox.navigation.core.history.MapboxHistoryReader
10+ import com.mapbox.navigation.core.history.MapboxHistoryReaderProvider
911import com.mapbox.navigation.core.replay.MapboxReplayer
1012import com.mapbox.navigation.core.trip.session.RouteProgressObserver
1113import com.mapbox.navigation.testing.LoggingFrontendTestRule
1214import io.mockk.every
1315import io.mockk.just
1416import io.mockk.mockk
17+ import io.mockk.mockkObject
1518import io.mockk.runs
1619import io.mockk.slot
20+ import io.mockk.unmockkAll
1721import io.mockk.verify
22+ import io.mockk.verifyOrder
23+ import org.junit.After
24+ import org.junit.Before
1825import org.junit.Rule
1926import org.junit.Test
2027
@@ -25,25 +32,113 @@ class ReplayHistorySessionTest {
2532 val loggerRule = LoggingFrontendTestRule ()
2633
2734 private val replayer: MapboxReplayer = mockk(relaxed = true )
35+ private val historyReader: MapboxHistoryReader = mockk(relaxed = true )
2836
2937 private val sut = ReplayHistorySession ()
3038
39+ @Before
40+ fun setup () {
41+ mockkObject(MapboxHistoryReaderProvider )
42+ every { MapboxHistoryReaderProvider .create(any()) } returns historyReader
43+ }
44+
45+ @After
46+ fun teardown () {
47+ unmockkAll()
48+ }
49+
50+ @Test
51+ fun `onAttached will call startReplayTripSession` () {
52+ val mapboxNavigation = mockMapboxNavigation()
53+
54+ sut.onAttached(mapboxNavigation)
55+
56+ verify(exactly = 1 ) { mapboxNavigation.startReplayTripSession() }
57+ }
58+
3159 @Test
32- fun `onAttached with startReplayTripSession ` () {
60+ fun `onAttached will call MapboxReplayer#play ` () {
3361 val mapboxNavigation = mockMapboxNavigation()
3462
3563 sut.onAttached(mapboxNavigation)
3664
37- verify { mapboxNavigation.startReplayTripSession () }
65+ verify(exactly = 1 ) { replayer.play () }
3866 }
3967
4068 @Test
41- fun `onAttached with call MapboxReplayer#play ` () {
69+ fun `setHistoryFile after onAttached will clear events and reset the trip ` () {
4270 val mapboxNavigation = mockMapboxNavigation()
4371
4472 sut.onAttached(mapboxNavigation)
73+ sut.setHistoryFile(" test_file_path" )
74+
75+ verifyOrder {
76+ mapboxNavigation.startReplayTripSession()
77+ replayer.clearEvents()
78+ mapboxNavigation.setNavigationRoutes(emptyList())
79+ mapboxNavigation.resetTripSession(any())
80+ replayer.play()
81+ // setHistoryFile was called
82+ replayer.clearEvents()
83+ mapboxNavigation.setNavigationRoutes(emptyList())
84+ MapboxHistoryReaderProvider .create(" test_file_path" )
85+ mapboxNavigation.resetTripSession(any())
86+ replayer.play()
87+ }
88+ verify(exactly = 1 ) {
89+ mapboxNavigation.startReplayTripSession()
90+ MapboxHistoryReaderProvider .create(any())
91+ }
92+ }
4593
46- verify { replayer.play() }
94+ @Test
95+ fun `setHistoryFile before onAttached will initialize once` () {
96+ val mapboxNavigation = mockMapboxNavigation()
97+
98+ sut.setHistoryFile(" test_file_path" )
99+ sut.onAttached(mapboxNavigation)
100+
101+ verifyOrder {
102+ mapboxNavigation.startReplayTripSession()
103+ replayer.clearEvents()
104+ mapboxNavigation.setNavigationRoutes(emptyList())
105+ MapboxHistoryReaderProvider .create(" test_file_path" )
106+ mapboxNavigation.resetTripSession(any())
107+ replayer.play()
108+ }
109+ verify(exactly = 1 ) {
110+ mapboxNavigation.startReplayTripSession()
111+ replayer.clearEvents()
112+ mapboxNavigation.setNavigationRoutes(any())
113+ MapboxHistoryReaderProvider .create(any())
114+ mapboxNavigation.resetTripSession(any())
115+ replayer.play()
116+ }
117+ }
118+
119+ @Test
120+ fun `onDetached will clean up but will not stopTripSession` () {
121+ val mapboxNavigation = mockMapboxNavigation()
122+
123+ sut.onAttached(mapboxNavigation)
124+ sut.onDetached(mapboxNavigation)
125+
126+ verifyOrder {
127+ mapboxNavigation.startReplayTripSession()
128+ replayer.stop()
129+ replayer.registerObserver(any())
130+ replayer.clearEvents()
131+ mapboxNavigation.setNavigationRoutes(emptyList())
132+ mapboxNavigation.resetTripSession(any())
133+ replayer.play()
134+ // onDetached called
135+ replayer.unregisterObserver(any())
136+ replayer.stop()
137+ replayer.clearEvents()
138+ }
139+ verify(exactly = 1 ) {
140+ replayer.play()
141+ }
47142 }
48143
49144 private fun mockMapboxNavigation (): MapboxNavigation {
0 commit comments