radityagumay
04/21/2018, 2:42 AMclass WeatherPresenterTest : Spek ({
given("a weather presenter") {
val repository = mock<WeatherRepository>()
val view = mock<WeatherView>()
val presenter = WeatherPresenter(repository)
beforeEachTest {
presenter.attachView(view)
}
whenever("fetch weather") {
then("return success") {
repository.fetchWeather() willReturnSingle weatherData // this weatherData from fixture
presenter.fetchWeather()
verify(view).onLoadWeatherSuccess(weatherData)
verifyNoMoreInteraction(view)
}
then("return error") {
repository.fetchWeather() willReturnSingleError weatherDataError // this weatherData from fixture
presenter.fetchWeather()
verify(view).onLoadWeatherError(weatherDataError)
verifyNoMoreInteraction(view)
}
}
afterEachTest {
presenter.detachView()
}
}
})