blob: 73267037df8c8a60c81c7a75fc9d7a1a0d2358b0 (
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
|
package com.mapbox.mapboxsdk.testapp.storage
import android.app.Activity
import android.support.annotation.WorkerThread
import com.mapbox.mapboxsdk.storage.FileSource
import junit.framework.Assert
import java.io.File
import java.util.concurrent.CountDownLatch
class FileSourceTestUtils(private val activity: Activity) {
val originalPath = FileSource.getResourcesCachePath(activity)
val testPath = "$originalPath/test"
fun setup() {
val testFile = File(testPath)
testFile.mkdirs()
}
fun cleanup() {
val currentPath = FileSource.getResourcesCachePath(activity)
if (currentPath != originalPath) {
Thread().run { changePath(originalPath) }
}
val testFile = File(testPath)
if (testFile.exists()) {
testFile.deleteRecursively()
}
}
@WorkerThread
fun changePath(path: String) {
val latch = CountDownLatch(1)
activity.runOnUiThread {
FileSource.setResourcesCachePath(
activity,
path,
object : FileSource.ResourcesCachePathChangeCallback {
override fun onSuccess(path: String?) {
latch.countDown()
}
override fun onError(message: String?) {
Assert.fail("Resource path change failed - path: $path, message: $message")
}
})
}
latch.await()
}
}
|