|
| 1 | +package se.michaelthelin.spotify; |
| 2 | + |
| 3 | +import com.github.tomakehurst.wiremock.junit5.WireMockTest; |
| 4 | +import org.apache.hc.core5.http.Header; |
| 5 | +import org.junit.jupiter.api.Assertions; |
| 6 | +import org.junit.jupiter.params.ParameterizedTest; |
| 7 | +import org.junit.jupiter.params.provider.ValueSource; |
| 8 | +import se.michaelthelin.spotify.SpotifyHttpManager.Builder; |
| 9 | +import se.michaelthelin.spotify.exceptions.SpotifyWebApiException; |
| 10 | + |
| 11 | +import java.net.URI; |
| 12 | + |
| 13 | +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; |
| 14 | +import static com.github.tomakehurst.wiremock.client.WireMock.get; |
| 15 | +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; |
| 16 | + |
| 17 | +@WireMockTest(httpPort = 9090) |
| 18 | +class SpotifyHttpManagerTest { |
| 19 | + |
| 20 | + private final SpotifyHttpManager spotifyHttpManager = new SpotifyHttpManager(new Builder()); |
| 21 | + |
| 22 | + @ParameterizedTest |
| 23 | + @ValueSource(ints = {405, 409, 410, 414, 422, 431, 499}) |
| 24 | + public void throwsSpotifyWebApiExceptionForAll4xxStatusCodes(int statusCode) { |
| 25 | + |
| 26 | + stubFor(get("/test/foo/") |
| 27 | + .willReturn(aResponse() |
| 28 | + .withStatus(statusCode))); |
| 29 | + |
| 30 | + Assertions.assertThrows(SpotifyWebApiException.class, () -> |
| 31 | + spotifyHttpManager.get(URI.create("http://localhost:9090/test/foo/"), new Header[0])); |
| 32 | + } |
| 33 | + |
| 34 | + @ParameterizedTest |
| 35 | + @ValueSource(ints = {501, 504, 599}) |
| 36 | + public void throwsSpotifyWebApiExceptionForAll5xxStatusCodes(int statusCode) { |
| 37 | + |
| 38 | + stubFor(get("/test/foo/") |
| 39 | + .willReturn(aResponse() |
| 40 | + .withStatus(statusCode))); |
| 41 | + |
| 42 | + Assertions.assertThrows(SpotifyWebApiException.class, () -> |
| 43 | + spotifyHttpManager.get(URI.create("http://localhost:9090/test/foo/"), new Header[0])); |
| 44 | + } |
| 45 | +} |
0 commit comments