After shifting from SqliteOpenHelper
to room
in my app, I've trying to write tests for the DAO
class.
My DAO looks something like this:
@Query("SELECT * FROM cards")
fun getAllCards(): List<CardData>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertCard(vararg cardData: CardData): List<Long>
@Query("SELECT * FROM cards ORDER BY isRead ASC, id DESC")
fun getItemList(): DataSource.Factory<Int, CardData>
@Query("SELECT * FROM cards where instr(title, :query) > 0 ORDER BY isRead ASC, id DESC")
fun getItemList(query: String): DataSource.Factory<Int, CardData>
@Query("UPDATE cards set isRead = 1 where title = :title")
fun markRead(title: String): Int
While writing test for getAllCards
, insertCard
and markRead
is trivial, I am still not sure how do I test the apis which return DataSource.Factory
, i.e getItemList
apis.
After searching on internet, I couldn't find anything related to this.
Can someone please help.