Skip to content

Instantly share code, notes, and snippets.

@fbcbl
Last active October 9, 2017 10:57
Show Gist options
  • Save fbcbl/b86abc23ba897a9dba45635dd904729b to your computer and use it in GitHub Desktop.
Save fbcbl/b86abc23ba897a9dba45635dd904729b to your computer and use it in GitHub Desktop.
kotlin_testing_pt2_example_1_test_3
class TemperaturePresenterTest {
private val lastLocation = Coordinate(41.5, 8.9)
private val currentLocation = Coordinate(38.7, 9.7)
val locationProvider: LocationProvider = mock {
on { getLastKnownLocation() }.then { lastLocation }
on { getExactLocation() }.then { currentLocation }
}
val temperatureProvider: TemperatureProvider = mock()
val view: View = mock()
var tested: TemperaturePresenter = TemperaturePresenter(
locationProvider, temperatureProvider, view)
@Test
fun `display temperature for last known location first, and then for exact location`() {
whenever(temperatureProvider.getCelsiusTemperatureAt(lastLocation))
.thenReturn(18f)
whenever(temperatureProvider.getCelsiusTemperatureAt(currentLocation))
.thenReturn(21f)
tested.start()
inOrder(temperatureProvider, view).apply {
verify(temperatureProvider).getCelsiusTemperatureAt(lastLocation)
verify(view).displayTemperature(18f)
verify(temperatureProvider).getCelsiusTemperatureAt(currentLocation)
verify(view).displayTemperature(21f)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment