Created
February 17, 2018 09:26
-
-
Save antonicg/5d26d645c7a6e4d9b9b03d7c47280b1e to your computer and use it in GitHub Desktop.
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
package com.antonicastejon.cryptodata.usecases | |
import android.arch.core.executor.testing.InstantTaskExecutorRule | |
import com.antonicastejon.cryptodata.common.cryptoPOJOmodel | |
import com.antonicastejon.cryptodata.common.cryptoViewModelFrom | |
import com.antonicastejon.cryptodata.common.mock | |
import com.antonicastejon.cryptodata.common.whenever | |
import com.antonicastejon.cryptodata.domain.CryptoListInteractor | |
import com.antonicastejon.cryptodata.model.CoinMarketCapRepository | |
import io.reactivex.Single | |
import org.junit.Rule | |
import org.junit.Test | |
import org.mockito.ArgumentMatchers.anyInt | |
class CryptoListUseCasesUnitTest { | |
@Rule | |
@JvmField | |
val rule = InstantTaskExecutorRule() | |
val coinMarketCapRepository = mock<CoinMarketCapRepository>() | |
val cryptoListUseCases by lazy { CryptoListInteractor(coinMarketCapRepository) } | |
@Test | |
fun testCryptoListUseCases_getCryptoList_Completed() { | |
whenever(coinMarketCapRepository.getCryptoList(anyInt(), anyInt())) | |
.thenReturn(Single.just(emptyList())) | |
cryptoListUseCases.getCryptoListBy(0) | |
.test() | |
.assertComplete() | |
} | |
@Test | |
fun testCryptoListUseCases_getCryptoList_Error() { | |
val response = Throwable("Error response") | |
whenever(coinMarketCapRepository.getCryptoList(anyInt(), anyInt())) | |
.thenReturn(Single.error(response)) | |
cryptoListUseCases.getCryptoListBy(0) | |
.test() | |
.assertError(response) | |
} | |
@Test | |
fun testCryptoListUseCases_getCryptoList_response() { | |
val response = arrayListOf(cryptoPOJOmodel()) | |
whenever(coinMarketCapRepository.getCryptoList(anyInt(), anyInt())) | |
.thenReturn(Single.just(response)) | |
val expectedList = arrayListOf(cryptoViewModelFrom(cryptoPOJOmodel())) | |
cryptoListUseCases.getCryptoListBy(0) | |
.test() | |
.assertValue(expectedList) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment