Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import io.reactivex.Single
import io.reactivex.schedulers.TestScheduler
import org.junit.Test
class MainScreenPresenterTest {
private val fakeCurrencyList: List<CurrencyModel> = listOf(
CurrencyModel(
name = "Bitcoin",
symbol = "BTC",
priceUsd = "9877.96"
),
CurrencyModel(
name = "Etherum",
symbol = "ETH",
priceUsd = "271.57"
)
)
@Test
fun `GIVEN successful data fetch WHEN screen opens THEN display data`() {
val view: MainScreenContract.View = mockk(relaxed = true)
val fetchCurrencyUseCase: FetchCurrencyUseCase = mockk {
every { execute() } returns Single.just(fakeCurrencyList)
}
val presenter = MainScreenPresenter(
fetchCurrencyUseCase = fetchCurrencyUseCase,
schedulerProvider = TrampolineTestSchedulers()
)
presenter.attach(view)
verify {
view.displayData(fakeCurrencyList)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment