Skip to content

Instantly share code, notes, and snippets.

@gbzarelli
Created July 30, 2020 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbzarelli/9391d6b146c40d3be4ed0367fe6c18b3 to your computer and use it in GitHub Desktop.
Save gbzarelli/9391d6b146c40d3be4ed0367fe6c18b3 to your computer and use it in GitHub Desktop.
Used in Medium article about Tests
@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