|
1 | 1 | package com.box.sdk; |
2 | 2 |
|
| 3 | +import java.net.MalformedURLException; |
| 4 | +import java.net.URL; |
| 5 | + |
3 | 6 | import static org.hamcrest.Matchers.equalTo; |
4 | 7 | import static org.hamcrest.Matchers.is; |
5 | 8 | import static org.hamcrest.Matchers.not; |
6 | 9 | import static org.junit.Assert.assertThat; |
| 10 | +import static org.mockito.Matchers.any; |
| 11 | +import static org.mockito.Mockito.mock; |
| 12 | +import static org.mockito.Mockito.when; |
7 | 13 |
|
8 | 14 | import org.junit.Test; |
9 | 15 | import org.junit.experimental.categories.Category; |
@@ -44,6 +50,38 @@ public void doesNotNeedRefreshWhenExpiresIsZero() { |
44 | 50 | assertThat(api.needsRefresh(), is(not(true))); |
45 | 51 | } |
46 | 52 |
|
| 53 | + @Test |
| 54 | + @Category(UnitTest.class) |
| 55 | + public void interceptorReceivesSentRequest() throws MalformedURLException { |
| 56 | + BoxAPIConnection api = new BoxAPIConnection(""); |
| 57 | + |
| 58 | + BoxAPIResponse fakeResponse = new BoxAPIResponse(); |
| 59 | + |
| 60 | + RequestInterceptor mockInterceptor = mock(RequestInterceptor.class); |
| 61 | + when(mockInterceptor.onRequest(any(BoxAPIRequest.class))).thenReturn(fakeResponse); |
| 62 | + api.setRequestInterceptor(mockInterceptor); |
| 63 | + |
| 64 | + BoxAPIRequest request = new BoxAPIRequest(api, new URL("http://anyurl.com"), "GET"); |
| 65 | + BoxAPIResponse response = request.send(); |
| 66 | + |
| 67 | + assertThat(response, is(equalTo(fakeResponse))); |
| 68 | + } |
| 69 | + |
| 70 | + @Test |
| 71 | + @Category(IntegrationTest.class) |
| 72 | + public void requestIsSentNormallyWhenInterceptorReturnsNullResponse() throws MalformedURLException { |
| 73 | + BoxAPIConnection api = new BoxAPIConnection(""); |
| 74 | + |
| 75 | + RequestInterceptor mockInterceptor = mock(RequestInterceptor.class); |
| 76 | + when(mockInterceptor.onRequest(any(BoxAPIRequest.class))).thenReturn(null); |
| 77 | + api.setRequestInterceptor(mockInterceptor); |
| 78 | + |
| 79 | + BoxAPIRequest request = new BoxAPIRequest(api, new URL("http://box.com"), "GET"); |
| 80 | + BoxAPIResponse response = request.send(); |
| 81 | + |
| 82 | + assertThat(response.getResponseCode(), is(200)); |
| 83 | + } |
| 84 | + |
47 | 85 | @Test |
48 | 86 | @Category(IntegrationTest.class) |
49 | 87 | public void refreshSucceeds() { |
|
0 commit comments