fix(common): 이미지 캐시 디렉터리를 분리한다
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package kr.co.vividnext.sodalive.common
|
||||
|
||||
import android.app.Application
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], application = Application::class)
|
||||
class ImageLoaderProviderTest {
|
||||
|
||||
@Test
|
||||
fun `image loader cache directory does not reuse legacy okhttp image cache`() {
|
||||
assertNotEquals(
|
||||
ImageLoaderProvider.LEGACY_OKHTTP_IMAGE_CACHE_DIRECTORY_NAME,
|
||||
ImageLoaderProvider.COIL_IMAGE_CACHE_DIRECTORY_NAME
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `image loader init deletes legacy cache and creates new cache directory`() {
|
||||
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
|
||||
val legacyCacheDirectory = File(
|
||||
context.cacheDir,
|
||||
ImageLoaderProvider.LEGACY_OKHTTP_IMAGE_CACHE_DIRECTORY_NAME
|
||||
)
|
||||
val newCacheDirectory = File(
|
||||
context.cacheDir,
|
||||
ImageLoaderProvider.COIL_IMAGE_CACHE_DIRECTORY_NAME
|
||||
)
|
||||
legacyCacheDirectory.mkdirs()
|
||||
File(legacyCacheDirectory, "journal").writeText("libcore.io.DiskLruCache\n1\n2\n")
|
||||
newCacheDirectory.deleteRecursively()
|
||||
|
||||
ImageLoaderProvider.init(context)
|
||||
|
||||
assertFalse(legacyCacheDirectory.exists())
|
||||
assertTrue(newCacheDirectory.exists())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user