Created
July 30, 2020 01:26
-
-
Save gbzarelli/9391d6b146c40d3be4ed0367fe6c18b3 to your computer and use it in GitHub Desktop.
Used in Medium article about Tests
This file contains 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
@SpringBootTest | |
class WeatherClientIntegrationTest { | |
@Autowired | |
private WeatherClient subject; | |
@Rule | |
public WireMockRule wireMockRule = new WireMockRule(8089); | |
@Test | |
void shouldCallWeatherService() throws Exception { | |
//given | |
wireMockRule.stubFor(get(urlPathEqualTo("/some-test-api-key/53.5511,9.9937")) | |
.willReturn(aResponse() | |
.withBody(FileLoader.read("classpath:weatherApiResponse.json")) | |
.withHeader(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) | |
.withStatus(200))); | |
//when | |
Optional<WeatherResponse> weatherResponse = subject.fetchWeather(); | |
//then | |
Optional<WeatherResponse> expectedResponse = Optional.of(new WeatherResponse("Rain")); | |
assertThat(weatherResponse, is(expectedResponse)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment