Skip to content

Commit

Permalink
Fix issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kmadsen committed Aug 30, 2022
1 parent 254b936 commit 027af78
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ internal class MapboxNavigationOwner {
attached = false
services.forEach { it.onDetached(mapboxNavigation!!) }
MapboxNavigationProvider.destroy()
mapboxNavigation = null
logI("disabled ${services.size} observers", LOG_CATEGORY)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,23 @@ class MapboxNavigationAppDelegateTest {
verify(exactly = 1) { observer.onAttached(any()) }
}

@Test
fun `verify disable will detach and current becomes null`() {
mapboxNavigationApp.setup { navigationOptions }

val testLifecycleOwner = CarAppLifecycleOwnerTest.TestLifecycleOwner()
mapboxNavigationApp.attach(testLifecycleOwner)
testLifecycleOwner.lifecycleRegistry.currentState = Lifecycle.State.RESUMED

val observer = mockk<MapboxNavigationObserver>(relaxUnitFun = true)
mapboxNavigationApp.registerObserver(observer)
mapboxNavigationApp.disable()
mapboxNavigationApp.unregisterObserver(observer)

assertNull(MapboxNavigationApp.current())
verify(exactly = 1) { observer.onDetached(any()) }
}

@Test
fun `verify current is null when all lifecycle owners are destroyed`() {
mapboxNavigationApp.setup { navigationOptions }
Expand Down

0 comments on commit 027af78

Please sign in to comment.