saving and retrieving data is working and db files are generated
This commit is contained in:
parent
72b594b0d0
commit
5df6e95e4f
|
@ -78,6 +78,7 @@ dependencies {
|
|||
testImplementation "junit:junit:4.12"
|
||||
androidTestImplementation "androidx.test:runner:1.1.0"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-core:3.1.0"
|
||||
androidTestImplementation "androidx.test:core:1.0.0"
|
||||
androidTestImplementation "androidx.arch.core:core-testing:${versions.architectureComponents}"
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package cash.z.wallet.sdk.db
|
||||
|
||||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||
import androidx.room.Room
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import cash.z.wallet.sdk.dao.CompactBlockDao
|
||||
import cash.z.wallet.sdk.vo.CompactBlock
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
class DbIntegrationTest {
|
||||
@get:Rule
|
||||
var instantTaskExecutorRule = InstantTaskExecutorRule()
|
||||
|
||||
private var dao: CompactBlockDao? = null
|
||||
private var db: CompactBlockDb? = null
|
||||
|
||||
@Before
|
||||
fun initDb() {
|
||||
// create real DB to inspect
|
||||
db = Room
|
||||
.databaseBuilder(ApplicationProvider.getApplicationContext(), CompactBlockDb::class.java, "compact-block.db")
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
.apply { dao = complactBlockDao() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDbExists() {
|
||||
assertNotNull(db)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDaoExists() {
|
||||
assertNotNull(dao)
|
||||
dao?.insert(CompactBlock(21))
|
||||
dao?.insert(CompactBlock(18))
|
||||
|
||||
val block = dao?.findById(18)
|
||||
assertNotNull(block)
|
||||
assertEquals(18, block?.height)
|
||||
}
|
||||
}
|
|
@ -13,5 +13,5 @@ interface CompactBlockDao {
|
|||
fun insert(block: CompactBlock)
|
||||
|
||||
@Query("SELECT * FROM CompactBlock WHERE height = :height")
|
||||
fun findById(height: Int): LiveData<CompactBlock>
|
||||
fun findById(height: Int): CompactBlock
|
||||
}
|
Loading…
Reference in New Issue