Last active
August 14, 2022 06:36
-
-
Save sanogueralorenzo/d13fb2ed90d2870237014c366f76f619 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 UsersPostsUseCaseTest { | |
private lateinit var usersPostsUseCase: UsersPostsUseCase | |
private val mockUserRepository: UserRepository = mock() | |
private val mockPostRepository: PostRepository = mock() | |
private val userList = listOf(user) | |
private val postList = listOf(post) | |
@Before | |
fun setUp() { | |
usersPostsUseCase = UsersPostsUseCase(mockUserRepository, mockPostRepository) | |
} | |
@Test | |
fun `repository get success`() { | |
// given | |
whenever(mockUserRepository.get(false)).thenReturn(Single.just(userList)) | |
whenever(mockPostRepository.get(false)).thenReturn(Single.just(postList)) | |
// when | |
val test = usersPostsUseCase.get(false).test() | |
// then | |
verify(mockUserRepository).get(false) | |
verify(mockPostRepository).get(false) | |
test.assertNoErrors() | |
test.assertComplete() | |
test.assertValueCount(1) | |
test.assertValue(map(userList, postList)) | |
} | |
@Test | |
fun `repository get fail`() { | |
// given | |
val throwable = Throwable() | |
whenever(mockUserRepository.get(false)).thenReturn(Single.error(throwable)) | |
whenever(mockPostRepository.get(false)).thenReturn(Single.error(throwable)) | |
// when | |
val test = usersPostsUseCase.get(false).test() | |
// then | |
verify(mockUserRepository).get(false) | |
verify(mockPostRepository).get(false) | |
test.assertNoValues() | |
test.assertNotComplete() | |
test.assertError(throwable) | |
test.assertValueCount(0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment