This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Abstraction over [BuildConfig] for accessing its values | |
*/ | |
interface BuildConfigProvider { | |
/** | |
* Gets the configuration for the given [key] | |
*/ | |
fun getValue(key: String): String | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android { | |
... | |
defaultConfig { | |
// Generate all the keys on BuildConfig.java | |
Config.keyList.forEach { key -> | |
buildConfigField("String", "KEY_$key", "\"$key\"") | |
} | |
} | |
applicationVariants.all { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@LargeTest | |
@RunWith(AndroidJUnit4::class) | |
class HomeTest { | |
@get:Rule | |
val homeActivityTestRule = ActivityTestRule(HomeActivity::class.java) | |
private lateinit var loadingIdlingResource: LoadingIdlingResource | |
@Before | |
fun setUp() { | |
loadingIdlingResource = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
class FavoriteShowsRepository @Inject | |
constructor(private val showDao: ShowDao) { | |
suspend fun allFavoriteShows(): List<FavoriteShow> { | |
return showDao.allFavouriteShows() | |
} | |
fun insertShowIntoFavorites(show: Show) { | |
val favoriteShow = FavoriteShow( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) |
NewerOlder