Skip to content

Instantly share code, notes, and snippets.

@fbcbl
Last active October 9, 2017 12:28
Show Gist options
  • Save fbcbl/92eb4128112fc0246dba7e9ebdd15fe9 to your computer and use it in GitHub Desktop.
Save fbcbl/92eb4128112fc0246dba7e9ebdd15fe9 to your computer and use it in GitHub Desktop.
kotlin_testing_pt2_example_2_java_test
package testing.fabiocarballo.com.myapplication;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
public class TemperaturePresenterJavaTest {
@Mock
LocationProvider locationProvider;
@Mock
TemperatureProvider temperatureProvider;
@Mock
View view;
TemperaturePresenter tested;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
tested = new TemperaturePresenter(
locationProvider, temperatureProvider, view);
}
@Test
public void testInexactTemperatureIsDisplayedFollowedByExactTemperature() {
Coordinate lastLocation = new Coordinate(41.5, 8.9);
Coordinate currentLocation = new 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();
InOrder inOrder = Mockito.inOrder(temperatureProvider, view);
inOrder.verify(temperatureProvider).getCelsiusTemperatureAt(lastLocation);
inOrder.verify(view).displayTemperature(18f);
inOrder.verify(temperatureProvider).getCelsiusTemperatureAt(currentLocation);
inOrder.verify(view).displayTemperature(21f);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment