Skip to content

Commit

Permalink
refactor: ObjectBoxを削除
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Sep 7, 2024
1 parent 775b1a1 commit a69cb3a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 77 deletions.
3 changes: 3 additions & 0 deletions modules/data/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ android {
unitTests.all {
useJUnitPlatform()
}
unitTests.includeAndroidResources = true
}
namespace 'net.pantasystem.milktea.data'
}
Expand Down Expand Up @@ -116,6 +117,8 @@ dependencies {
implementation "androidx.exifinterface:exifinterface:1.3.6"
implementation libs.objectbox.kotlin

testImplementation libs.robolectric

}

kapt {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package net.pantasystem.milktea.data.infrastructure.image

import android.content.Context
import androidx.room.Room
import androidx.test.core.app.ApplicationProvider
import io.objectbox.BoxStore
import io.objectbox.kotlin.boxFor
import kotlinx.coroutines.runBlocking
import kotlinx.datetime.Clock
import net.pantasystem.milktea.api.misskey.DefaultOkHttpClientProvider
import net.pantasystem.milktea.data.infrastructure.BoxStoreHolder
import net.pantasystem.milktea.data.infrastructure.DataBase
import net.pantasystem.milktea.model.image.ImageCache
import org.junit.Assert
import org.junit.Before
Expand All @@ -18,25 +17,23 @@ class ImageCacheRepositoryImplTest {


lateinit var repository: ImageCacheRepositoryImpl
lateinit var store: BoxStore
lateinit var dao: ImageCacheDAO
@Before
fun setup() {
val context = ApplicationProvider.getApplicationContext<Context>()
val storeHolder = BoxStoreHolder(context)
store = storeHolder.boxStore
val database = Room.inMemoryDatabaseBuilder(context, DataBase::class.java).build()
repository = ImageCacheRepositoryImpl(
boxStoreHolder = storeHolder,
okHttpClientProvider = DefaultOkHttpClientProvider(),
context = context,
coroutineDispatcher = kotlinx.coroutines.Dispatchers.Default
coroutineDispatcher = kotlinx.coroutines.Dispatchers.Default,
database.imageCacheDAO(),
)
store.removeAllObjects()
dao = database.imageCacheDAO()
}

@Test
fun deleteExpiredCaches() = runBlocking {

val cacheStore = store.boxFor<ImageCacheRecord>()
val data = listOf(
ImageCache(
sourceUrl = "https://example.com/image2.png",
Expand Down Expand Up @@ -75,16 +72,16 @@ class ImageCacheRepositoryImplTest {
)
)
data.forEach {
cacheStore.put(
ImageCacheRecord.from(it)
dao.upsert(
ImageCacheEntity.from(it)
)
}

Assert.assertEquals(5, cacheStore.count())
Assert.assertEquals(5, dao.count())

repository.deleteExpiredCaches()

Assert.assertEquals(3, cacheStore.count())
Assert.assertEquals(3, dao.count())

Assert.assertEquals(
setOf(
Expand All @@ -94,7 +91,7 @@ class ImageCacheRepositoryImplTest {
).map {
it.sourceUrl
},
cacheStore.all.map { it.toModel() }.toSet().map {
dao.findAll().map { it.toModel() }.toSet().map {
it.sourceUrl
}
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ interface ImageCacheDAO {

@Query("""DELETE FROM image_caches WHERE source_url = :url""")
suspend fun deleteByUrl(url: String)

@Query("""SELECT * FROM image_caches""")
suspend fun findAll(): List<ImageCacheEntity>
}

This file was deleted.

2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ dependencyResolutionManagement {
library("objectbox-kotlin", "io.objectbox:objectbox-kotlin:3.5.1")

library("konfetti", "nl.dionsegijn:konfetti-xml:2.0.3")

library("robolectric", "org.robolectric:robolectric:4.13")
}
}
}
Expand Down

0 comments on commit a69cb3a

Please sign in to comment.