Skip to content

Instantly share code, notes, and snippets.

@hitherejoe hitherejoe/CachedBufferooDaoTest.kt Secret
Last active Oct 18, 2017

Embed
What would you like to do?
@RunWith(AndroidJUnit4::class)
open class CachedBufferooDaoTest {
private lateinit var bufferoosDatabase: BufferoosDatabase
@Before
fun initDb() {
bufferoosDatabase = Room.inMemoryDatabaseBuilder(InstrumentationRegistry.getContext(),
BufferoosDatabase::class.java).build()
}
@After
fun closeDb() {
bufferoosDatabase.close()
}
@Test
fun insertBufferoosSavesData() {
val cachedBufferoo = BufferooFactory.makeCachedBufferoo()
bufferoosDatabase.cachedBufferooDao().insertBufferoo(cachedBufferoo)
val bufferoos = bufferoosDatabase.cachedBufferooDao().getBufferoos()
assert(bufferoos.isNotEmpty())
}
@Test
fun getBufferoosRetrievesData() {
val cachedBufferoos = BufferooFactory.makeCachedBufferooList(5)
cachedBufferoos.forEach {
bufferoosDatabase.cachedBufferooDao().insertBufferoo(it) }
val retrievedBufferoos = bufferoosDatabase.cachedBufferooDao().getBufferoos()
assert(retrievedBufferoos == cachedBufferoos.sortedWith(compareBy({ it.id }, { it.id })))
}
@Test
fun clearBufferoosClearsData() {
val cachedBufferoo = BufferooFactory.makeCachedBufferoo()
bufferoosDatabase.cachedBufferooDao().insertBufferoo(cachedBufferoo)
bufferoosDatabase.cachedBufferooDao().clearBufferoos()
assert(bufferoosDatabase.cachedBufferooDao().getBufferoos().isEmpty())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.