saving and retrieving data is working and db files are generated

This commit is contained in:
Kevin Gorham 2018-11-28 03:28:31 -05:00 committed by Jack Grigg
parent 72b594b0d0
commit 5df6e95e4f
No known key found for this signature in database
GPG Key ID: 1B8D649257DB0829
3 changed files with 48 additions and 1 deletions

View File

@ -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}"
}

View File

@ -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)
}
}

View File

@ -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
}