summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleBuilderTest.kt
blob: cb42b0b33d7dc038d100f594c4c59ec8511d86e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package com.mapbox.mapboxsdk.maps

import android.graphics.Bitmap
import com.mapbox.mapboxsdk.style.layers.SymbolLayer
import com.mapbox.mapboxsdk.style.layers.TransitionOptions
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
import io.mockk.mockk
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
class StyleBuilderTest {

    @Test
    fun testFromUrl() {
        val expected = Style.MAPBOX_STREETS
        val builder = Style.Builder()
        builder.fromUrl(expected)
        assertEquals(expected, builder.url)
    }

    @Test
    fun testFromJson() {
        val expected = "{}"
        val builder = Style.Builder()
        builder.fromJson(expected)
        assertEquals(expected, builder.json)
    }

    @Test
    fun testWithLayer() {
        val layer = mockk<SymbolLayer>()
        val builder = Style.Builder()
        builder.withLayer(layer)
        assertEquals(layer, builder.layers[0].layer)
    }

    @Test
    fun testWithLayerAt() {
        val expectedIndex = 5
        val layer = mockk<SymbolLayer>()
        val builder = Style.Builder()
        builder.withLayerAt(layer, expectedIndex)
        assertEquals(layer, builder.layers[0].layer)
        assertEquals(expectedIndex, (builder.layers[0] as Style.Builder.LayerAtWrapper).index)
    }

    @Test
    fun testWithLayerAbove() {
        val expectedAbove = "above"
        val layer = mockk<SymbolLayer>()
        val builder = Style.Builder()
        builder.withLayerAbove(layer, expectedAbove)
        assertEquals(layer, builder.layers[0].layer)
        assertEquals(expectedAbove, (builder.layers[0] as Style.Builder.LayerAboveWrapper).aboveLayer)
    }

    @Test
    fun testWithLayerBelow() {
        val expectedBelow = "above"
        val layer = mockk<SymbolLayer>()
        val builder = Style.Builder()
        builder.withLayerBelow(layer, expectedBelow)
        assertEquals(layer, builder.layers[0].layer)
        assertEquals(expectedBelow, (builder.layers[0] as Style.Builder.LayerBelowWrapper).belowLayer)
    }

    @Test
    fun testWithSource() {
        val source = mockk<GeoJsonSource>()
        val builder = Style.Builder()
        builder.withSource(source)
        assertEquals(source, builder.sources[0])
    }

    @Test
    fun testWithImage() {
        val bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8)
        val builder = Style.Builder()
        builder.withImage("id", bitmap)
        assertEquals(bitmap, builder.images[0].bitmap)
        assertEquals("id", builder.images[0].id)
        assertEquals(false, builder.images[0].sdf)
    }

    @Test
    fun testWithImageSdf() {
        val bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8)
        val builder = Style.Builder()
        builder.withImage("id", bitmap, true)
        assertEquals(bitmap, builder.images[0].bitmap)
        assertEquals("id", builder.images[0].id)
        assertEquals(true, builder.images[0].sdf)
    }

    @Test
    fun testWithTransitionOptions() {
        val transitionOptions = TransitionOptions(100, 200)
        val builder = Style.Builder()
        builder.withTransition(transitionOptions)
        assertEquals(100, builder.transitionOptions.duration)
        assertEquals(200, builder.transitionOptions.delay)
    }
}