Skip to content

Commit 0ab0e53

Browse files
committed
Rename test methods and classes.
1 parent 5269e07 commit 0ab0e53

File tree

3 files changed

+38
-31
lines changed

3 files changed

+38
-31
lines changed
Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 The Android Open Source Project
2+
* Copyright 2025 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,32 +14,39 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.google.samples.apps.nowinandroid.core.database
17+
package com.google.samples.apps.nowinandroid.core.database.dao
1818

1919
import android.content.Context
2020
import androidx.room.Room
2121
import androidx.test.core.app.ApplicationProvider
22-
import com.google.samples.apps.nowinandroid.core.database.dao.NewsResourceDao
23-
import com.google.samples.apps.nowinandroid.core.database.dao.TopicDao
22+
import com.google.samples.apps.nowinandroid.core.database.NiaDatabase
2423
import org.junit.After
2524
import org.junit.Before
2625

27-
abstract class TestDatabaseSetup {
28-
protected lateinit var newsResourceDao: NewsResourceDao
29-
protected lateinit var topicDao: TopicDao
30-
private lateinit var db: NiaDatabase
26+
27+
internal abstract class DatabaseTest {
28+
29+
private lateinit var db : NiaDatabase
30+
protected lateinit var newsResourceDao : NewsResourceDao
31+
protected lateinit var topicDao : TopicDao
3132

3233
@Before
33-
fun createDb() {
34-
val context = ApplicationProvider.getApplicationContext<Context>()
35-
db = Room.inMemoryDatabaseBuilder(
36-
context,
37-
NiaDatabase::class.java,
38-
).build()
34+
fun setup() {
35+
db = run {
36+
val context = ApplicationProvider.getApplicationContext<Context>()
37+
Room.inMemoryDatabaseBuilder(
38+
context,
39+
NiaDatabase::class.java,
40+
).build()
41+
}
3942
newsResourceDao = db.newsResourceDao()
4043
topicDao = db.topicDao()
4144
}
4245

4346
@After
44-
fun closeDb() = db.close()
47+
fun closeDb(){
48+
db.close()
49+
}
4550
}
51+
52+

core/database/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/core/database/dao/NewsResourceDaoTest.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.samples.apps.nowinandroid.core.database.dao
1818

19-
import com.google.samples.apps.nowinandroid.core.database.TestDatabaseSetup
2019
import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceEntity
2120
import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceTopicCrossRef
2221
import com.google.samples.apps.nowinandroid.core.database.model.TopicEntity
@@ -27,9 +26,10 @@ import kotlinx.datetime.Instant
2726
import org.junit.Test
2827
import kotlin.test.assertEquals
2928

30-
class NewsResourceDaoTest : TestDatabaseSetup() {
29+
internal class NewsResourceDaoTest : DatabaseTest() {
30+
3131
@Test
32-
fun newsResourceDao_fetches_items_by_descending_publish_date() = runTest {
32+
fun getNewsResources_allEntries_areOrderedByPublishDateDesc() = runTest {
3333
val newsResourceEntities = listOf(
3434
testNewsResource(
3535
id = "0",
@@ -64,7 +64,7 @@ class NewsResourceDaoTest : TestDatabaseSetup() {
6464
}
6565

6666
@Test
67-
fun newsResourceDao_filters_items_by_news_ids_by_descending_publish_date() = runTest {
67+
fun getNewsResources_filteredById_areOrderedByDescendingPublishDate() = runTest {
6868
val newsResourceEntities = listOf(
6969
testNewsResource(
7070
id = "0",
@@ -102,7 +102,7 @@ class NewsResourceDaoTest : TestDatabaseSetup() {
102102
}
103103

104104
@Test
105-
fun newsResourceDao_filters_items_by_topic_ids_by_descending_publish_date() = runTest {
105+
fun getNewsResources_filteredByTopicId_areOrderedByDescendingPublishDate() = runTest {
106106
val topicEntities = listOf(
107107
testTopicEntity(
108108
id = "1",
@@ -162,7 +162,7 @@ class NewsResourceDaoTest : TestDatabaseSetup() {
162162
}
163163

164164
@Test
165-
fun newsResourceDao_filters_items_by_news_and_topic_ids_by_descending_publish_date() = runTest {
165+
fun getNewsResources_filteredByIdAndTopicId_areOrderedByDescendingPublishDate() = runTest {
166166
val topicEntities = listOf(
167167
testTopicEntity(
168168
id = "1",
@@ -224,7 +224,7 @@ class NewsResourceDaoTest : TestDatabaseSetup() {
224224
}
225225

226226
@Test
227-
fun newsResourceDao_deletes_items_by_ids() =
227+
fun deleteNewsResources_byId() =
228228
runTest {
229229
val newsResourceEntities = listOf(
230230
testNewsResource(

core/database/src/androidTest/kotlin/com/google/samples/apps/nowinandroid/core/database/dao/TopicDaoTest.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616

1717
package com.google.samples.apps.nowinandroid.core.database.dao
1818

19-
import com.google.samples.apps.nowinandroid.core.database.TestDatabaseSetup
2019
import com.google.samples.apps.nowinandroid.core.database.model.TopicEntity
2120
import kotlinx.coroutines.flow.first
2221
import kotlinx.coroutines.test.runTest
2322
import org.junit.Test
2423
import kotlin.test.assertEquals
2524

26-
class TopicDaoTest : TestDatabaseSetup() {
25+
internal class TopicDaoTest : DatabaseTest() {
26+
2727
@Test
28-
fun topicDao_fetchTopics() = runTest {
28+
fun getTopics() = runTest {
2929
insertTopics()
3030

3131
val savedTopics = topicDao.getTopicEntities().first()
@@ -37,7 +37,7 @@ class TopicDaoTest : TestDatabaseSetup() {
3737
}
3838

3939
@Test
40-
fun topicDao_getSingleTopicEntity() = runTest {
40+
fun getTopic() = runTest {
4141
insertTopics()
4242

4343
val savedTopicEntity = topicDao.getTopicEntity("2").first()
@@ -46,7 +46,7 @@ class TopicDaoTest : TestDatabaseSetup() {
4646
}
4747

4848
@Test
49-
fun topicDao_getOneOffTopicEntity() = runTest {
49+
fun getTopics_oneOff() = runTest {
5050
insertTopics()
5151

5252
val savedTopics = topicDao.getOneOffTopicEntities()
@@ -58,7 +58,7 @@ class TopicDaoTest : TestDatabaseSetup() {
5858
}
5959

6060
@Test
61-
fun topicDao_getTopicEntities_ByIds() = runTest {
61+
fun getTopics_byId() = runTest {
6262
insertTopics()
6363

6464
val savedTopics = topicDao.getTopicEntities(setOf("1", "2"))
@@ -68,7 +68,7 @@ class TopicDaoTest : TestDatabaseSetup() {
6868
}
6969

7070
@Test
71-
fun topicDao_IgnoreNewEntry_If_EntityExists() = runTest {
71+
fun insertTopic_newEntryIsIgnoredIfAlreadyExists() = runTest {
7272
insertTopics()
7373
topicDao.insertOrIgnoreTopics(
7474
listOf(testTopicEntity("1", "compose")),
@@ -80,7 +80,7 @@ class TopicDaoTest : TestDatabaseSetup() {
8080
}
8181

8282
@Test
83-
fun topicDao_Upsert_Entities() = runTest {
83+
fun upsertTopic_existingEntryIsUpdated() = runTest {
8484
insertTopics()
8585
topicDao.upsertTopics(
8686
listOf(testTopicEntity("1", "newName")),
@@ -93,7 +93,7 @@ class TopicDaoTest : TestDatabaseSetup() {
9393
}
9494

9595
@Test
96-
fun topicDao_Delete_Entities() = runTest {
96+
fun deleteTopics_byId_existingEntriesAreDeleted() = runTest {
9797
insertTopics()
9898
topicDao.deleteTopics(listOf("1", "2"))
9999

0 commit comments

Comments
 (0)