@@ -34,6 +34,7 @@ import com.mapbox.navigation.core.internal.telemetry.UserFeedbackCallback
3434import com.mapbox.navigation.core.internal.telemetry.registerUserFeedbackCallback
3535import com.mapbox.navigation.core.internal.telemetry.unregisterUserFeedbackCallback
3636import com.mapbox.navigation.core.lifecycle.MapboxNavigationApp
37+ import com.mapbox.navigation.testing.LoggingFrontendTestRule
3738import com.mapbox.navigation.testing.MainCoroutineRule
3839import com.mapbox.navigation.utils.internal.DefaultLifecycleObserver
3940import com.mapbox.navigation.utils.internal.logD
@@ -73,6 +74,9 @@ class MapboxCopilotImplTest {
7374 @get:Rule
7475 val coroutineRule = MainCoroutineRule ()
7576
77+ @get:Rule
78+ val loggingFrontendTestRule = LoggingFrontendTestRule ()
79+
7680 @Before
7781 fun setUp () {
7882 mockkStatic(SystemClock ::elapsedRealtime)
@@ -463,6 +467,30 @@ class MapboxCopilotImplTest {
463467 verify(exactly = 1 ) { mockedAppLifecycle.removeObserver(any()) }
464468 }
465469
470+ @Test
471+ fun `activity Lifecycle Callbacks is unregistered when stop if MapboxNavigationApp is not setup` () {
472+ val mockedMapboxNavigation = prepareBasicMockks()
473+ val mockedAppLifecycle = prepareCarAppLifecycleOwnerMockk()
474+ val historyRecordingStateChangeObserver = slot<HistoryRecordingStateChangeObserver >()
475+ every {
476+ mockedMapboxNavigation.registerHistoryRecordingStateChangeObserver(
477+ capture(historyRecordingStateChangeObserver)
478+ )
479+ } just Runs
480+ val mapboxCopilot = createMapboxCopilotImplementation(mockedMapboxNavigation)
481+ mapboxCopilot.start()
482+ val activeGuidanceHistoryRecordingSessionState =
483+ mockk<HistoryRecordingSessionState .ActiveGuidance >(relaxed = true )
484+ historyRecordingStateChangeObserver.captured.onShouldStartRecording(
485+ activeGuidanceHistoryRecordingSessionState
486+ )
487+
488+ mapboxCopilot.stop()
489+
490+ verify(exactly = 1 ) { anyConstructed<CarAppLifecycleOwner >().attachAllActivities(any()) }
491+ verify(exactly = 1 ) { anyConstructed<CarAppLifecycleOwner >().detachAllActivities(any()) }
492+ }
493+
466494 @Test
467495 fun `unregisterHistoryRecordingStateChangeObserver is called when stop` () {
468496 val mockedMapboxNavigation = prepareBasicMockks()
0 commit comments