Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/dao test #50

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/database/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,26 @@ android {
buildFeatures {
buildConfig = true
}

defaultConfig {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

packaging {
resources {
excludes.add("META-INF/LICENSE.md")
excludes.add("META-INF/LICENSE-notice.md")
}
}
}

dependencies {
implementation(projects.core.common)

Local()

androidTestImplementation(projects.core.testing)
androidTestImplementation(libs.room.test)
androidTestImplementation(libs.androidx.runner)
androidTestImplementation(libs.androidx.junit)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package kr.co.database.dao

import android.content.Context
import androidx.room.Room
import androidx.test.core.app.ApplicationProvider
import androidx.test.platform.app.InstrumentationRegistry
import junit.framework.TestCase.assertEquals
import kotlinx.coroutines.test.runTest
import kr.co.database.SeeDocsDatabase
import kr.co.database.dummy.DataBaseDummy
import kr.co.database.model.BookmarkFile
import kr.co.testing.util.testWithItem
import org.junit.After
import org.junit.Before
import org.junit.Test
import java.io.IOException

internal class BookmarkFileDaoTest {

private lateinit var database: SeeDocsDatabase
private lateinit var bookmarkFileDao: BookmarkFileDao

@Before
fun setup() {
val context = ApplicationProvider.getApplicationContext<Context>()
database = Room.inMemoryDatabaseBuilder(
context,
SeeDocsDatabase::class.java
).allowMainThreadQueries().build()

bookmarkFileDao = database.bookmarkFileDao()
}

@After
@Throws(IOException::class)
fun close() {
database.close()
}

@Test
@Throws(Exception::class)
fun bookmarkInsert() = runTest {
val bookmarkFile = DataBaseDummy.BOOKMARK_DUMMY

bookmarkFileDao.insert(bookmarkFile)

bookmarkFileDao.get().testWithItem {
assertEquals(listOf(bookmarkFile), this)
}
}

@Test
@Throws(Exception::class)
fun bookmarkDelete() = runTest {
val bookmarkFile = DataBaseDummy.BOOKMARK_DUMMY

bookmarkFileDao.insert(bookmarkFile)
bookmarkFileDao.delete(bookmarkFile)

bookmarkFileDao.get().testWithItem {
assertEquals(emptyList<BookmarkFile>(), this)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package kr.co.database.dummy

import kr.co.database.model.BookmarkFile
import kr.co.database.model.FileType
import kr.co.database.model.RecentFile
import java.time.LocalDateTime

internal object DataBaseDummy {

val BOOKMARK_DUMMY = BookmarkFile(
name = "DUMMY.pdf",
path = "",
type = FileType.PDF,
size = 0,
createdAt = LocalDateTime.of(2024,6,2,2,0),
lastModified = LocalDateTime.of(2024,6,2,2,0)
)

val RECENT_DUMMY = RecentFile(
name = "DUMMY.pdf",
path = "",
type = FileType.PDF,
size = 0,
createdAt = LocalDateTime.of(2024,6,2,2,0),
lastModified = LocalDateTime.of(2024,6,2,2,0)
)
}
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ composeActivity = "1.9.3"
composeNavigation = "2.8.4"
compose-plugin = "1.6.10"

testRunner = "1.6.2"
coreKtx = "1.15.0"
junit = "4.13.2"
junitVersion = "1.2.1"
Expand All @@ -48,6 +49,7 @@ turbine = "1.2.0"
android-desugarJdkLibs = { group = "com.android.tools", name = "desugar_jdk_libs", version.ref = "androidDesugarJdkLibs" }

junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-runner = { group = "androidx.test", name = "runner", version.ref = "testRunner" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-core-splashscreen = { group = "androidx.core", name = "core-splashscreen", version.ref = "coreSplashscreen" }
Expand All @@ -71,6 +73,7 @@ koin-junit = { group = "io.insert-koin", name = "koin-test-junit4", version.ref
room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
room-test = { group = "androidx.room", name = "room-testing", version.ref = "room" }

datastore-preferences = { group = "androidx.datastore", name = "datastore-preferences", version.ref = "dataStore" }

Expand Down
Loading