summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/offline/CacheTest.kt
blob: da4cfbaf018311f2fca3a6b27444c11043acabbc (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
package com.mapbox.mapboxsdk.testapp.offline

import android.content.Context
import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import com.mapbox.mapboxsdk.offline.OfflineManager
import com.mapbox.mapboxsdk.testapp.activity.FeatureOverviewActivity
import java.util.concurrent.CountDownLatch
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class CacheTest {

  @Rule
  @JvmField
  var rule = ActivityTestRule(FeatureOverviewActivity::class.java)

  private val context: Context by lazy { rule.activity }

  private val countDownLatch = CountDownLatch(1)

  @Test
  fun testSetMaximumAmbientCacheSize() {
    rule.activity.runOnUiThread {
      OfflineManager.getInstance(context).setMaximumAmbientCacheSize(10000000, object : OfflineManager.FileSourceCallback {
        override fun onSuccess() {
          countDownLatch.countDown()
        }

        override fun onError(message: String) {
          Assert.assertNull("onError should not be called", message)
        }
      })
    }
    countDownLatch.await()
  }

  @Test
  fun testSetClearAmbientCache() {
    rule.activity.runOnUiThread {
      OfflineManager.getInstance(context).clearAmbientCache(object : OfflineManager.FileSourceCallback {
        override fun onSuccess() {
          countDownLatch.countDown()
        }

        override fun onError(message: String) {
          Assert.assertNull("onError should not be called", message)
        }
      })
    }
    countDownLatch.await()
  }

  @Test
  fun testSetInvalidateAmbientCache() {
    rule.activity.runOnUiThread {
      OfflineManager.getInstance(context).invalidateAmbientCache(object : OfflineManager.FileSourceCallback {
        override fun onSuccess() {
          countDownLatch.countDown()
        }

        override fun onError(message: String) {
          Assert.assertNull("onError should not be called", message)
        }
      })
    }
    countDownLatch.await()
  }

  @Test
  fun testSetResetDatabase() {
    rule.activity.runOnUiThread {
      OfflineManager.getInstance(context).resetDatabase(object : OfflineManager.FileSourceCallback {
        override fun onSuccess() {
          countDownLatch.countDown()
        }

        override fun onError(message: String) {
          Assert.assertNull("onError should not be called", message)
        }
      })
    }
    countDownLatch.await()
  }

  @Test
  fun testSetPackDatabase() {
    rule.activity.runOnUiThread {
      OfflineManager.getInstance(context).packDatabase(object : OfflineManager.FileSourceCallback {
        override fun onSuccess() {
          countDownLatch.countDown()
        }

        override fun onError(message: String) {
          Assert.assertNull("onError should not be called", message)
        }
      })
    }
    countDownLatch.await()
  }
}