Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for unknown lane types #7691

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.mapbox.navigation.instrumentation_tests.core

import android.content.Context
import android.location.Location
import androidx.annotation.IntegerRes
import com.mapbox.api.directions.v5.models.DirectionsRoute
import com.mapbox.navigation.instrumentation_tests.R
import com.mapbox.navigation.instrumentation_tests.utils.readRawFileText
import com.mapbox.navigation.testing.ui.BaseCoreNoCleanUpTest
import com.mapbox.navigation.ui.maneuver.api.MapboxLaneIconsApi
import com.mapbox.navigation.ui.maneuver.model.LaneIconResources
import com.mapbox.navigation.ui.maneuver.model.LaneIndicator
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Test

class LanesTest : BaseCoreNoCleanUpTest() {

@Test
fun testUnknownIndicationTypes() {
val route = getRoute(context, R.raw.route_with_unknown_lane_types)
val lanes = route.legs()?.first()?.steps()?.first()?.intersections()?.first()?.lanes()

assertNotNull(lanes)
requireNotNull(lanes)

assertTrue(lanes.isNotEmpty())
assertEquals(listOf("left", "straight", "unknown"), lanes.first().indications())
assertEquals(listOf("right", "unknown"), lanes.last().indications())
assertEquals("unknown", lanes.last().validIndication())
}

@Test
fun testUnknownLaneTypesRendering() {
val laneIconRes = LaneIconResources.Builder().build()
val laneApi = MapboxLaneIconsApi(laneIconRes)

val inactiveIndicator = LaneIndicator
.Builder()
.drivingSide("right")
.isActive(false)
.directions(listOf("unknown"))
.activeDirection(null)
.build()

val inactiveTurnLane = laneApi.getTurnLane(inactiveIndicator)
assertEquals(laneIconRes.laneStraight, inactiveTurnLane.drawableResId)

val activeIndicator = LaneIndicator
.Builder()
.drivingSide("right")
.isActive(true)
.directions(listOf("unknown", "right"))
.activeDirection("unknown")
.build()

val activeTurnLane = laneApi.getTurnLane(activeIndicator)
assertEquals(laneIconRes.laneStraight, activeTurnLane.drawableResId)
}

private fun getRoute(
context: Context,
@IntegerRes routeFileResource: Int
): DirectionsRoute {
val routeAsString = readRawFileText(context, routeFileResource)
return DirectionsRoute.fromJson(routeAsString)
}

override fun setupMockLocation(): Location {
return mockLocationUpdatesRule.generateLocationUpdate {
// no op
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.mapbox.navigation.instrumentation_tests.core

import android.content.Context
import android.location.Location
import androidx.annotation.IntegerRes
import com.mapbox.api.directions.v5.models.DirectionsRoute
import com.mapbox.navigation.instrumentation_tests.R
import com.mapbox.navigation.instrumentation_tests.utils.readRawFileText
import com.mapbox.navigation.testing.ui.BaseCoreNoCleanUpTest
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Test

class TollCostsTest : BaseCoreNoCleanUpTest() {

@Test
fun testNoTollCostsData() {
val route = getRoute(context, R.raw.route_with_no_toll_costs)
assertNull(route.tollCosts())
}

@Test
fun testEmptyTollCosts() {
val route = getRoute(context, R.raw.route_with_empty_toll_costs)
val tollCosts = route.tollCosts()
assertNotNull(tollCosts)

tollCosts!!
assertEquals(1, tollCosts.size)
assertNull(tollCosts[0].currency())
assertNull(tollCosts[0].paymentMethods())
}

@Test
fun testEmptyTollCostsDataPaymentMethods() {
val route = getRoute(context, R.raw.route_with_empty_toll_costs_payment_data)
val tollCosts = route.tollCosts()
assertNotNull(tollCosts)

tollCosts!!
assertEquals(1, tollCosts.size)
assertEquals("JPY", tollCosts[0].currency())

val paymentMethods = tollCosts[0].paymentMethods()
assertNotNull(paymentMethods)

paymentMethods!!
assertNull(paymentMethods.cash())
assertNull(paymentMethods.etc())
}

private fun getRoute(
context: Context,
@IntegerRes routeFileResource: Int
): DirectionsRoute {
val routeAsString = readRawFileText(context, routeFileResource)
return DirectionsRoute.fromJson(routeAsString)
}

override fun setupMockLocation(): Location {
return mockLocationUpdatesRule.generateLocationUpdate {
// no op
}
}
}
Loading
Loading