GithubTrending
GithubTrending copied to clipboard
Inept stubbing in ProjectsDataRepositoryTest
https://github.com/hitherejoe/GithubTrending/blob/02ae6cd2fed321da48bdace13815709f43921a7f/Data/src/test/java/co/joebirch/data/ProjectsDataRepositoryTest.kt#L96
Issue: 2 tests were failing
-
bookmarkProjectCompletes
You should be using factory.getCacheDataStore().setProjectAsBookmarked(any())
instead of cache.setProjectAsBookmarked(any())
private fun stubBookmarkProject(completable: Completable) {
whenever(factory.getCacheDataStore().setProjectAsBookmarked(any())).thenReturn(completable)
}
-
unbookmarkProjectCompletes
Same
@chetdeva You can also do this
private fun stubBookmarkProject(completable: Completable) {
whenever(store.setProjectAsBookmarked(any()))
.thenReturn(completable)
}
private fun stubUnBookmarkProject(completable: Completable) {
whenever(store.setProjectAsUnbookmarked(any()))
.thenReturn(completable)
}
Because stubbing for data stores are already handled in these methods
private fun stubFactoryGetDataStore() {
whenever(factory.getDataStore(any(), any()))
.thenReturn(store)
}
private fun stubFactoryGetCacheDataStore() {
whenever(factory.getCacheDataStore())
.thenReturn(store)
}