GithubTrending icon indicating copy to clipboard operation
GithubTrending copied to clipboard

Inept stubbing in ProjectsDataRepositoryTest

Open chetdeva opened this issue 6 years ago • 1 comments

https://github.com/hitherejoe/GithubTrending/blob/02ae6cd2fed321da48bdace13815709f43921a7f/Data/src/test/java/co/joebirch/data/ProjectsDataRepositoryTest.kt#L96

Issue: 2 tests were failing

  1. 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)
}
  1. unbookmarkProjectCompletes

Same

chetdeva avatar Jun 28 '18 19:06 chetdeva

@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)
    }

arthlimchiu avatar Jul 02 '18 12:07 arthlimchiu