@@ -6,15 +6,22 @@ import com.mapbox.navigation.base.options.NavigationOptions
6
6
import com.mapbox.navigation.core.MapboxNavigation
7
7
import com.mapbox.navigation.core.TripSessionResetCallback
8
8
import com.mapbox.navigation.core.directions.session.RoutesObserver
9
+ import com.mapbox.navigation.core.history.MapboxHistoryReader
10
+ import com.mapbox.navigation.core.history.MapboxHistoryReaderProvider
9
11
import com.mapbox.navigation.core.replay.MapboxReplayer
10
12
import com.mapbox.navigation.core.trip.session.RouteProgressObserver
11
13
import com.mapbox.navigation.testing.LoggingFrontendTestRule
12
14
import io.mockk.every
13
15
import io.mockk.just
14
16
import io.mockk.mockk
17
+ import io.mockk.mockkObject
15
18
import io.mockk.runs
16
19
import io.mockk.slot
20
+ import io.mockk.unmockkAll
17
21
import io.mockk.verify
22
+ import io.mockk.verifyOrder
23
+ import org.junit.After
24
+ import org.junit.Before
18
25
import org.junit.Rule
19
26
import org.junit.Test
20
27
@@ -25,25 +32,113 @@ class ReplayHistorySessionTest {
25
32
val loggerRule = LoggingFrontendTestRule ()
26
33
27
34
private val replayer: MapboxReplayer = mockk(relaxed = true )
35
+ private val historyReader: MapboxHistoryReader = mockk(relaxed = true )
28
36
29
37
private val sut = ReplayHistorySession ()
30
38
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
+
31
59
@Test
32
- fun `onAttached with startReplayTripSession ` () {
60
+ fun `onAttached will call MapboxReplayer#play ` () {
33
61
val mapboxNavigation = mockMapboxNavigation()
34
62
35
63
sut.onAttached(mapboxNavigation)
36
64
37
- verify { mapboxNavigation.startReplayTripSession () }
65
+ verify(exactly = 1 ) { replayer.play () }
38
66
}
39
67
40
68
@Test
41
- fun `onAttached with call MapboxReplayer#play ` () {
69
+ fun `setHistoryFile after onAttached will clear events and reset the trip ` () {
42
70
val mapboxNavigation = mockMapboxNavigation()
43
71
44
72
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
+ }
45
93
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
+ }
47
142
}
48
143
49
144
private fun mockMapboxNavigation (): MapboxNavigation {
0 commit comments