Last active
January 3, 2020 19:26
-
-
Save anibalbastiass/250bdd8cd7cdc047891cca2f2d7e359f to your computer and use it in GitHub Desktop.
CurrenciesRepositoryImplTest.kt
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(JUnit4::class) | |
class CurrenciesRepositoryImplTest { | |
private val restApi = mock<ForeignExchangeApiService>() | |
private val mapper = mock<CurrenciesUiMapper>() | |
private val testDispatcher = TestCoroutineDispatcher() | |
private val currenciesRemoteImpl = CurrenciesRepositoryImpl(restApi, mapper) | |
private val managedCoroutineScope: ManagedCoroutineScope = | |
TestScope( | |
testDispatcher | |
) | |
@Before | |
fun setup() { | |
Dispatchers.setMain(testDispatcher) | |
} | |
@Test | |
fun `given RemoteCurrency, when GetLatestCurrencies, then assert not null`() { | |
stubRestApiGetLatestCurrencies(makeRemoteCurrencies()) | |
managedCoroutineScope.launch { | |
withContext(testDispatcher) { | |
val response = currenciesRemoteImpl.getLatestCurrencies("HRK") | |
Assert.assertNotNull(response) | |
} | |
} | |
} | |
@Test | |
fun `given RemoteCurrency, when GetLatestCurrencies, then returns data`() { | |
val remoteCurrencies = makeRemoteCurrencies() | |
stubRestApiGetLatestCurrencies(remoteCurrencies) | |
managedCoroutineScope.launch { | |
withContext(testDispatcher) { | |
val response = currenciesRemoteImpl.getLatestCurrencies("HRK") | |
Assert.assertEquals(response, remoteCurrencies) | |
} | |
} | |
} | |
private fun stubRestApiGetLatestCurrencies(currencies: RemoteCurrencies) { | |
whenever(restApi.getLatestCurrencies("HRK")).thenReturn(CallFake.buildSuccess(currencies)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment