|
1 | 1 | package com.auth0.net; |
2 | 2 |
|
| 3 | +import com.auth0.exception.Auth0Exception; |
3 | 4 | import okhttp3.OkHttpClient; |
4 | 5 | import okhttp3.Request; |
5 | 6 | import okhttp3.Response; |
6 | 7 | import okhttp3.mockwebserver.MockResponse; |
7 | 8 | import okhttp3.mockwebserver.MockWebServer; |
8 | 9 | import okhttp3.mockwebserver.RecordedRequest; |
| 10 | +import okhttp3.mockwebserver.SocketPolicy; |
9 | 11 | import org.junit.After; |
10 | 12 | import org.junit.Before; |
11 | 13 | import org.junit.Test; |
12 | 14 |
|
| 15 | +import java.time.Duration; |
13 | 16 | import java.util.ArrayList; |
14 | 17 | import java.util.List; |
15 | 18 |
|
16 | 19 | import static org.hamcrest.CoreMatchers.is; |
17 | 20 | import static org.hamcrest.MatcherAssert.assertThat; |
18 | 21 | import static org.hamcrest.Matchers.closeTo; |
19 | 22 | import static org.hamcrest.Matchers.greaterThan; |
| 23 | +import static org.junit.Assert.assertThrows; |
20 | 24 |
|
21 | 25 | public class RateLimitInterceptorTest { |
22 | 26 |
|
@@ -175,4 +179,21 @@ public void shouldBackOffOnRetries() throws Exception { |
175 | 179 | assertThat(retryTimings.get(5), greaterThan(retryTimings.get(2))); |
176 | 180 | } |
177 | 181 |
|
| 182 | + @Test |
| 183 | + public void shouldThrowAuth0Exception() { |
| 184 | + OkHttpClient client = new OkHttpClient.Builder() |
| 185 | + .addInterceptor(new RateLimitInterceptor(3)) |
| 186 | + .readTimeout(Duration.ofSeconds(1)) |
| 187 | + .build(); |
| 188 | + |
| 189 | + server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.NO_RESPONSE)); |
| 190 | + |
| 191 | + okhttp3.Request request = new Request.Builder() |
| 192 | + .get() |
| 193 | + .url(server.url("/")) |
| 194 | + .build(); |
| 195 | + |
| 196 | + Auth0Exception e = assertThrows(Auth0Exception.class, () -> client.newCall(request).execute()); |
| 197 | + assertThat(e.getMessage(), is("Failed to execute request")); |
| 198 | + } |
178 | 199 | } |
0 commit comments