|
| 1 | +package com.mapbox.navigation.core |
| 2 | + |
| 3 | +import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI |
| 4 | +import com.mapbox.navigation.base.utils.DecodeUtils |
| 5 | +import com.mapbox.navigation.core.directions.session.RoutesUpdatedResult |
| 6 | +import com.mapbox.navigation.core.preview.RoutesPreview |
| 7 | +import com.mapbox.navigation.core.preview.RoutesPreviewUpdate |
| 8 | +import io.mockk.clearStaticMockk |
| 9 | +import io.mockk.every |
| 10 | +import io.mockk.mockk |
| 11 | +import io.mockk.mockkStatic |
| 12 | +import io.mockk.unmockkStatic |
| 13 | +import io.mockk.verify |
| 14 | +import org.junit.After |
| 15 | +import org.junit.Before |
| 16 | +import org.junit.Test |
| 17 | + |
| 18 | +@OptIn(ExperimentalPreviewMapboxNavigationAPI::class) |
| 19 | +class RoutesCacheClearerTest { |
| 20 | + |
| 21 | + private val sut = RoutesCacheClearer() |
| 22 | + |
| 23 | + @Before |
| 24 | + fun setUp() { |
| 25 | + mockkStatic(DecodeUtils::class) |
| 26 | + } |
| 27 | + |
| 28 | + @After |
| 29 | + fun tearDown() { |
| 30 | + unmockkStatic(DecodeUtils::class) |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + fun onRoutesChanged_emptyNoPreviewedRoutes() { |
| 35 | + sut.onRoutesChanged(RoutesUpdatedResult(emptyList(), "")) |
| 36 | + |
| 37 | + verify(exactly = 1) { DecodeUtils.clearCache() } |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + fun onRoutesChanged_nonEmptyNoPreviewedRoutes() { |
| 42 | + sut.onRoutesChanged(RoutesUpdatedResult(listOf(mockk()), "")) |
| 43 | + |
| 44 | + verify(exactly = 0) { DecodeUtils.clearCache() } |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + fun onRoutesChanged_emptyHasPreviewedRoutes() { |
| 49 | + sut.routesPreviewUpdated( |
| 50 | + RoutesPreviewUpdate("", RoutesPreview(listOf(mockk()), emptyList(), listOf(mockk()), 0)) |
| 51 | + ) |
| 52 | + clearStaticMockk(DecodeUtils::class) |
| 53 | + |
| 54 | + sut.onRoutesChanged(RoutesUpdatedResult(emptyList(), "")) |
| 55 | + |
| 56 | + verify(exactly = 0) { DecodeUtils.clearCache() } |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + fun onRoutesChanged_emptyClearedPreviewedRoutes() { |
| 61 | + sut.routesPreviewUpdated( |
| 62 | + RoutesPreviewUpdate("", RoutesPreview(listOf(mockk()), emptyList(), listOf(mockk()), 0)) |
| 63 | + ) |
| 64 | + sut.routesPreviewUpdated( |
| 65 | + RoutesPreviewUpdate("", mockk { every { routesList } returns emptyList() }) |
| 66 | + ) |
| 67 | + clearStaticMockk(DecodeUtils::class) |
| 68 | + |
| 69 | + sut.onRoutesChanged(RoutesUpdatedResult(emptyList(), "")) |
| 70 | + |
| 71 | + verify(exactly = 1) { DecodeUtils.clearCache() } |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + fun routesPreviewUpdated_nullPreviewAndNoActiveRoutes() { |
| 76 | + sut.routesPreviewUpdated(RoutesPreviewUpdate("", null)) |
| 77 | + |
| 78 | + verify(exactly = 1) { DecodeUtils.clearCache() } |
| 79 | + } |
| 80 | + |
| 81 | + @Test |
| 82 | + fun routesPreviewUpdated_emptyRoutesAndNoActiveRoutes() { |
| 83 | + sut.routesPreviewUpdated( |
| 84 | + RoutesPreviewUpdate("", mockk { every { routesList } returns emptyList() }) |
| 85 | + ) |
| 86 | + |
| 87 | + verify(exactly = 1) { DecodeUtils.clearCache() } |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + fun routesPreviewUpdated_nonEmptyRoutesAndNoActiveRoutes() { |
| 92 | + sut.routesPreviewUpdated( |
| 93 | + RoutesPreviewUpdate("", RoutesPreview(listOf(mockk()), emptyList(), listOf(mockk()), 0)) |
| 94 | + ) |
| 95 | + |
| 96 | + verify(exactly = 0) { DecodeUtils.clearCache() } |
| 97 | + } |
| 98 | + |
| 99 | + @Test |
| 100 | + fun routesPreviewUpdated_nullPreviewAndHasActiveRoutes() { |
| 101 | + sut.onRoutesChanged(RoutesUpdatedResult(listOf(mockk()), "")) |
| 102 | + clearStaticMockk(DecodeUtils::class) |
| 103 | + |
| 104 | + sut.routesPreviewUpdated(RoutesPreviewUpdate("", null)) |
| 105 | + |
| 106 | + verify(exactly = 0) { DecodeUtils.clearCache() } |
| 107 | + } |
| 108 | + |
| 109 | + @Test |
| 110 | + fun routesPreviewUpdated_emptyRoutesAndHasActiveRoutes() { |
| 111 | + sut.onRoutesChanged(RoutesUpdatedResult(listOf(mockk()), "")) |
| 112 | + clearStaticMockk(DecodeUtils::class) |
| 113 | + |
| 114 | + sut.routesPreviewUpdated( |
| 115 | + RoutesPreviewUpdate("", mockk { every { routesList } returns emptyList() }) |
| 116 | + ) |
| 117 | + |
| 118 | + verify(exactly = 0) { DecodeUtils.clearCache() } |
| 119 | + } |
| 120 | + |
| 121 | + @Test |
| 122 | + fun routesPreviewUpdated_nullPreviewAndClearedActiveRoutes() { |
| 123 | + sut.onRoutesChanged(RoutesUpdatedResult(listOf(mockk()), "")) |
| 124 | + sut.onRoutesChanged(RoutesUpdatedResult(emptyList(), "")) |
| 125 | + clearStaticMockk(DecodeUtils::class) |
| 126 | + |
| 127 | + sut.routesPreviewUpdated(RoutesPreviewUpdate("", null)) |
| 128 | + |
| 129 | + verify(exactly = 1) { DecodeUtils.clearCache() } |
| 130 | + } |
| 131 | + |
| 132 | + @Test |
| 133 | + fun routesPreviewUpdated_emptyRoutesAndClearedActiveRoutes() { |
| 134 | + sut.onRoutesChanged(RoutesUpdatedResult(listOf(mockk()), "")) |
| 135 | + sut.onRoutesChanged(RoutesUpdatedResult(emptyList(), "")) |
| 136 | + clearStaticMockk(DecodeUtils::class) |
| 137 | + |
| 138 | + sut.routesPreviewUpdated( |
| 139 | + RoutesPreviewUpdate("", mockk { every { routesList } returns emptyList() }) |
| 140 | + ) |
| 141 | + |
| 142 | + verify(exactly = 1) { DecodeUtils.clearCache() } |
| 143 | + } |
| 144 | +} |
0 commit comments