Skip to content

Commit 33260b1

Browse files
committed
feat: search room test code 작성중
1 parent 67dfdc6 commit 33260b1

4 files changed

Lines changed: 42 additions & 31 deletions

File tree

app/build.gradle

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ android {
4545
}
4646

4747
dependencies {
48-
def room_version = "2.2.3"
48+
def room_version = "2.2.5"
4949

5050
implementation fileTree(dir: 'libs', include: ['*.jar'])
5151
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
@@ -59,25 +59,24 @@ dependencies {
5959

6060
// room
6161
implementation "androidx.room:room-runtime:$room_version"
62+
implementation "androidx.room:room-ktx:$room_version"
6263
kapt "androidx.room:room-compiler:$room_version"
63-
androidTestImplementation "androidx.room:room-testing:2.2.3"
64-
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
65-
androidTestImplementation "org.koin:koin-test:2.0.1"
66-
androidTestImplementation "org.mockito:mockito-core:2.25.0"
64+
androidTestImplementation "androidx.room:room-testing:$room_version"
6765

6866
// test implementation
67+
testImplementation 'junit:junit:4.12'
68+
androidTestImplementation 'androidx.test:runner:1.2.0'
69+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
70+
androidTestImplementation 'androidx.test:rules:1.2.0'
71+
androidTestImplementation 'androidx.test:core:1.2.0'
72+
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
73+
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
6974
// implementation 'androidx.legacy:legacy-support-v4:1.0.0'
70-
// testImplementation 'junit:junit:4.12'
7175
// testImplementation 'org.robolectric:robolectric:4.3'
7276
// testImplementation 'org.powermock:powermock-api-mockito:1.4.12'
7377
// testImplementation 'org.powermock:powermock-module-junit4:1.6.2'
7478
// testImplementation 'androidx.arch.core:core-testing:2.1.0'
75-
// androidTestImplementation 'androidx.test:runner:1.2.0'
76-
// androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
77-
// androidTestImplementation 'androidx.test:rules:1.2.0'
78-
// androidTestImplementation 'androidx.test:core:1.2.0'
79-
// androidTestImplementation 'androidx.test.ext:junit:1.1.1'
80-
// androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
79+
8180

8281
// Google Ads
8382
implementation 'com.google.android.gms:play-services-ads:18.2.0'
@@ -95,6 +94,9 @@ dependencies {
9594
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
9695
implementation 'android.arch.lifecycle:viewmodel:1.1.1'
9796
annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.1.0'
97+
implementation 'android.arch.lifecycle:extensions:1.0.0';
98+
//noinspection LifecycleAnnotationProcessorWithJava8
99+
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0';
98100

99101
// Coroutines
100102
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version"

app/src/androidTest/java/com/seok/gfd/room/dao/SearchGithubIdDaoTest.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ import java.util.*
1616

1717
@RunWith(AndroidJUnit4::class)
1818
class SearchGithubIdDaoTest {
19-
private lateinit var githubIdDao: SearchGithubIdDao
2019
private lateinit var db : AppDatabase
2120

2221
@Before
2322
fun createDb() {
2423
val context = InstrumentationRegistry.getInstrumentation().targetContext
25-
db = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java).build()
26-
githubIdDao = db.searchGithubDao()
2724
}
2825

2926
@After
@@ -35,10 +32,6 @@ class SearchGithubIdDaoTest {
3532
@Test
3633
@Throws(Exception::class)
3734
fun write(){
38-
val searchGithubId : SearchGithubId = SearchGithubId(1, "2", Date())
39-
githubIdDao.insertSearchGithubId(searchGithubId)
40-
val byName = githubIdDao.selectGithubIds("2")
41-
println(byName)
4235
}
4336

4437
}

app/src/main/java/com/seok/gfd/room/dao/SearchGithubIdDao.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ package com.seok.gfd.room.dao
22

33
import androidx.room.*
44
import com.seok.gfd.room.entity.SearchGithubId
5-
import java.util.*
65

76
@Dao
8-
abstract class SearchGithubIdDao {
7+
interface SearchGithubIdDao {
98
@Insert(onConflict = OnConflictStrategy.REPLACE)
10-
abstract fun insertSearchGithubId(searchGithubId: SearchGithubId)
9+
suspend fun insert(searchGithubId: SearchGithubId) : Int
1110

1211
@Delete
13-
abstract fun deleteSearchGithubId(searchGithubId: SearchGithubId)
12+
suspend fun delete(searchGithubId: SearchGithubId)
1413

15-
@Query("SELECT * FROM search_github_ids WHERE gid_name = :gidName")
16-
abstract fun selectGithubIds(gidName : String) : List<SearchGithubId>
14+
// @Query("SELECT * FROM $TABLE_NAME WHERE gid_name = :gidName")
15+
abstract fun selectAll(gidName : String) : List<SearchGithubId>
1716
}
Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
11
package com.seok.gfd.room.entity
22

3-
import androidx.room.ColumnInfo
4-
import androidx.room.Entity
5-
import androidx.room.PrimaryKey
3+
import androidx.room.*
64
import java.util.*
75

8-
@Entity(tableName = "search_github_ids")
6+
private const val TABLE_NAME = "search_github_ids"
7+
8+
@Entity(tableName = TABLE_NAME)
99
data class SearchGithubId(
10-
@PrimaryKey var gid: Int,
10+
@PrimaryKey(autoGenerate = true) var gid: Int,
1111
@ColumnInfo(name = "gid_name") val gidName: String?,
12-
@ColumnInfo(name = "created", defaultValue = "CURRENT_TIMESTAMP") val created: Date?
12+
@ColumnInfo(name = "created", defaultValue = "CURRENT_TIMESTAMP") val created: Date? = Date()
1313
)
14+
15+
@Dao
16+
interface SearchGithubIdDao {
17+
@Insert(onConflict = OnConflictStrategy.REPLACE)
18+
suspend fun insert(searchGithubId: SearchGithubId) : Int
19+
20+
@Delete
21+
suspend fun delete(searchGithubId: SearchGithubId)
22+
23+
@Query("SELECT * FROM $TABLE_NAME WHERE gid_name = :gidName")
24+
suspend fun selectAll(gidName : String) : List<SearchGithubId>
25+
}
26+
27+
@Database(entities = [SearchGithubId::class], version = 1)
28+
abstract class AppDatabase : RoomDatabase(){
29+
abstract fun searchGithubIdDao(): SearchGithubIdDao
30+
}

0 commit comments

Comments
 (0)