Skip to content

Commit 14e68a5

Browse files
committed
Move :tasks-core tests where they belong
1 parent 3f61715 commit 14e68a5

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed

tasks-core/build.gradle.kts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
plugins {
2525
alias(libs.plugins.jetbrains.kotlin.multiplatform)
2626
alias(libs.plugins.jetbrains.kotlin.serialization)
27+
alias(libs.plugins.ksp)
2728
}
2829

2930
kotlin {
@@ -46,5 +47,15 @@ kotlin {
4647
commonTest.dependencies {
4748
implementation(kotlin("test"))
4849
}
50+
51+
jvmTest.dependencies {
52+
implementation(libs.kotlinx.coroutines.test)
53+
implementation(libs.androidx.room.testing)
54+
implementation(libs.androidx.sqlite.bundled)
55+
}
4956
}
50-
}
57+
}
58+
59+
dependencies {
60+
add("kspJvm", libs.androidx.room.compiler)
61+
}

tasks-app-shared/src/commonTest/kotlin/net/opatry/tasks/data/TaskDaoTest.kt renamed to tasks-core/src/jvmTest/kotlin/net/opatry/tasks/data/TaskDaoTest.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222

2323
package net.opatry.tasks.data
2424

25+
import androidx.room.Room
2526
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
2627
import kotlinx.coroutines.flow.first
2728
import kotlinx.coroutines.test.runTest
2829
import kotlinx.datetime.Clock
2930
import kotlinx.datetime.Instant
3031
import net.opatry.tasks.data.entity.TaskEntity
31-
import net.opatry.tasks.data.util.inMemoryTasksAppDatabaseBuilder
3232
import org.junit.After
3333
import kotlin.test.BeforeTest
3434
import kotlin.test.Test
@@ -42,16 +42,15 @@ class TaskDaoTest {
4242
private val now: Instant
4343
get() = Clock.System.now()
4444

45-
private lateinit var db: TasksAppDatabase
45+
private lateinit var db: TasksCoreTestDatabase
4646
private lateinit var taskDao: TaskDao
4747

4848
@BeforeTest
4949
fun createDb() {
50-
db = inMemoryTasksAppDatabaseBuilder()
50+
db = Room.inMemoryDatabaseBuilder<TasksCoreTestDatabase>()
5151
.setDriver(BundledSQLiteDriver())
5252
.build()
5353
taskDao = db.getTaskDao()
54-
taskDao = db.getTaskDao()
5554
}
5655

5756
@After
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222

2323
package net.opatry.tasks.data
2424

25+
import androidx.room.Room
2526
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
2627
import kotlinx.coroutines.flow.first
2728
import kotlinx.coroutines.test.runTest
2829
import kotlinx.datetime.Clock
2930
import kotlinx.datetime.Instant
3031
import net.opatry.tasks.data.entity.TaskEntity
3132
import net.opatry.tasks.data.entity.TaskListEntity
32-
import net.opatry.tasks.data.util.inMemoryTasksAppDatabaseBuilder
3333
import org.junit.After
3434
import kotlin.test.BeforeTest
3535
import kotlin.test.Test
@@ -42,13 +42,13 @@ class TaskListDaoTest {
4242
private val now: Instant
4343
get() = Clock.System.now()
4444

45-
private lateinit var db: TasksAppDatabase
45+
private lateinit var db: TasksCoreTestDatabase
4646
private lateinit var taskListDao: TaskListDao
4747
private lateinit var taskDao: TaskDao
4848

4949
@BeforeTest
5050
fun createDb() {
51-
db = inMemoryTasksAppDatabaseBuilder()
51+
db = Room.inMemoryDatabaseBuilder<TasksCoreTestDatabase>()
5252
.setDriver(BundledSQLiteDriver())
5353
.build()
5454
taskListDao = db.getTaskListDao()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2025 Olivier Patry
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the Software
9+
* is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
20+
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
package net.opatry.tasks.data
24+
25+
import androidx.room.Database
26+
import androidx.room.RoomDatabase
27+
import androidx.room.TypeConverters
28+
import net.opatry.tasks.data.entity.TaskEntity
29+
import net.opatry.tasks.data.entity.TaskListEntity
30+
31+
@Database(
32+
entities = [
33+
TaskEntity::class,
34+
TaskListEntity::class,
35+
],
36+
version = 1,
37+
exportSchema = false,
38+
)
39+
40+
@TypeConverters(CoreConverters::class)
41+
abstract class TasksCoreTestDatabase : RoomDatabase() {
42+
abstract fun getTaskListDao(): TaskListDao
43+
abstract fun getTaskDao(): TaskDao
44+
}

0 commit comments

Comments
 (0)