summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/MapboxAnimatorTest.kt
blob: 7c126c7832aaa00a4e00d1ade46bd1c04a9e3f52 (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
package com.mapbox.mapboxsdk.location

import android.animation.ValueAnimator
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import org.junit.Test
import org.junit.runner.RunWith
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(0f, 10f, listener, Int.MAX_VALUE)

    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(0f, 10f, listener, 5)

    for (i in 0 until 5) {
      mapboxAnimator.onAnimationUpdate(valueAnimator)
      Thread.sleep(150)
    }

    verify(exactly = 3) { listener.onNewAnimationValue(5f) }
  }
}