Skip to content

Instantly share code, notes, and snippets.

@fbcbl
Last active October 9, 2017 10:11
Show Gist options
  • Save fbcbl/5207ecda6a11ce2afb3c422b48684ee5 to your computer and use it in GitHub Desktop.
Save fbcbl/5207ecda6a11ce2afb3c422b48684ee5 to your computer and use it in GitHub Desktop.
kotlin
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 testInexactTemperatureIsDisplayedFollowedByExactTemperature() {
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()
val inOrder = Mockito.inOrder(temperatureProvider, view)
inOrder.verify<TemperatureProvider>(temperatureProvider)
.getCelsiusTemperatureAt(lastLocation)
inOrder.verify<View>(view).displayTemperature(18f)
inOrder.verify<TemperatureProvider>(temperatureProvider)
.getCelsiusTemperatureAt(currentLocation)
inOrder.verify<View>(view).displayTemperature(21f)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment