Skip to content

Instantly share code, notes, and snippets.

View reactivedroid's full-sized avatar
🎯
Focusing

Ashwini Kumar reactivedroid

🎯
Focusing
View GitHub Profile
@reactivedroid
reactivedroid / BuildConfigProviderImpl.kt
Last active October 9, 2022 11:03
Implementation of the BuildConfigProvider.kt
class BuildConfigProviderImpl
@Inject
constructor(@ApplicationContext private val context: Context) : BuildConfigProvider {
private fun getFlavorMap(): MutableMap<String, String> {
return if (BuildConfig.BUILD_TYPE == "release") {
BuildConfig.RELEASE_MAP
} else {
buildConfigurationFor(getFlavor())
}
@reactivedroid
reactivedroid / BuildConfigProvider.kt
Last active October 9, 2022 10:57
Abstraction over [BuildConfig] for accessing its values
/**
* Abstraction over [BuildConfig] for accessing its values
*/
interface BuildConfigProvider {
/**
* Gets the configuration for the given [key]
*/
fun getValue(key: String): String
/**
@reactivedroid
reactivedroid / Config.kt
Created October 7, 2022 13:02
Config file containing all the build configurations according to the supported environment
object Config {
object Flavor {
const val PROD = "prod"
const val STAGING = "staging"
}
const val HOST_URL = "HOST_URL"
const val SOME_KEY = "SOME_KEY"
// Supported flavors
@reactivedroid
reactivedroid / build.gradle.kts
Last active October 9, 2022 07:48
Build Gradle File showing the changes to enable dynamic configuration switching feature
android {
...
defaultConfig {
// Generate all the keys on BuildConfig.java
Config.keyList.forEach { key ->
buildConfigField("String", "KEY_$key", "\"$key\"")
}
}
applicationVariants.all {
fun launchHome(func: HomeRobot.() -> Unit) = HomeRobot().apply { func() }
class HomeRobot {
fun verifyHome() {
onView(withId(R.id.popular_show_header)).check(matches(isDisplayed()))
onView(allOf(withId(R.id.popular_shows), isDisplayed()))
}
fun verifyFavorite() {
// Click on 1st item and mark as favorite
onView(withId(R.id.popular_shows))
@LargeTest
@RunWith(AndroidJUnit4::class)
class HomeTest {
@get:Rule
val homeActivityTestRule = ActivityTestRule(HomeActivity::class.java)
private lateinit var loadingIdlingResource: LoadingIdlingResource
@Before
fun setUp() {
loadingIdlingResource =
@ExperimentalCoroutinesApi
@RunWith(RobolectricTestRunner::class)
class HomeViewModelTest {
// Executes tasks in the Architecture Components in the same thread
@get:Rule
val instantTaskExecutorRule = InstantTaskExecutorRule()
// Set the main coroutines dispatcher for unit testing.
@get:Rule
var mainCoroutineRule = MainCoroutineRule()
@RunWith(RobolectricTestRunner::class)
@Config(manifest = Config.NONE)
class FavoriteShowsRepositoryTest {
@Mock
private lateinit var context: Context
private lateinit var favoriteShowsRepository: FavoriteShowsRepository
private lateinit var tvMazeDb: TvMazeDatabase
private lateinit var showDao: ShowDao
@Before
@Singleton
class FavoriteShowsRepository @Inject
constructor(private val showDao: ShowDao) {
suspend fun allFavoriteShows(): List<FavoriteShow> {
return showDao.allFavouriteShows()
}
fun insertShowIntoFavorites(show: Show) {
val favoriteShow = FavoriteShow(
@Dao
interface ShowDao {
@Query("SELECT * FROM favourite_shows")
suspend fun allFavouriteShows(): List<FavoriteShow>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(favoriteShow: FavoriteShow)
@Delete
suspend fun remove(favoriteShow: FavoriteShow)