Last active
October 9, 2017 10:54
-
-
Save fbcbl/d6281642630bb9c118241606335a3a46 to your computer and use it in GitHub Desktop.
kotlin_testing_pt2_example_1_test_2
This file contains hidden or 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
| class TemperaturePresenterTest { | |
| @Mock lateinit var locationProvider: LocationProvider | |
| @Mock lateinit var temperatureProvider: TemperatureProvider | |
| @Mock lateinit var view: View | |
| lateinit var tested: TemperaturePresenter | |
| @Before | |
| fun setUp() { | |
| MockitoAnnotations.initMocks(this) | |
| tested = TemperaturePresenter(locationProvider, temperatureProvider, view) | |
| } | |
| @Test | |
| fun `display temperature for last known location first, and then for exact location`() { | |
| val lastLocation = Coordinate(41.5, 8.9) | |
| val currentLocation = Coordinate(38.7, 9.7) | |
| Mockito.`when`(locationProvider.getLastKnownLocation()) | |
| .thenReturn(lastLocation) | |
| Mockito.`when`(locationProvider.getExactLocation()) | |
| .thenReturn(currentLocation) | |
| Mockito.`when`(temperatureProvider.getCelsiusTemperatureAt(lastLocation)) | |
| .thenReturn(18f) | |
| Mockito.`when`(temperatureProvider.getCelsiusTemperatureAt(currentLocation)) | |
| .thenReturn(21f) | |
| tested.start() | |
| Mockito.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