[android] fixing ktlint issues
This commit is contained in:
@@ -18,310 +18,310 @@ import org.junit.Test
|
||||
|
||||
class IndicatorLocationLayerRendererTest {
|
||||
|
||||
private val style: Style = mockk(relaxUnitFun = true)
|
||||
private val layerSourceProvider: LayerSourceProvider = mockk(relaxUnitFun = true)
|
||||
private val layer: Layer = mockk(relaxUnitFun = true)
|
||||
private val style: Style = mockk(relaxUnitFun = true)
|
||||
private val layerSourceProvider: LayerSourceProvider = mockk(relaxUnitFun = true)
|
||||
private val layer: Layer = mockk(relaxUnitFun = true)
|
||||
|
||||
private lateinit var locationLayerRenderer: IndicatorLocationLayerRenderer
|
||||
private lateinit var locationLayerRenderer: IndicatorLocationLayerRenderer
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
every { style.removeLayer(any<Layer>()) } returns true
|
||||
locationLayerRenderer = IndicatorLocationLayerRenderer(layerSourceProvider)
|
||||
every { layerSourceProvider.generateLocationComponentLayer() } returns layer
|
||||
locationLayerRenderer.initializeComponents(style)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun sanity() {
|
||||
Assert.assertNotNull(locationLayerRenderer)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun initializeComponents_withLocation() {
|
||||
val newLayer: Layer = mockk(relaxUnitFun = true)
|
||||
every { layerSourceProvider.generateLocationComponentLayer() } returns newLayer
|
||||
val latLng = LatLng(10.0, 20.0)
|
||||
val bearing = 11f
|
||||
val accuracy = 65f
|
||||
locationLayerRenderer.setLatLng(latLng)
|
||||
locationLayerRenderer.setGpsBearing(bearing)
|
||||
locationLayerRenderer.setAccuracyRadius(accuracy)
|
||||
|
||||
locationLayerRenderer.initializeComponents(mockk())
|
||||
|
||||
verify { newLayer.setProperties(LocationPropertyFactory.location(latLng.toLocationArray())) }
|
||||
verify { newLayer.setProperties(LocationPropertyFactory.bearing(bearing.toDouble())) }
|
||||
verify { newLayer.setProperties(LocationPropertyFactory.accuracyRadius(accuracy)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addLayers() {
|
||||
val positionManager: LocationComponentPositionManager = mockk(relaxUnitFun = true)
|
||||
|
||||
locationLayerRenderer.addLayers(positionManager)
|
||||
|
||||
verify { positionManager.addLayerToMap(layer) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun removeLayers() {
|
||||
locationLayerRenderer.removeLayers()
|
||||
|
||||
verify { style.removeLayer(layer) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun hide() {
|
||||
locationLayerRenderer.hide()
|
||||
|
||||
verify { layer.setProperties(LocationPropertyFactory.visibility(Property.NONE)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun show() {
|
||||
locationLayerRenderer.show(RenderMode.NORMAL, false)
|
||||
|
||||
verify { layer.setProperties(LocationPropertyFactory.visibility(Property.VISIBLE)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun show_normal_notStale() {
|
||||
locationLayerRenderer.show(RenderMode.NORMAL, false)
|
||||
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.topImage(FOREGROUND_ICON),
|
||||
LocationPropertyFactory.bearingImage(BACKGROUND_ICON),
|
||||
LocationPropertyFactory.shadowImage(SHADOW_ICON)
|
||||
)
|
||||
@Before
|
||||
fun setup() {
|
||||
every { style.removeLayer(any<Layer>()) } returns true
|
||||
locationLayerRenderer = IndicatorLocationLayerRenderer(layerSourceProvider)
|
||||
every { layerSourceProvider.generateLocationComponentLayer() } returns layer
|
||||
locationLayerRenderer.initializeComponents(style)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun show_compass_notStale() {
|
||||
locationLayerRenderer.show(RenderMode.COMPASS, false)
|
||||
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.topImage(FOREGROUND_ICON),
|
||||
LocationPropertyFactory.bearingImage(BEARING_ICON),
|
||||
LocationPropertyFactory.shadowImage(SHADOW_ICON)
|
||||
)
|
||||
@Test
|
||||
fun sanity() {
|
||||
Assert.assertNotNull(locationLayerRenderer)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun show_gps_notStale() {
|
||||
locationLayerRenderer.show(RenderMode.GPS, false)
|
||||
@Test
|
||||
fun initializeComponents_withLocation() {
|
||||
val newLayer: Layer = mockk(relaxUnitFun = true)
|
||||
every { layerSourceProvider.generateLocationComponentLayer() } returns newLayer
|
||||
val latLng = LatLng(10.0, 20.0)
|
||||
val bearing = 11f
|
||||
val accuracy = 65f
|
||||
locationLayerRenderer.setLatLng(latLng)
|
||||
locationLayerRenderer.setGpsBearing(bearing)
|
||||
locationLayerRenderer.setAccuracyRadius(accuracy)
|
||||
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.topImage(""),
|
||||
LocationPropertyFactory.bearingImage(FOREGROUND_ICON),
|
||||
LocationPropertyFactory.shadowImage(BACKGROUND_ICON)
|
||||
)
|
||||
locationLayerRenderer.initializeComponents(mockk())
|
||||
|
||||
verify { newLayer.setProperties(LocationPropertyFactory.location(latLng.toLocationArray())) }
|
||||
verify { newLayer.setProperties(LocationPropertyFactory.bearing(bearing.toDouble())) }
|
||||
verify { newLayer.setProperties(LocationPropertyFactory.accuracyRadius(accuracy)) }
|
||||
}
|
||||
verify { layer.setProperties(LocationPropertyFactory.accuracyRadius(0f)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun show_normal_stale() {
|
||||
locationLayerRenderer.show(RenderMode.NORMAL, true)
|
||||
@Test
|
||||
fun addLayers() {
|
||||
val positionManager: LocationComponentPositionManager = mockk(relaxUnitFun = true)
|
||||
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.topImage(FOREGROUND_STALE_ICON),
|
||||
LocationPropertyFactory.bearingImage(BACKGROUND_STALE_ICON),
|
||||
LocationPropertyFactory.shadowImage(SHADOW_ICON)
|
||||
)
|
||||
locationLayerRenderer.addLayers(positionManager)
|
||||
|
||||
verify { positionManager.addLayerToMap(layer) }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun show_compass_stale() {
|
||||
locationLayerRenderer.show(RenderMode.COMPASS, true)
|
||||
@Test
|
||||
fun removeLayers() {
|
||||
locationLayerRenderer.removeLayers()
|
||||
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.topImage(FOREGROUND_STALE_ICON),
|
||||
LocationPropertyFactory.bearingImage(BEARING_STALE_ICON),
|
||||
LocationPropertyFactory.shadowImage(SHADOW_ICON)
|
||||
)
|
||||
verify { style.removeLayer(layer) }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun show_gps_stale() {
|
||||
locationLayerRenderer.show(RenderMode.GPS, true)
|
||||
@Test
|
||||
fun hide() {
|
||||
locationLayerRenderer.hide()
|
||||
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.topImage(""),
|
||||
LocationPropertyFactory.bearingImage(FOREGROUND_STALE_ICON),
|
||||
LocationPropertyFactory.shadowImage(BACKGROUND_STALE_ICON)
|
||||
)
|
||||
verify { layer.setProperties(LocationPropertyFactory.visibility(Property.NONE)) }
|
||||
}
|
||||
verify { layer.setProperties(LocationPropertyFactory.accuracyRadius(0f)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun styleAccuracy() {
|
||||
val colorArray = ColorUtils.colorToRgbaArray(Color.RED)
|
||||
val exp = Expression.rgba(colorArray[0], colorArray[1], colorArray[2], 0.7f)
|
||||
@Test
|
||||
fun show() {
|
||||
locationLayerRenderer.show(RenderMode.NORMAL, false)
|
||||
|
||||
locationLayerRenderer.styleAccuracy(0.7f, Color.RED)
|
||||
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.accuracyRadiusColor(exp),
|
||||
LocationPropertyFactory.accuracyRadiusBorderColor(exp)
|
||||
)
|
||||
verify { layer.setProperties(LocationPropertyFactory.visibility(Property.VISIBLE)) }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun setLatLng() {
|
||||
val latLng = LatLng(10.0, 20.0)
|
||||
locationLayerRenderer.setLatLng(latLng)
|
||||
@Test
|
||||
fun show_normal_notStale() {
|
||||
locationLayerRenderer.show(RenderMode.NORMAL, false)
|
||||
|
||||
verify { layer.setProperties(LocationPropertyFactory.location(latLng.toLocationArray())) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun setGpsBearing() {
|
||||
val bearing = 30.0
|
||||
locationLayerRenderer.setGpsBearing(bearing.toFloat())
|
||||
|
||||
verify { layer.setProperties(LocationPropertyFactory.bearing(bearing)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun setCompassBearing() {
|
||||
val bearing = 30.0
|
||||
locationLayerRenderer.setCompassBearing(bearing.toFloat())
|
||||
|
||||
verify { layer.setProperties(LocationPropertyFactory.bearing(bearing)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun setAccuracyRadius() {
|
||||
val radius = 40f
|
||||
locationLayerRenderer.setAccuracyRadius(radius)
|
||||
|
||||
verify { layer.setProperties(LocationPropertyFactory.accuracyRadius(radius)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun styleScaling() {
|
||||
val exp = Expression.literal("")
|
||||
locationLayerRenderer.styleScaling(exp)
|
||||
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.shadowImageSize(exp),
|
||||
LocationPropertyFactory.bearingImageSize(exp),
|
||||
LocationPropertyFactory.topImageSize(exp)
|
||||
)
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.topImage(FOREGROUND_ICON),
|
||||
LocationPropertyFactory.bearingImage(BACKGROUND_ICON),
|
||||
LocationPropertyFactory.shadowImage(SHADOW_ICON)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun setLocationStale() {
|
||||
locationLayerRenderer.setLocationStale(true, RenderMode.NORMAL)
|
||||
@Test
|
||||
fun show_compass_notStale() {
|
||||
locationLayerRenderer.show(RenderMode.COMPASS, false)
|
||||
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.topImage(FOREGROUND_STALE_ICON),
|
||||
LocationPropertyFactory.bearingImage(BACKGROUND_STALE_ICON),
|
||||
LocationPropertyFactory.shadowImage(SHADOW_ICON)
|
||||
)
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.topImage(FOREGROUND_ICON),
|
||||
LocationPropertyFactory.bearingImage(BEARING_ICON),
|
||||
LocationPropertyFactory.shadowImage(SHADOW_ICON)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addBitmaps_shadow() {
|
||||
addBitmaps(withShadow = true, renderMode = RenderMode.NORMAL)
|
||||
@Test
|
||||
fun show_gps_notStale() {
|
||||
locationLayerRenderer.show(RenderMode.GPS, false)
|
||||
|
||||
verify { style.addImage(SHADOW_ICON, shadowBitmap) }
|
||||
}
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.topImage(""),
|
||||
LocationPropertyFactory.bearingImage(FOREGROUND_ICON),
|
||||
LocationPropertyFactory.shadowImage(BACKGROUND_ICON)
|
||||
)
|
||||
}
|
||||
verify { layer.setProperties(LocationPropertyFactory.accuracyRadius(0f)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addBitmaps_noShadow() {
|
||||
addBitmaps(withShadow = false, renderMode = RenderMode.NORMAL)
|
||||
@Test
|
||||
fun show_normal_stale() {
|
||||
locationLayerRenderer.show(RenderMode.NORMAL, true)
|
||||
|
||||
verify { style.removeImage(SHADOW_ICON) }
|
||||
}
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.topImage(FOREGROUND_STALE_ICON),
|
||||
LocationPropertyFactory.bearingImage(BACKGROUND_STALE_ICON),
|
||||
LocationPropertyFactory.shadowImage(SHADOW_ICON)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addBitmaps_normal() {
|
||||
addBitmaps(withShadow = true, renderMode = RenderMode.NORMAL)
|
||||
@Test
|
||||
fun show_compass_stale() {
|
||||
locationLayerRenderer.show(RenderMode.COMPASS, true)
|
||||
|
||||
verify { style.addImage(FOREGROUND_ICON, foregroundBitmap) }
|
||||
verify { style.addImage(FOREGROUND_STALE_ICON, foregroundStaleBitmap) }
|
||||
verify { style.addImage(BACKGROUND_ICON, backgroundBitmap) }
|
||||
verify { style.addImage(BACKGROUND_STALE_ICON, backgroundStaleBitmap) }
|
||||
verify { style.addImage(BEARING_ICON, bearingBitmap) }
|
||||
}
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.topImage(FOREGROUND_STALE_ICON),
|
||||
LocationPropertyFactory.bearingImage(BEARING_STALE_ICON),
|
||||
LocationPropertyFactory.shadowImage(SHADOW_ICON)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addBitmaps_compass() {
|
||||
every { bearingBitmap.width } returns 40
|
||||
every { bearingBitmap.height } returns 40
|
||||
every { bearingBitmap.config } returns mockk()
|
||||
every { backgroundBitmap.width } returns 20
|
||||
every { backgroundBitmap.height } returns 10
|
||||
@Test
|
||||
fun show_gps_stale() {
|
||||
locationLayerRenderer.show(RenderMode.GPS, true)
|
||||
|
||||
val mergedBitmap = mockk<Bitmap>()
|
||||
mockkStatic(BitmapUtils::class)
|
||||
every { BitmapUtils.mergeBitmap(bearingBitmap, backgroundBitmap, 10f, 15f) } returns mergedBitmap
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.topImage(""),
|
||||
LocationPropertyFactory.bearingImage(FOREGROUND_STALE_ICON),
|
||||
LocationPropertyFactory.shadowImage(BACKGROUND_STALE_ICON)
|
||||
)
|
||||
}
|
||||
verify { layer.setProperties(LocationPropertyFactory.accuracyRadius(0f)) }
|
||||
}
|
||||
|
||||
every { bearingBitmap.width } returns 40
|
||||
every { bearingBitmap.height } returns 40
|
||||
every { bearingBitmap.config } returns mockk()
|
||||
every { backgroundStaleBitmap.width } returns 30
|
||||
every { backgroundStaleBitmap.height } returns 10
|
||||
@Test
|
||||
fun styleAccuracy() {
|
||||
val colorArray = ColorUtils.colorToRgbaArray(Color.RED)
|
||||
val exp = Expression.rgba(colorArray[0], colorArray[1], colorArray[2], 0.7f)
|
||||
|
||||
val mergedStaleBitmap = mockk<Bitmap>()
|
||||
every { BitmapUtils.mergeBitmap(bearingBitmap, backgroundStaleBitmap, 5f, 15f) } returns mergedStaleBitmap
|
||||
locationLayerRenderer.styleAccuracy(0.7f, Color.RED)
|
||||
|
||||
addBitmaps(withShadow = true, renderMode = RenderMode.COMPASS)
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.accuracyRadiusColor(exp),
|
||||
LocationPropertyFactory.accuracyRadiusBorderColor(exp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
verify { style.addImage(BEARING_ICON, mergedBitmap) }
|
||||
verify { style.addImage(BEARING_STALE_ICON, mergedStaleBitmap) }
|
||||
@Test
|
||||
fun setLatLng() {
|
||||
val latLng = LatLng(10.0, 20.0)
|
||||
locationLayerRenderer.setLatLng(latLng)
|
||||
|
||||
unmockkStatic(BitmapUtils::class)
|
||||
}
|
||||
verify { layer.setProperties(LocationPropertyFactory.location(latLng.toLocationArray())) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addBitmaps_gps() {
|
||||
addBitmaps(withShadow = true, renderMode = RenderMode.GPS)
|
||||
@Test
|
||||
fun setGpsBearing() {
|
||||
val bearing = 30.0
|
||||
locationLayerRenderer.setGpsBearing(bearing.toFloat())
|
||||
|
||||
verify { style.addImage(FOREGROUND_ICON, foregroundBitmap) }
|
||||
verify { style.addImage(FOREGROUND_STALE_ICON, foregroundStaleBitmap) }
|
||||
verify { style.addImage(BACKGROUND_ICON, backgroundBitmap) }
|
||||
verify { style.addImage(BACKGROUND_STALE_ICON, backgroundStaleBitmap) }
|
||||
verify { style.addImage(BEARING_ICON, bearingBitmap) }
|
||||
}
|
||||
verify { layer.setProperties(LocationPropertyFactory.bearing(bearing)) }
|
||||
}
|
||||
|
||||
private val shadowBitmap = mockk<Bitmap>()
|
||||
private val backgroundBitmap = mockk<Bitmap>()
|
||||
private val backgroundStaleBitmap = mockk<Bitmap>()
|
||||
private val bearingBitmap = mockk<Bitmap>()
|
||||
private val foregroundBitmap = mockk<Bitmap>()
|
||||
private val foregroundStaleBitmap = mockk<Bitmap>()
|
||||
@Test
|
||||
fun setCompassBearing() {
|
||||
val bearing = 30.0
|
||||
locationLayerRenderer.setCompassBearing(bearing.toFloat())
|
||||
|
||||
private fun addBitmaps(withShadow: Boolean, @RenderMode.Mode renderMode: Int) {
|
||||
locationLayerRenderer.addBitmaps(
|
||||
renderMode,
|
||||
if (withShadow) shadowBitmap else null,
|
||||
backgroundBitmap,
|
||||
backgroundStaleBitmap,
|
||||
bearingBitmap,
|
||||
foregroundBitmap,
|
||||
foregroundStaleBitmap
|
||||
)
|
||||
}
|
||||
verify { layer.setProperties(LocationPropertyFactory.bearing(bearing)) }
|
||||
}
|
||||
|
||||
private fun LatLng.toLocationArray() = arrayOf(latitude, longitude, 0.0)
|
||||
}
|
||||
@Test
|
||||
fun setAccuracyRadius() {
|
||||
val radius = 40f
|
||||
locationLayerRenderer.setAccuracyRadius(radius)
|
||||
|
||||
verify { layer.setProperties(LocationPropertyFactory.accuracyRadius(radius)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun styleScaling() {
|
||||
val exp = Expression.literal("")
|
||||
locationLayerRenderer.styleScaling(exp)
|
||||
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.shadowImageSize(exp),
|
||||
LocationPropertyFactory.bearingImageSize(exp),
|
||||
LocationPropertyFactory.topImageSize(exp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun setLocationStale() {
|
||||
locationLayerRenderer.setLocationStale(true, RenderMode.NORMAL)
|
||||
|
||||
verify {
|
||||
layer.setProperties(
|
||||
LocationPropertyFactory.topImage(FOREGROUND_STALE_ICON),
|
||||
LocationPropertyFactory.bearingImage(BACKGROUND_STALE_ICON),
|
||||
LocationPropertyFactory.shadowImage(SHADOW_ICON)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addBitmaps_shadow() {
|
||||
addBitmaps(withShadow = true, renderMode = RenderMode.NORMAL)
|
||||
|
||||
verify { style.addImage(SHADOW_ICON, shadowBitmap) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addBitmaps_noShadow() {
|
||||
addBitmaps(withShadow = false, renderMode = RenderMode.NORMAL)
|
||||
|
||||
verify { style.removeImage(SHADOW_ICON) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addBitmaps_normal() {
|
||||
addBitmaps(withShadow = true, renderMode = RenderMode.NORMAL)
|
||||
|
||||
verify { style.addImage(FOREGROUND_ICON, foregroundBitmap) }
|
||||
verify { style.addImage(FOREGROUND_STALE_ICON, foregroundStaleBitmap) }
|
||||
verify { style.addImage(BACKGROUND_ICON, backgroundBitmap) }
|
||||
verify { style.addImage(BACKGROUND_STALE_ICON, backgroundStaleBitmap) }
|
||||
verify { style.addImage(BEARING_ICON, bearingBitmap) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addBitmaps_compass() {
|
||||
every { bearingBitmap.width } returns 40
|
||||
every { bearingBitmap.height } returns 40
|
||||
every { bearingBitmap.config } returns mockk()
|
||||
every { backgroundBitmap.width } returns 20
|
||||
every { backgroundBitmap.height } returns 10
|
||||
|
||||
val mergedBitmap = mockk<Bitmap>()
|
||||
mockkStatic(BitmapUtils::class)
|
||||
every { BitmapUtils.mergeBitmap(bearingBitmap, backgroundBitmap, 10f, 15f) } returns mergedBitmap
|
||||
|
||||
every { bearingBitmap.width } returns 40
|
||||
every { bearingBitmap.height } returns 40
|
||||
every { bearingBitmap.config } returns mockk()
|
||||
every { backgroundStaleBitmap.width } returns 30
|
||||
every { backgroundStaleBitmap.height } returns 10
|
||||
|
||||
val mergedStaleBitmap = mockk<Bitmap>()
|
||||
every { BitmapUtils.mergeBitmap(bearingBitmap, backgroundStaleBitmap, 5f, 15f) } returns mergedStaleBitmap
|
||||
|
||||
addBitmaps(withShadow = true, renderMode = RenderMode.COMPASS)
|
||||
|
||||
verify { style.addImage(BEARING_ICON, mergedBitmap) }
|
||||
verify { style.addImage(BEARING_STALE_ICON, mergedStaleBitmap) }
|
||||
|
||||
unmockkStatic(BitmapUtils::class)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addBitmaps_gps() {
|
||||
addBitmaps(withShadow = true, renderMode = RenderMode.GPS)
|
||||
|
||||
verify { style.addImage(FOREGROUND_ICON, foregroundBitmap) }
|
||||
verify { style.addImage(FOREGROUND_STALE_ICON, foregroundStaleBitmap) }
|
||||
verify { style.addImage(BACKGROUND_ICON, backgroundBitmap) }
|
||||
verify { style.addImage(BACKGROUND_STALE_ICON, backgroundStaleBitmap) }
|
||||
verify { style.addImage(BEARING_ICON, bearingBitmap) }
|
||||
}
|
||||
|
||||
private val shadowBitmap = mockk<Bitmap>()
|
||||
private val backgroundBitmap = mockk<Bitmap>()
|
||||
private val backgroundStaleBitmap = mockk<Bitmap>()
|
||||
private val bearingBitmap = mockk<Bitmap>()
|
||||
private val foregroundBitmap = mockk<Bitmap>()
|
||||
private val foregroundStaleBitmap = mockk<Bitmap>()
|
||||
|
||||
private fun addBitmaps(withShadow: Boolean, @RenderMode.Mode renderMode: Int) {
|
||||
locationLayerRenderer.addBitmaps(
|
||||
renderMode,
|
||||
if (withShadow) shadowBitmap else null,
|
||||
backgroundBitmap,
|
||||
backgroundStaleBitmap,
|
||||
bearingBitmap,
|
||||
foregroundBitmap,
|
||||
foregroundStaleBitmap
|
||||
)
|
||||
}
|
||||
|
||||
private fun LatLng.toLocationArray() = arrayOf(latitude, longitude, 0.0)
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -14,117 +14,117 @@ import org.mockito.junit.MockitoJUnitRunner
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class LocationComponentPositionManagerTest {
|
||||
|
||||
private lateinit var style: Style
|
||||
private lateinit var layer: Layer
|
||||
private lateinit var style: Style
|
||||
private lateinit var layer: Layer
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
style = mockk(relaxed = true)
|
||||
layer = mockk(relaxed = true)
|
||||
}
|
||||
@Before
|
||||
fun setup() {
|
||||
style = mockk(relaxed = true)
|
||||
layer = mockk(relaxed = true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_noChange_null() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
val requiresUpdate = positionManager.update(null, null)
|
||||
assertFalse(requiresUpdate)
|
||||
}
|
||||
@Test
|
||||
fun update_noChange_null() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
val requiresUpdate = positionManager.update(null, null)
|
||||
assertFalse(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_noChange_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, "above", null)
|
||||
val requiresUpdate = positionManager.update("above", null)
|
||||
assertFalse(requiresUpdate)
|
||||
}
|
||||
@Test
|
||||
fun update_noChange_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, "above", null)
|
||||
val requiresUpdate = positionManager.update("above", null)
|
||||
assertFalse(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_noChange_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, "below")
|
||||
val requiresUpdate = positionManager.update(null, "below")
|
||||
assertFalse(requiresUpdate)
|
||||
}
|
||||
@Test
|
||||
fun update_noChange_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, "below")
|
||||
val requiresUpdate = positionManager.update(null, "below")
|
||||
assertFalse(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_fromNull_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
val requiresUpdate = positionManager.update("above", null)
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
@Test
|
||||
fun update_fromNull_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
val requiresUpdate = positionManager.update("above", null)
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_fromNull_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
val requiresUpdate = positionManager.update(null, "below")
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
@Test
|
||||
fun update_fromNull_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
val requiresUpdate = positionManager.update(null, "below")
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_toNull_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, "above", null)
|
||||
val requiresUpdate = positionManager.update(null, null)
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
@Test
|
||||
fun update_toNull_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, "above", null)
|
||||
val requiresUpdate = positionManager.update(null, null)
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_toNull_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, "below")
|
||||
val requiresUpdate = positionManager.update(null, null)
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
@Test
|
||||
fun update_toNull_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, "below")
|
||||
val requiresUpdate = positionManager.update(null, null)
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_fromValue_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, "above1", null)
|
||||
val requiresUpdate = positionManager.update("above2", null)
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
@Test
|
||||
fun update_fromValue_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, "above1", null)
|
||||
val requiresUpdate = positionManager.update("above2", null)
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun update_fromValue_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, "below1")
|
||||
val requiresUpdate = positionManager.update(null, "below2")
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
@Test
|
||||
fun update_fromValue_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, "below1")
|
||||
val requiresUpdate = positionManager.update(null, "below2")
|
||||
assertTrue(requiresUpdate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addLayer_noModifier() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
positionManager.addLayerToMap(layer)
|
||||
@Test
|
||||
fun addLayer_noModifier() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
positionManager.addLayerToMap(layer)
|
||||
|
||||
verify { style.addLayer(layer) }
|
||||
}
|
||||
verify { style.addLayer(layer) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addLayer_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, "above", null)
|
||||
positionManager.addLayerToMap(layer)
|
||||
@Test
|
||||
fun addLayer_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, "above", null)
|
||||
positionManager.addLayerToMap(layer)
|
||||
|
||||
verify { style.addLayerAbove(layer, "above") }
|
||||
}
|
||||
verify { style.addLayerAbove(layer, "above") }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addLayer_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, "below")
|
||||
positionManager.addLayerToMap(layer)
|
||||
@Test
|
||||
fun addLayer_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, "below")
|
||||
positionManager.addLayerToMap(layer)
|
||||
|
||||
verify { style.addLayerBelow(layer, "below") }
|
||||
}
|
||||
verify { style.addLayerBelow(layer, "below") }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addLayer_afterUpdate_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
positionManager.update("above", null)
|
||||
positionManager.addLayerToMap(layer)
|
||||
@Test
|
||||
fun addLayer_afterUpdate_above() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
positionManager.update("above", null)
|
||||
positionManager.addLayerToMap(layer)
|
||||
|
||||
verify { style.addLayerAbove(layer, "above") }
|
||||
}
|
||||
verify { style.addLayerAbove(layer, "above") }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addLayer_afterUpdate_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
positionManager.update(null, "below")
|
||||
positionManager.addLayerToMap(layer)
|
||||
@Test
|
||||
fun addLayer_afterUpdate_below() {
|
||||
val positionManager = LocationComponentPositionManager(style, null, null)
|
||||
positionManager.update(null, "below")
|
||||
positionManager.addLayerToMap(layer)
|
||||
|
||||
verify { style.addLayerBelow(layer, "below") }
|
||||
}
|
||||
}
|
||||
verify { style.addLayerBelow(layer, "below") }
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -11,33 +11,33 @@ import org.robolectric.RobolectricTestRunner
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class MapboxAnimatorTest {
|
||||
|
||||
@Test
|
||||
fun fps_unlimited() {
|
||||
val valueAnimator = mockk<ValueAnimator>()
|
||||
every { valueAnimator.animatedValue } answers { 5f }
|
||||
val listener = mockk<MapboxAnimator.AnimationsValueChangeListener<Float>>()
|
||||
every { listener.onNewAnimationValue(any()) } answers {}
|
||||
val mapboxAnimator = MapboxFloatAnimator(floatArrayOf(0f, 10f).toTypedArray(), listener, Int.MAX_VALUE)
|
||||
@Test
|
||||
fun fps_unlimited() {
|
||||
val valueAnimator = mockk<ValueAnimator>()
|
||||
every { valueAnimator.animatedValue } answers { 5f }
|
||||
val listener = mockk<MapboxAnimator.AnimationsValueChangeListener<Float>>()
|
||||
every { listener.onNewAnimationValue(any()) } answers {}
|
||||
val mapboxAnimator = MapboxFloatAnimator(floatArrayOf(0f, 10f).toTypedArray(), listener, Int.MAX_VALUE)
|
||||
|
||||
for (i in 0 until 5)
|
||||
mapboxAnimator.onAnimationUpdate(valueAnimator)
|
||||
for (i in 0 until 5)
|
||||
mapboxAnimator.onAnimationUpdate(valueAnimator)
|
||||
|
||||
verify(exactly = 5) { listener.onNewAnimationValue(5f) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fps_limited() {
|
||||
val valueAnimator = mockk<ValueAnimator>()
|
||||
every { valueAnimator.animatedValue } answers { 5f }
|
||||
val listener = mockk<MapboxAnimator.AnimationsValueChangeListener<Float>>()
|
||||
every { listener.onNewAnimationValue(any()) } answers {}
|
||||
val mapboxAnimator = MapboxFloatAnimator(floatArrayOf(0f, 10f).toTypedArray(), listener, 5)
|
||||
|
||||
for (i in 0 until 5) {
|
||||
mapboxAnimator.onAnimationUpdate(valueAnimator)
|
||||
Thread.sleep(150)
|
||||
verify(exactly = 5) { listener.onNewAnimationValue(5f) }
|
||||
}
|
||||
|
||||
verify(exactly = 3) { listener.onNewAnimationValue(5f) }
|
||||
}
|
||||
}
|
||||
@Test
|
||||
fun fps_limited() {
|
||||
val valueAnimator = mockk<ValueAnimator>()
|
||||
every { valueAnimator.animatedValue } answers { 5f }
|
||||
val listener = mockk<MapboxAnimator.AnimationsValueChangeListener<Float>>()
|
||||
every { listener.onNewAnimationValue(any()) } answers {}
|
||||
val mapboxAnimator = MapboxFloatAnimator(floatArrayOf(0f, 10f).toTypedArray(), listener, 5)
|
||||
|
||||
for (i in 0 until 5) {
|
||||
mapboxAnimator.onAnimationUpdate(valueAnimator)
|
||||
Thread.sleep(150)
|
||||
}
|
||||
|
||||
verify(exactly = 3) { listener.onNewAnimationValue(5f) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,84 +10,84 @@ import org.robolectric.RobolectricTestRunner
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class LoggerTest {
|
||||
|
||||
private val logger: LoggerDefinition = mockk(relaxed = true)
|
||||
private val logger: LoggerDefinition = mockk(relaxed = true)
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
Logger.setLoggerDefinition(logger)
|
||||
}
|
||||
@Before
|
||||
fun setUp() {
|
||||
Logger.setLoggerDefinition(logger)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun verbosityLogLevel() {
|
||||
Logger.setVerbosity(Logger.VERBOSE)
|
||||
Logger.v(TAG, MESSAGE)
|
||||
verify { logger.v(TAG, MESSAGE) }
|
||||
}
|
||||
@Test
|
||||
fun verbosityLogLevel() {
|
||||
Logger.setVerbosity(Logger.VERBOSE)
|
||||
Logger.v(TAG, MESSAGE)
|
||||
verify { logger.v(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun verbosityLogLevelIgnore() {
|
||||
Logger.setVerbosity(Logger.DEBUG)
|
||||
Logger.v(TAG, MESSAGE)
|
||||
verify(exactly = 0) { logger.v(TAG, MESSAGE) }
|
||||
}
|
||||
@Test
|
||||
fun verbosityLogLevelIgnore() {
|
||||
Logger.setVerbosity(Logger.DEBUG)
|
||||
Logger.v(TAG, MESSAGE)
|
||||
verify(exactly = 0) { logger.v(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun debugLogLevel() {
|
||||
Logger.setVerbosity(Logger.VERBOSE)
|
||||
Logger.d(TAG, MESSAGE)
|
||||
verify { logger.d(TAG, MESSAGE) }
|
||||
}
|
||||
@Test
|
||||
fun debugLogLevel() {
|
||||
Logger.setVerbosity(Logger.VERBOSE)
|
||||
Logger.d(TAG, MESSAGE)
|
||||
verify { logger.d(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun debugLogLevelIgnore() {
|
||||
Logger.setVerbosity(Logger.WARN)
|
||||
Logger.d(TAG, MESSAGE)
|
||||
verify(exactly = 0) { logger.d(TAG, MESSAGE) }
|
||||
}
|
||||
@Test
|
||||
fun debugLogLevelIgnore() {
|
||||
Logger.setVerbosity(Logger.WARN)
|
||||
Logger.d(TAG, MESSAGE)
|
||||
verify(exactly = 0) { logger.d(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun warnLogLevel() {
|
||||
Logger.setVerbosity(Logger.WARN)
|
||||
Logger.w(TAG, MESSAGE)
|
||||
verify { logger.w(TAG, MESSAGE) }
|
||||
}
|
||||
@Test
|
||||
fun warnLogLevel() {
|
||||
Logger.setVerbosity(Logger.WARN)
|
||||
Logger.w(TAG, MESSAGE)
|
||||
verify { logger.w(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun warnLogLevelIgnore() {
|
||||
Logger.setVerbosity(Logger.ERROR)
|
||||
Logger.w(TAG, MESSAGE)
|
||||
verify(exactly = 0) { logger.w(TAG, MESSAGE) }
|
||||
}
|
||||
@Test
|
||||
fun warnLogLevelIgnore() {
|
||||
Logger.setVerbosity(Logger.ERROR)
|
||||
Logger.w(TAG, MESSAGE)
|
||||
verify(exactly = 0) { logger.w(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun errorLogLevel() {
|
||||
Logger.setVerbosity(Logger.ERROR)
|
||||
Logger.e(TAG, MESSAGE)
|
||||
verify { logger.e(TAG, MESSAGE) }
|
||||
}
|
||||
@Test
|
||||
fun errorLogLevel() {
|
||||
Logger.setVerbosity(Logger.ERROR)
|
||||
Logger.e(TAG, MESSAGE)
|
||||
verify { logger.e(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun errorLogLevelIgnore() {
|
||||
Logger.setVerbosity(Logger.NONE)
|
||||
Logger.e(TAG, MESSAGE)
|
||||
verify(exactly = 0) { logger.e(TAG, MESSAGE) }
|
||||
}
|
||||
@Test
|
||||
fun errorLogLevelIgnore() {
|
||||
Logger.setVerbosity(Logger.NONE)
|
||||
Logger.e(TAG, MESSAGE)
|
||||
verify(exactly = 0) { logger.e(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun noneLogLevelIgnore() {
|
||||
Logger.setVerbosity(Logger.NONE)
|
||||
Logger.v(TAG, MESSAGE)
|
||||
Logger.d(TAG, MESSAGE)
|
||||
Logger.w(TAG, MESSAGE)
|
||||
Logger.e(TAG, MESSAGE)
|
||||
verify(exactly = 0) { logger.v(TAG, MESSAGE) }
|
||||
verify(exactly = 0) { logger.d(TAG, MESSAGE) }
|
||||
verify(exactly = 0) { logger.w(TAG, MESSAGE) }
|
||||
verify(exactly = 0) { logger.e(TAG, MESSAGE) }
|
||||
}
|
||||
@Test
|
||||
fun noneLogLevelIgnore() {
|
||||
Logger.setVerbosity(Logger.NONE)
|
||||
Logger.v(TAG, MESSAGE)
|
||||
Logger.d(TAG, MESSAGE)
|
||||
Logger.w(TAG, MESSAGE)
|
||||
Logger.e(TAG, MESSAGE)
|
||||
verify(exactly = 0) { logger.v(TAG, MESSAGE) }
|
||||
verify(exactly = 0) { logger.d(TAG, MESSAGE) }
|
||||
verify(exactly = 0) { logger.w(TAG, MESSAGE) }
|
||||
verify(exactly = 0) { logger.e(TAG, MESSAGE) }
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG: String = "TAG"
|
||||
const val MESSAGE: String = "message"
|
||||
}
|
||||
}
|
||||
companion object {
|
||||
const val TAG: String = "TAG"
|
||||
const val MESSAGE: String = "message"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,86 +16,86 @@ import org.robolectric.RobolectricTestRunner
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class MapboxMapOptionsAttrsTest {
|
||||
|
||||
@RelaxedMockK
|
||||
private lateinit var options: MapboxMapOptions
|
||||
@RelaxedMockK
|
||||
private lateinit var options: MapboxMapOptions
|
||||
|
||||
@RelaxedMockK
|
||||
private lateinit var typedArray: TypedArray
|
||||
@RelaxedMockK
|
||||
private lateinit var typedArray: TypedArray
|
||||
|
||||
@RelaxedMockK
|
||||
private lateinit var context: Context
|
||||
@RelaxedMockK
|
||||
private lateinit var context: Context
|
||||
|
||||
@RelaxedMockK
|
||||
private lateinit var resources: Resources
|
||||
@RelaxedMockK
|
||||
private lateinit var resources: Resources
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockKAnnotations.init(this)
|
||||
every {
|
||||
context.resources
|
||||
}.returns(resources)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun enabledLocalIdeographFontFamily() {
|
||||
mockEnableLocalIdeograph(enabled = true)
|
||||
|
||||
val options = MapboxMapOptions.createFromAttributes(options, context, typedArray)
|
||||
|
||||
verify(exactly = 1) {
|
||||
options.localIdeographFontFamily(any())
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockKAnnotations.init(this)
|
||||
every {
|
||||
context.resources
|
||||
}.returns(resources)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun localIdeographFontFamily() {
|
||||
mockEnableLocalIdeograph(enabled = true)
|
||||
@Test
|
||||
fun enabledLocalIdeographFontFamily() {
|
||||
mockEnableLocalIdeograph(enabled = true)
|
||||
|
||||
val font = "foo"
|
||||
mockLocalIdeographString(font)
|
||||
val options = MapboxMapOptions.createFromAttributes(options, context, typedArray)
|
||||
|
||||
val options = MapboxMapOptions.createFromAttributes(options, context, typedArray)
|
||||
|
||||
verify(exactly = 1) {
|
||||
options.localIdeographFontFamily(font)
|
||||
verify(exactly = 1) {
|
||||
options.localIdeographFontFamily(any())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun localIdeographFontFamilies() {
|
||||
mockEnableLocalIdeograph(enabled = true)
|
||||
@Test
|
||||
fun localIdeographFontFamily() {
|
||||
mockEnableLocalIdeograph(enabled = true)
|
||||
|
||||
val fonts = arrayOf("foo", "bar")
|
||||
mockLocalIdeographStringArray(fonts)
|
||||
val font = "foo"
|
||||
mockLocalIdeographString(font)
|
||||
|
||||
val options = MapboxMapOptions.createFromAttributes(options, context, typedArray)
|
||||
val options = MapboxMapOptions.createFromAttributes(options, context, typedArray)
|
||||
|
||||
verify(exactly = 1) {
|
||||
options.localIdeographFontFamily(*fonts)
|
||||
verify(exactly = 1) {
|
||||
options.localIdeographFontFamily(font)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun mockEnableLocalIdeograph(enabled: Boolean) {
|
||||
every {
|
||||
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_localIdeographEnabled, true)
|
||||
}.returns(enabled)
|
||||
}
|
||||
@Test
|
||||
fun localIdeographFontFamilies() {
|
||||
mockEnableLocalIdeograph(enabled = true)
|
||||
|
||||
private fun mockLocalIdeographString(font: String) {
|
||||
every {
|
||||
typedArray.getString(R.styleable.mapbox_MapView_mapbox_localIdeographFontFamily)
|
||||
}.returns(font)
|
||||
}
|
||||
val fonts = arrayOf("foo", "bar")
|
||||
mockLocalIdeographStringArray(fonts)
|
||||
|
||||
private fun mockLocalIdeographStringArray(fonts: Array<String>) {
|
||||
val resId = 9000
|
||||
val options = MapboxMapOptions.createFromAttributes(options, context, typedArray)
|
||||
|
||||
every {
|
||||
typedArray.getResourceId(R.styleable.mapbox_MapView_mapbox_localIdeographFontFamilies, 0)
|
||||
}.returns(resId)
|
||||
verify(exactly = 1) {
|
||||
options.localIdeographFontFamily(*fonts)
|
||||
}
|
||||
}
|
||||
|
||||
every {
|
||||
resources.getStringArray(resId)
|
||||
}.returns(fonts)
|
||||
}
|
||||
}
|
||||
private fun mockEnableLocalIdeograph(enabled: Boolean) {
|
||||
every {
|
||||
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_localIdeographEnabled, true)
|
||||
}.returns(enabled)
|
||||
}
|
||||
|
||||
private fun mockLocalIdeographString(font: String) {
|
||||
every {
|
||||
typedArray.getString(R.styleable.mapbox_MapView_mapbox_localIdeographFontFamily)
|
||||
}.returns(font)
|
||||
}
|
||||
|
||||
private fun mockLocalIdeographStringArray(fonts: Array<String>) {
|
||||
val resId = 9000
|
||||
|
||||
every {
|
||||
typedArray.getResourceId(R.styleable.mapbox_MapView_mapbox_localIdeographFontFamilies, 0)
|
||||
}.returns(resId)
|
||||
|
||||
every {
|
||||
resources.getStringArray(resId)
|
||||
}.returns(fonts)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,211 +16,211 @@ import org.robolectric.RobolectricTestRunner
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class MapboxMapTest {
|
||||
|
||||
private lateinit var mapboxMap: MapboxMap
|
||||
private lateinit var mapboxMap: MapboxMap
|
||||
|
||||
private lateinit var nativeMapView: NativeMap
|
||||
private lateinit var nativeMapView: NativeMap
|
||||
|
||||
private lateinit var transform: Transform
|
||||
private lateinit var transform: Transform
|
||||
|
||||
private lateinit var cameraChangeDispatcher: CameraChangeDispatcher
|
||||
private lateinit var cameraChangeDispatcher: CameraChangeDispatcher
|
||||
|
||||
private lateinit var developerAnimationListener: MapboxMap.OnDeveloperAnimationListener
|
||||
private lateinit var developerAnimationListener: MapboxMap.OnDeveloperAnimationListener
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
cameraChangeDispatcher = spyk()
|
||||
developerAnimationListener = mockk(relaxed = true)
|
||||
nativeMapView = mockk(relaxed = true)
|
||||
transform = mockk(relaxed = true)
|
||||
mapboxMap = MapboxMap(nativeMapView, transform, mockk(relaxed = true), null, null, cameraChangeDispatcher, listOf(developerAnimationListener))
|
||||
every { nativeMapView.isDestroyed } returns false
|
||||
every { nativeMapView.nativePtr } returns 5
|
||||
mapboxMap.injectLocationComponent(spyk())
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
}
|
||||
@Before
|
||||
fun setup() {
|
||||
cameraChangeDispatcher = spyk()
|
||||
developerAnimationListener = mockk(relaxed = true)
|
||||
nativeMapView = mockk(relaxed = true)
|
||||
transform = mockk(relaxed = true)
|
||||
mapboxMap = MapboxMap(nativeMapView, transform, mockk(relaxed = true), null, null, cameraChangeDispatcher, listOf(developerAnimationListener))
|
||||
every { nativeMapView.isDestroyed } returns false
|
||||
every { nativeMapView.nativePtr } returns 5
|
||||
mapboxMap.injectLocationComponent(spyk())
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTransitionOptions() {
|
||||
val expected = TransitionOptions(100, 200)
|
||||
mapboxMap.style?.transition = expected
|
||||
verify { nativeMapView.transitionOptions = expected }
|
||||
}
|
||||
@Test
|
||||
fun testTransitionOptions() {
|
||||
val expected = TransitionOptions(100, 200)
|
||||
mapboxMap.style?.transition = expected
|
||||
verify { nativeMapView.transitionOptions = expected }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMoveCamera() {
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
mapboxMap.moveCamera(update, callback)
|
||||
verify { transform.moveCamera(mapboxMap, update, callback) }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
@Test
|
||||
fun testMoveCamera() {
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
mapboxMap.moveCamera(update, callback)
|
||||
verify { transform.moveCamera(mapboxMap, update, callback) }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEaseCamera() {
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
mapboxMap.easeCamera(update, callback)
|
||||
verify { transform.easeCamera(mapboxMap, update, MapboxConstants.ANIMATION_DURATION, true, callback) }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
@Test
|
||||
fun testEaseCamera() {
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
mapboxMap.easeCamera(update, callback)
|
||||
verify { transform.easeCamera(mapboxMap, update, MapboxConstants.ANIMATION_DURATION, true, callback) }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAnimateCamera() {
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
mapboxMap.animateCamera(update, callback)
|
||||
verify { transform.animateCamera(mapboxMap, update, MapboxConstants.ANIMATION_DURATION, callback) }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
@Test
|
||||
fun testAnimateCamera() {
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
mapboxMap.animateCamera(update, callback)
|
||||
verify { transform.animateCamera(mapboxMap, update, MapboxConstants.ANIMATION_DURATION, callback) }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScrollBy() {
|
||||
mapboxMap.scrollBy(100f, 200f)
|
||||
verify { nativeMapView.moveBy(100.0, 200.0, 0) }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
@Test
|
||||
fun testScrollBy() {
|
||||
mapboxMap.scrollBy(100f, 200f)
|
||||
verify { nativeMapView.moveBy(100.0, 200.0, 0) }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testResetNorth() {
|
||||
mapboxMap.resetNorth()
|
||||
verify { transform.resetNorth() }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
@Test
|
||||
fun testResetNorth() {
|
||||
mapboxMap.resetNorth()
|
||||
verify { transform.resetNorth() }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFocalBearing() {
|
||||
mapboxMap.setFocalBearing(35.0, 100f, 200f, 1000)
|
||||
verify { transform.setBearing(35.0, 100f, 200f, 1000) }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
@Test
|
||||
fun testFocalBearing() {
|
||||
mapboxMap.setFocalBearing(35.0, 100f, 200f, 1000)
|
||||
verify { transform.setBearing(35.0, 100f, 200f, 1000) }
|
||||
verify { developerAnimationListener.onDeveloperAnimationStarted() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMinZoom() {
|
||||
mapboxMap.setMinZoomPreference(10.0)
|
||||
verify { transform.minZoom = 10.0 }
|
||||
}
|
||||
@Test
|
||||
fun testMinZoom() {
|
||||
mapboxMap.setMinZoomPreference(10.0)
|
||||
verify { transform.minZoom = 10.0 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMaxZoom() {
|
||||
mapboxMap.setMaxZoomPreference(10.0)
|
||||
verify { transform.maxZoom = 10.0 }
|
||||
}
|
||||
@Test
|
||||
fun testMaxZoom() {
|
||||
mapboxMap.setMaxZoomPreference(10.0)
|
||||
verify { transform.maxZoom = 10.0 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMinPitch() {
|
||||
mapboxMap.setMinPitchPreference(10.0)
|
||||
verify { transform.minPitch = 10.0 }
|
||||
}
|
||||
@Test
|
||||
fun testMinPitch() {
|
||||
mapboxMap.setMinPitchPreference(10.0)
|
||||
verify { transform.minPitch = 10.0 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMaxPitch() {
|
||||
mapboxMap.setMaxPitchPreference(10.0)
|
||||
verify { transform.maxPitch = 10.0 }
|
||||
}
|
||||
@Test
|
||||
fun testMaxPitch() {
|
||||
mapboxMap.setMaxPitchPreference(10.0)
|
||||
verify { transform.maxPitch = 10.0 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFpsListener() {
|
||||
val fpsChangedListener = mockk<MapboxMap.OnFpsChangedListener>()
|
||||
mapboxMap.onFpsChangedListener = fpsChangedListener
|
||||
assertEquals("Listener should match", fpsChangedListener, mapboxMap.onFpsChangedListener)
|
||||
}
|
||||
@Test
|
||||
fun testFpsListener() {
|
||||
val fpsChangedListener = mockk<MapboxMap.OnFpsChangedListener>()
|
||||
mapboxMap.onFpsChangedListener = fpsChangedListener
|
||||
assertEquals("Listener should match", fpsChangedListener, mapboxMap.onFpsChangedListener)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTilePrefetch() {
|
||||
mapboxMap.prefetchesTiles = true
|
||||
verify { nativeMapView.prefetchTiles = true }
|
||||
}
|
||||
@Test
|
||||
fun testTilePrefetch() {
|
||||
mapboxMap.prefetchesTiles = true
|
||||
verify { nativeMapView.prefetchTiles = true }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetPrefetchZoomDelta() {
|
||||
every { nativeMapView.prefetchZoomDelta } answers { 3 }
|
||||
assertEquals(3, mapboxMap.prefetchZoomDelta)
|
||||
}
|
||||
@Test
|
||||
fun testGetPrefetchZoomDelta() {
|
||||
every { nativeMapView.prefetchZoomDelta } answers { 3 }
|
||||
assertEquals(3, mapboxMap.prefetchZoomDelta)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSetPrefetchZoomDelta() {
|
||||
mapboxMap.prefetchZoomDelta = 2
|
||||
verify { nativeMapView.prefetchZoomDelta = 2 }
|
||||
}
|
||||
@Test
|
||||
fun testSetPrefetchZoomDelta() {
|
||||
mapboxMap.prefetchZoomDelta = 2
|
||||
verify { nativeMapView.prefetchZoomDelta = 2 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCameraForLatLngBounds() {
|
||||
val bounds = LatLngBounds.Builder().include(LatLng()).include(LatLng(1.0, 1.0)).build()
|
||||
mapboxMap.setLatLngBoundsForCameraTarget(bounds)
|
||||
verify { nativeMapView.setLatLngBounds(bounds) }
|
||||
}
|
||||
@Test
|
||||
fun testCameraForLatLngBounds() {
|
||||
val bounds = LatLngBounds.Builder().include(LatLng()).include(LatLng(1.0, 1.0)).build()
|
||||
mapboxMap.setLatLngBoundsForCameraTarget(bounds)
|
||||
verify { nativeMapView.setLatLngBounds(bounds) }
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun testAnimateCameraChecksDurationPositive() {
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(LatLng(30.0, 30.0)), 0, null)
|
||||
}
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun testAnimateCameraChecksDurationPositive() {
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(LatLng(30.0, 30.0)), 0, null)
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun testEaseCameraChecksDurationPositive() {
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newLatLng(LatLng(30.0, 30.0)), 0, null)
|
||||
}
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun testEaseCameraChecksDurationPositive() {
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newLatLng(LatLng(30.0, 30.0)), 0, null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetNativeMapPtr() {
|
||||
assertEquals(5, mapboxMap.nativeMapPtr)
|
||||
}
|
||||
@Test
|
||||
fun testGetNativeMapPtr() {
|
||||
assertEquals(5, mapboxMap.nativeMapPtr)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNativeMapIsNotCalledOnStateSave() {
|
||||
clearMocks(nativeMapView)
|
||||
mapboxMap.onSaveInstanceState(mockk(relaxed = true))
|
||||
verify { nativeMapView wasNot Called }
|
||||
}
|
||||
@Test
|
||||
fun testNativeMapIsNotCalledOnStateSave() {
|
||||
clearMocks(nativeMapView)
|
||||
mapboxMap.onSaveInstanceState(mockk(relaxed = true))
|
||||
verify { nativeMapView wasNot Called }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCameraChangeDispatcherCleared() {
|
||||
mapboxMap.onDestroy()
|
||||
verify { cameraChangeDispatcher.onDestroy() }
|
||||
}
|
||||
@Test
|
||||
fun testCameraChangeDispatcherCleared() {
|
||||
mapboxMap.onDestroy()
|
||||
verify { cameraChangeDispatcher.onDestroy() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStyleClearedOnDestroy() {
|
||||
val style = mockk<Style>(relaxed = true)
|
||||
val builder = mockk<Style.Builder>(relaxed = true)
|
||||
every { builder.build(nativeMapView) } returns style
|
||||
mapboxMap.setStyle(builder)
|
||||
@Test
|
||||
fun testStyleClearedOnDestroy() {
|
||||
val style = mockk<Style>(relaxed = true)
|
||||
val builder = mockk<Style.Builder>(relaxed = true)
|
||||
every { builder.build(nativeMapView) } returns style
|
||||
mapboxMap.setStyle(builder)
|
||||
|
||||
mapboxMap.onDestroy()
|
||||
verify(exactly = 1) { style.clear() }
|
||||
}
|
||||
mapboxMap.onDestroy()
|
||||
verify(exactly = 1) { style.clear() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStyleCallbackNotCalledWhenPreviousFailed() {
|
||||
val style = mockk<Style>(relaxed = true)
|
||||
val builder = mockk<Style.Builder>(relaxed = true)
|
||||
every { builder.build(nativeMapView) } returns style
|
||||
val onStyleLoadedListener = mockk<Style.OnStyleLoaded>(relaxed = true)
|
||||
@Test
|
||||
fun testStyleCallbackNotCalledWhenPreviousFailed() {
|
||||
val style = mockk<Style>(relaxed = true)
|
||||
val builder = mockk<Style.Builder>(relaxed = true)
|
||||
every { builder.build(nativeMapView) } returns style
|
||||
val onStyleLoadedListener = mockk<Style.OnStyleLoaded>(relaxed = true)
|
||||
|
||||
mapboxMap.setStyle(builder, onStyleLoadedListener)
|
||||
mapboxMap.onFailLoadingStyle()
|
||||
mapboxMap.setStyle(builder, onStyleLoadedListener)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
verify(exactly = 1) { onStyleLoadedListener.onStyleLoaded(style) }
|
||||
}
|
||||
mapboxMap.setStyle(builder, onStyleLoadedListener)
|
||||
mapboxMap.onFailLoadingStyle()
|
||||
mapboxMap.setStyle(builder, onStyleLoadedListener)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
verify(exactly = 1) { onStyleLoadedListener.onStyleLoaded(style) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStyleCallbackNotCalledWhenPreviousNotFinished() {
|
||||
// regression test for #14337
|
||||
val style = mockk<Style>(relaxed = true)
|
||||
val builder = mockk<Style.Builder>(relaxed = true)
|
||||
every { builder.build(nativeMapView) } returns style
|
||||
val onStyleLoadedListener = mockk<Style.OnStyleLoaded>(relaxed = true)
|
||||
@Test
|
||||
fun testStyleCallbackNotCalledWhenPreviousNotFinished() {
|
||||
// regression test for #14337
|
||||
val style = mockk<Style>(relaxed = true)
|
||||
val builder = mockk<Style.Builder>(relaxed = true)
|
||||
every { builder.build(nativeMapView) } returns style
|
||||
val onStyleLoadedListener = mockk<Style.OnStyleLoaded>(relaxed = true)
|
||||
|
||||
mapboxMap.setStyle(builder, onStyleLoadedListener)
|
||||
mapboxMap.setStyle(builder, onStyleLoadedListener)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
verify(exactly = 1) { onStyleLoadedListener.onStyleLoaded(style) }
|
||||
}
|
||||
}
|
||||
mapboxMap.setStyle(builder, onStyleLoadedListener)
|
||||
mapboxMap.setStyle(builder, onStyleLoadedListener)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
verify(exactly = 1) { onStyleLoadedListener.onStyleLoaded(style) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,9 +155,11 @@ class StyleBuilderTest {
|
||||
drawable.intrinsicHeight = 1
|
||||
val builder = Style.Builder()
|
||||
builder.withImage("id", drawable)
|
||||
assertTrue(BitmapUtils.equals(
|
||||
assertTrue(
|
||||
BitmapUtils.equals(
|
||||
BitmapUtils.getBitmapFromDrawable(drawable)!!,
|
||||
builder.images[0].bitmap)
|
||||
builder.images[0].bitmap
|
||||
)
|
||||
)
|
||||
assertEquals("id", builder.images[0].id)
|
||||
assertEquals(false, builder.images[0].sdf)
|
||||
@@ -170,9 +172,11 @@ class StyleBuilderTest {
|
||||
drawable.intrinsicHeight = 1
|
||||
val builder = Style.Builder()
|
||||
builder.withImage("id", drawable, true)
|
||||
assertTrue(BitmapUtils.equals(
|
||||
assertTrue(
|
||||
BitmapUtils.equals(
|
||||
BitmapUtils.getBitmapFromDrawable(drawable)!!,
|
||||
builder.images[0].bitmap)
|
||||
builder.images[0].bitmap
|
||||
)
|
||||
)
|
||||
assertEquals("id", builder.images[0].id)
|
||||
assertEquals(true, builder.images[0].sdf)
|
||||
@@ -188,15 +192,19 @@ class StyleBuilderTest {
|
||||
drawable2.intrinsicHeight = 1
|
||||
val builder = Style.Builder()
|
||||
builder.withDrawableImages(Pair<String, Drawable>("id1", drawable1), Pair<String, Drawable>("id2", drawable2))
|
||||
assertTrue(BitmapUtils.equals(
|
||||
assertTrue(
|
||||
BitmapUtils.equals(
|
||||
BitmapUtils.getBitmapFromDrawable(drawable1)!!,
|
||||
builder.images[0].bitmap)
|
||||
builder.images[0].bitmap
|
||||
)
|
||||
)
|
||||
assertEquals("id1", builder.images[0].id)
|
||||
assertEquals(false, builder.images[0].sdf)
|
||||
assertTrue(BitmapUtils.equals(
|
||||
assertTrue(
|
||||
BitmapUtils.equals(
|
||||
BitmapUtils.getBitmapFromDrawable(drawable2)!!,
|
||||
builder.images[1].bitmap)
|
||||
builder.images[1].bitmap
|
||||
)
|
||||
)
|
||||
assertEquals("id2", builder.images[1].id)
|
||||
assertEquals(false, builder.images[1].sdf)
|
||||
@@ -212,15 +220,19 @@ class StyleBuilderTest {
|
||||
drawable2.intrinsicHeight = 1
|
||||
val builder = Style.Builder()
|
||||
builder.withDrawableImages(true, Pair<String, Drawable>("id1", drawable1), Pair<String, Drawable>("id2", drawable2))
|
||||
assertTrue(BitmapUtils.equals(
|
||||
assertTrue(
|
||||
BitmapUtils.equals(
|
||||
BitmapUtils.getBitmapFromDrawable(drawable1)!!,
|
||||
builder.images[0].bitmap)
|
||||
builder.images[0].bitmap
|
||||
)
|
||||
)
|
||||
assertEquals("id1", builder.images[0].id)
|
||||
assertEquals(true, builder.images[0].sdf)
|
||||
assertTrue(BitmapUtils.equals(
|
||||
assertTrue(
|
||||
BitmapUtils.equals(
|
||||
BitmapUtils.getBitmapFromDrawable(drawable2)!!,
|
||||
builder.images[1].bitmap)
|
||||
builder.images[1].bitmap
|
||||
)
|
||||
)
|
||||
assertEquals("id2", builder.images[1].id)
|
||||
assertEquals(true, builder.images[1].sdf)
|
||||
@@ -234,4 +246,4 @@ class StyleBuilderTest {
|
||||
assertEquals(100, builder.transitionOptions.duration)
|
||||
assertEquals(200, builder.transitionOptions.delay)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,4 +405,4 @@ class StyleTest {
|
||||
Assert.assertEquals("Layer that failed to be added shouldn't be cached", layer1, mapboxMap.style!!.getLayer("layer1"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,191 +12,191 @@ import org.robolectric.RobolectricTestRunner
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class TransformTest {
|
||||
|
||||
private lateinit var mapView: MapView
|
||||
private lateinit var nativeMapView: NativeMap
|
||||
private lateinit var transform: Transform
|
||||
private lateinit var cameraChangeDispatcher: CameraChangeDispatcher
|
||||
private lateinit var mapView: MapView
|
||||
private lateinit var nativeMapView: NativeMap
|
||||
private lateinit var transform: Transform
|
||||
private lateinit var cameraChangeDispatcher: CameraChangeDispatcher
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
cameraChangeDispatcher = spyk()
|
||||
mapView = mockk()
|
||||
nativeMapView = mockk()
|
||||
transform = Transform(mapView, nativeMapView, cameraChangeDispatcher)
|
||||
every { nativeMapView.isDestroyed } returns false
|
||||
every { nativeMapView.cameraPosition } returns CameraPosition.DEFAULT
|
||||
every { nativeMapView.cancelTransitions() } answers {}
|
||||
every { nativeMapView.jumpTo(any(), any(), any(), any(), any()) } answers {}
|
||||
every { nativeMapView.easeTo(any(), any(), any(), any(), any(), any(), any()) } answers {}
|
||||
every { nativeMapView.flyTo(any(), any(), any(), any(), any(), any()) } answers {}
|
||||
every { nativeMapView.minZoom = any() } answers {}
|
||||
every { nativeMapView.maxZoom = any() } answers {}
|
||||
every { nativeMapView.minPitch = any() } answers {}
|
||||
every { nativeMapView.maxPitch = any() } answers {}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMoveCamera() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
|
||||
transform.cameraPosition
|
||||
every { nativeMapView.cameraPosition } returns expected
|
||||
transform.moveCamera(mapboxMap, update, callback)
|
||||
|
||||
verify { cameraChangeDispatcher.onCameraMove() }
|
||||
verify { nativeMapView.jumpTo(target, -1.0, -1.0, -1.0, null) }
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMoveCameraToSamePosition() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val expected = CameraPosition.DEFAULT
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
|
||||
transform.moveCamera(mapboxMap, update, null) // Initialize camera position
|
||||
transform.moveCamera(mapboxMap, update, callback)
|
||||
|
||||
verify(exactly = 1, verifyBlock = { nativeMapView.jumpTo(any(), any(), any(), any(), any()) })
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEaseCamera() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
every { mapView.addOnCameraDidChangeListener(any()) } answers { transform.onCameraDidChange(true) }
|
||||
every { mapView.removeOnCameraDidChangeListener(any()) } answers {}
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
|
||||
transform.easeCamera(mapboxMap, update, 100, false, callback)
|
||||
|
||||
verify { nativeMapView.easeTo(target, -1.0, -1.0, -1.0, null, 100, false) }
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEaseCameraToSamePosition() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val expected = CameraPosition.DEFAULT
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
transform.moveCamera(mapboxMap, update, null)
|
||||
|
||||
transform.easeCamera(mapboxMap, update, 100, false, callback)
|
||||
|
||||
verify(exactly = 0, verifyBlock = { nativeMapView.easeTo(any(), any(), any(), any(), any(), any(), any()) })
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAnimateCamera() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
every { mapView.addOnCameraDidChangeListener(any()) } answers { transform.onCameraDidChange(true) }
|
||||
every { mapView.removeOnCameraDidChangeListener(any()) } answers {}
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
|
||||
transform.animateCamera(mapboxMap, update, 100, callback)
|
||||
|
||||
verify { nativeMapView.flyTo(target, -1.0, -1.0, -1.0, null, 100) }
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAnimateCameraToSamePosition() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val expected = CameraPosition.DEFAULT
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
transform.moveCamera(mapboxMap, update, null)
|
||||
|
||||
transform.animateCamera(mapboxMap, update, 100, callback)
|
||||
|
||||
verify(exactly = 0, verifyBlock = { nativeMapView.flyTo(any(), any(), any(), any(), any(), any()) })
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMinZoom() {
|
||||
transform.minZoom = 10.0
|
||||
verify { nativeMapView.minZoom = 10.0 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMaxZoom() {
|
||||
transform.maxZoom = 10.0
|
||||
verify { nativeMapView.maxZoom = 10.0 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMinPitch() {
|
||||
transform.minPitch = 10.0
|
||||
verify { nativeMapView.minPitch = 10.0 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMaxPitch() {
|
||||
transform.maxPitch = 10.0
|
||||
verify { nativeMapView.maxPitch = 10.0 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCancelNotInvokedFromOnFinish() {
|
||||
val slot = slot<MapView.OnCameraDidChangeListener>()
|
||||
every { mapView.addOnCameraDidChangeListener(capture(slot)) } answers { slot.captured.onCameraDidChange(true) }
|
||||
every { mapView.removeOnCameraDidChangeListener(any()) } answers {}
|
||||
// regression test for https://github.com/mapbox/mapbox-gl-native/issues/13735
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
|
||||
val callback = object : MapboxMap.CancelableCallback {
|
||||
override fun onCancel() {
|
||||
throw IllegalStateException("onCancel shouldn't be called from onFinish")
|
||||
}
|
||||
|
||||
override fun onFinish() {
|
||||
transform.animateCamera(mapboxMap, CameraUpdateFactory.newCameraPosition(expected), 500, null)
|
||||
}
|
||||
@Before
|
||||
fun setup() {
|
||||
cameraChangeDispatcher = spyk()
|
||||
mapView = mockk()
|
||||
nativeMapView = mockk()
|
||||
transform = Transform(mapView, nativeMapView, cameraChangeDispatcher)
|
||||
every { nativeMapView.isDestroyed } returns false
|
||||
every { nativeMapView.cameraPosition } returns CameraPosition.DEFAULT
|
||||
every { nativeMapView.cancelTransitions() } answers {}
|
||||
every { nativeMapView.jumpTo(any(), any(), any(), any(), any()) } answers {}
|
||||
every { nativeMapView.easeTo(any(), any(), any(), any(), any(), any(), any()) } answers {}
|
||||
every { nativeMapView.flyTo(any(), any(), any(), any(), any(), any()) } answers {}
|
||||
every { nativeMapView.minZoom = any() } answers {}
|
||||
every { nativeMapView.maxZoom = any() } answers {}
|
||||
every { nativeMapView.minPitch = any() } answers {}
|
||||
every { nativeMapView.maxPitch = any() } answers {}
|
||||
}
|
||||
transform.animateCamera(mapboxMap, CameraUpdateFactory.newCameraPosition(expected), 500, callback)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMoveCamera() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
|
||||
transform.cameraPosition
|
||||
every { nativeMapView.cameraPosition } returns expected
|
||||
transform.moveCamera(mapboxMap, update, callback)
|
||||
|
||||
verify { cameraChangeDispatcher.onCameraMove() }
|
||||
verify { nativeMapView.jumpTo(target, -1.0, -1.0, -1.0, null) }
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMoveCameraToSamePosition() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val expected = CameraPosition.DEFAULT
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
|
||||
transform.moveCamera(mapboxMap, update, null) // Initialize camera position
|
||||
transform.moveCamera(mapboxMap, update, callback)
|
||||
|
||||
verify(exactly = 1, verifyBlock = { nativeMapView.jumpTo(any(), any(), any(), any(), any()) })
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEaseCamera() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
every { mapView.addOnCameraDidChangeListener(any()) } answers { transform.onCameraDidChange(true) }
|
||||
every { mapView.removeOnCameraDidChangeListener(any()) } answers {}
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
|
||||
transform.easeCamera(mapboxMap, update, 100, false, callback)
|
||||
|
||||
verify { nativeMapView.easeTo(target, -1.0, -1.0, -1.0, null, 100, false) }
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEaseCameraToSamePosition() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val expected = CameraPosition.DEFAULT
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
transform.moveCamera(mapboxMap, update, null)
|
||||
|
||||
transform.easeCamera(mapboxMap, update, 100, false, callback)
|
||||
|
||||
verify(exactly = 0, verifyBlock = { nativeMapView.easeTo(any(), any(), any(), any(), any(), any(), any()) })
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAnimateCamera() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
every { mapView.addOnCameraDidChangeListener(any()) } answers { transform.onCameraDidChange(true) }
|
||||
every { mapView.removeOnCameraDidChangeListener(any()) } answers {}
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
|
||||
transform.animateCamera(mapboxMap, update, 100, callback)
|
||||
|
||||
verify { nativeMapView.flyTo(target, -1.0, -1.0, -1.0, null, 100) }
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAnimateCameraToSamePosition() {
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val callback = mockk<MapboxMap.CancelableCallback>()
|
||||
every { callback.onFinish() } answers {}
|
||||
|
||||
val expected = CameraPosition.DEFAULT
|
||||
val update = CameraUpdateFactory.newCameraPosition(expected)
|
||||
transform.moveCamera(mapboxMap, update, null)
|
||||
|
||||
transform.animateCamera(mapboxMap, update, 100, callback)
|
||||
|
||||
verify(exactly = 0, verifyBlock = { nativeMapView.flyTo(any(), any(), any(), any(), any(), any()) })
|
||||
verify { callback.onFinish() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMinZoom() {
|
||||
transform.minZoom = 10.0
|
||||
verify { nativeMapView.minZoom = 10.0 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMaxZoom() {
|
||||
transform.maxZoom = 10.0
|
||||
verify { nativeMapView.maxZoom = 10.0 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMinPitch() {
|
||||
transform.minPitch = 10.0
|
||||
verify { nativeMapView.minPitch = 10.0 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMaxPitch() {
|
||||
transform.maxPitch = 10.0
|
||||
verify { nativeMapView.maxPitch = 10.0 }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCancelNotInvokedFromOnFinish() {
|
||||
val slot = slot<MapView.OnCameraDidChangeListener>()
|
||||
every { mapView.addOnCameraDidChangeListener(capture(slot)) } answers { slot.captured.onCameraDidChange(true) }
|
||||
every { mapView.removeOnCameraDidChangeListener(any()) } answers {}
|
||||
// regression test for https://github.com/mapbox/mapbox-gl-native/issues/13735
|
||||
val mapboxMap = mockk<MapboxMap>()
|
||||
every { mapboxMap.cameraPosition } answers { CameraPosition.DEFAULT }
|
||||
|
||||
val target = LatLng(1.0, 2.0)
|
||||
val expected = CameraPosition.Builder().target(target).build()
|
||||
|
||||
val callback = object : MapboxMap.CancelableCallback {
|
||||
override fun onCancel() {
|
||||
throw IllegalStateException("onCancel shouldn't be called from onFinish")
|
||||
}
|
||||
|
||||
override fun onFinish() {
|
||||
transform.animateCamera(mapboxMap, CameraUpdateFactory.newCameraPosition(expected), 500, null)
|
||||
}
|
||||
}
|
||||
transform.animateCamera(mapboxMap, CameraUpdateFactory.newCameraPosition(expected), 500, callback)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,55 +13,55 @@ import org.robolectric.RobolectricTestRunner
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class HttpRequestUrlTest {
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MapboxInjector.inject(mockk(relaxed = true), "pk.foobar", "foobar")
|
||||
}
|
||||
@Before
|
||||
fun setUp() {
|
||||
MapboxInjector.inject(mockk(relaxed = true), "pk.foobar", "foobar")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOfflineFlagMapboxCom() {
|
||||
val expected = "http://mapbox.com/path/of/no/return.pbf?offline=true"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("mapbox.com", "http://mapbox.com/path/of/no/return.pbf", 0, true)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
@Test
|
||||
fun testOfflineFlagMapboxCom() {
|
||||
val expected = "http://mapbox.com/path/of/no/return.pbf?offline=true"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("mapbox.com", "http://mapbox.com/path/of/no/return.pbf", 0, true)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOfflineFlagMapboxCn() {
|
||||
val expected = "http://mapbox.cn/path/of/no/return.pbf?offline=true"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("mapbox.cn", "http://mapbox.cn/path/of/no/return.pbf", 0, true)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
@Test
|
||||
fun testOfflineFlagMapboxCn() {
|
||||
val expected = "http://mapbox.cn/path/of/no/return.pbf?offline=true"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("mapbox.cn", "http://mapbox.cn/path/of/no/return.pbf", 0, true)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOfflineFlagInvalidHost() {
|
||||
val expected = "http://foobar.com/path/of/no/return.pbf"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("foobar.com", "http://foobar.com/path/of/no/return.pbf", 0, true)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
@Test
|
||||
fun testOfflineFlagInvalidHost() {
|
||||
val expected = "http://foobar.com/path/of/no/return.pbf"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("foobar.com", "http://foobar.com/path/of/no/return.pbf", 0, true)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnlineMapboxCom() {
|
||||
val expected = "http://mapbox.com/path/of/no/return.pbf?sku=foobar"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("mapbox.com", "http://mapbox.com/path/of/no/return.pbf", 0, false)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
@Test
|
||||
fun testOnlineMapboxCom() {
|
||||
val expected = "http://mapbox.com/path/of/no/return.pbf?sku=foobar"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("mapbox.com", "http://mapbox.com/path/of/no/return.pbf", 0, false)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnlineMapboxCn() {
|
||||
val expected = "http://mapbox.cn/path/of/no/return.pbf?sku=foobar"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("mapbox.cn", "http://mapbox.cn/path/of/no/return.pbf", 0, false)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
@Test
|
||||
fun testOnlineMapboxCn() {
|
||||
val expected = "http://mapbox.cn/path/of/no/return.pbf?sku=foobar"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("mapbox.cn", "http://mapbox.cn/path/of/no/return.pbf", 0, false)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnlineInvalidHost() {
|
||||
val expected = "http://foobar.com/path/of/no/return.pbf"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("foobar.com", "http://foobar.com/path/of/no/return.pbf", 0, false)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
@Test
|
||||
fun testOnlineInvalidHost() {
|
||||
val expected = "http://foobar.com/path/of/no/return.pbf"
|
||||
val actual = HttpRequestUrl.buildResourceUrl("foobar.com", "http://foobar.com/path/of/no/return.pbf", 0, false)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
MapboxInjector.clear()
|
||||
}
|
||||
}
|
||||
@After
|
||||
fun tearDown() {
|
||||
MapboxInjector.clear()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,25 +11,27 @@ import org.robolectric.RobolectricTestRunner
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class HttpRequestUtilTest {
|
||||
|
||||
@Test
|
||||
fun replaceHttpClient() {
|
||||
MapboxInjector.inject(mockk(relaxed = true), "")
|
||||
@Test
|
||||
fun replaceHttpClient() {
|
||||
MapboxInjector.inject(mockk(relaxed = true), "")
|
||||
|
||||
assertEquals(HttpRequestImpl.DEFAULT_CLIENT, HttpRequestImpl.client)
|
||||
assertEquals(HttpRequestImpl.DEFAULT_CLIENT, HttpRequestImpl.client)
|
||||
|
||||
val httpMock = mockk<OkHttpClient>()
|
||||
HttpRequestUtil.setOkHttpClient(httpMock)
|
||||
assertEquals("Http client should have set to the mocked client",
|
||||
httpMock,
|
||||
HttpRequestImpl.client
|
||||
)
|
||||
val httpMock = mockk<OkHttpClient>()
|
||||
HttpRequestUtil.setOkHttpClient(httpMock)
|
||||
assertEquals(
|
||||
"Http client should have set to the mocked client",
|
||||
httpMock,
|
||||
HttpRequestImpl.client
|
||||
)
|
||||
|
||||
HttpRequestUtil.setOkHttpClient(null)
|
||||
assertEquals("Http client should have been reset to the default client",
|
||||
HttpRequestImpl.DEFAULT_CLIENT,
|
||||
HttpRequestImpl.client
|
||||
)
|
||||
HttpRequestUtil.setOkHttpClient(null)
|
||||
assertEquals(
|
||||
"Http client should have been reset to the default client",
|
||||
HttpRequestImpl.DEFAULT_CLIENT,
|
||||
HttpRequestImpl.client
|
||||
)
|
||||
|
||||
MapboxInjector.clear()
|
||||
}
|
||||
}
|
||||
MapboxInjector.clear()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,17 +6,17 @@ import org.junit.Test
|
||||
|
||||
class ColorUtilsTest {
|
||||
|
||||
@Test
|
||||
fun rgbaToColor_decimalComponent() {
|
||||
val input = "rgba(255,128.0000952303,0,0.7)"
|
||||
val result = ColorUtils.rgbaToColor(input)
|
||||
Assert.assertEquals(Color.argb(255, 128, 0, (0.7 * 255).toInt()), result)
|
||||
}
|
||||
@Test
|
||||
fun rgbaToColor_decimalComponent() {
|
||||
val input = "rgba(255,128.0000952303,0,0.7)"
|
||||
val result = ColorUtils.rgbaToColor(input)
|
||||
Assert.assertEquals(Color.argb(255, 128, 0, (0.7 * 255).toInt()), result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun rgbaToColor_decimalComponent_floor() {
|
||||
val input = "rgba(255,128.70123,0,0.7)"
|
||||
val result = ColorUtils.rgbaToColor(input)
|
||||
Assert.assertEquals(Color.argb(255, 128, 0, (0.7 * 255).toInt()), result)
|
||||
}
|
||||
}
|
||||
@Test
|
||||
fun rgbaToColor_decimalComponent_floor() {
|
||||
val input = "rgba(255,128.70123,0,0.7)"
|
||||
val result = ColorUtils.rgbaToColor(input)
|
||||
Assert.assertEquals(Color.argb(255, 128, 0, (0.7 * 255).toInt()), result)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user