Skip to content

Commit

Permalink
Merge pull request #2 from aliumujib/feature/country_detail
Browse files Browse the repository at this point in the history
Removed old tests from seed project
  • Loading branch information
aliumujib committed Dec 26, 2019
2 parents 84a1b0b + dc74f00 commit 795e8fb
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import io.reactivex.Single
interface CountriesDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(user: CountryCacheModel)
fun insert(country: CountryCacheModel)


@Insert(onConflict = OnConflictStrategy.REPLACE)
fun save(user: List<CountryCacheModel>)
fun save(countries: List<CountryCacheModel>)


@Query("DELETE FROM COUNTRIES")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.aliumujib.countryflags.cache.dao

import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.room.Room
import com.aliumujib.countryflags.cache.data.CacheDataFactory
import com.aliumujib.countryflags.cache.room.CountriesDB
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment

@RunWith(RobolectricTestRunner::class)
class CountriesDaoTest {

@Rule
@JvmField var instantTaskExecutorRule = InstantTaskExecutorRule()

private lateinit var database: CountriesDB

@Before
fun setUp() {
database = Room.inMemoryDatabaseBuilder(
RuntimeEnvironment.application.applicationContext,
CountriesDB::class.java)
.allowMainThreadQueries().build()
}

@Test
fun `check that calling getAllCountries() on dao returns data`() {
val countryCacheModel = CacheDataFactory.makeCountryCacheModelList(10)
database.countriesDao().save(countryCacheModel)

val testObserver = database.countriesDao().getAllCountries().test()
testObserver.assertValue(countryCacheModel)
}


@After
fun tearDown() {
database.close()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ object CacheDataFactory {
return randomBuild()
}

fun makeCountryCacheModelList(count: Int): List<CountryCacheModel> {
val articles = mutableListOf<CountryCacheModel>()
repeat(count) {
articles.add(makeCountryCacheModel())
}
return articles
}

fun makeCountryEntityList(count: Int): List<CountryEntity> {
val articles = mutableListOf<CountryEntity>()
repeat(count) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.aliumujib.countryflags

object UIDataFactory {


}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AllCountriesViewModel @Inject constructor(
companion object {

private val reducer =
BiFunction { previousState: AllCountriesViewState, result: AllCountriesResult ->
BiFunction { _: AllCountriesViewState, result: AllCountriesResult ->
when (result) {
is LoadAllCountriesResults -> {
when (result) {
Expand Down

0 comments on commit 795e8fb

Please sign in to comment.