Skip to content

Commit b2b6a1d

Browse files
authored
fix: SharedLinkAPIConnection uses request interceptor (#1203)
Fixes #1200
1 parent fcb6657 commit b2b6a1d

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/main/java/com/box/sdk/SharedLinkAPIConnection.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ void unlockAccessToken() {
140140
this.wrappedConnection.unlockAccessToken();
141141
}
142142

143+
@Override
144+
public RequestInterceptor getRequestInterceptor() {
145+
return this.wrappedConnection.getRequestInterceptor();
146+
}
147+
143148
/**
144149
* Gets the shared link used for accessing shared items.
145150
*
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.box.sdk;
2+
3+
import com.eclipsesource.json.JsonObject;
4+
import org.hamcrest.CoreMatchers;
5+
import org.hamcrest.MatcherAssert;
6+
import org.junit.Test;
7+
8+
import java.util.Collections;
9+
10+
public class BoxItemTest {
11+
@Test
12+
public void shouldUseRequestInterceptor() {
13+
String itemType = "file";
14+
String itemId = "some_id";
15+
BoxAPIConnection api = new BoxAPIConnection("");
16+
api.setRequestInterceptor(request -> {
17+
if ("https://api.box.com/2.0/shared_items".equals(request.getUrl().toString())) {
18+
JsonObject body = new JsonObject();
19+
body.add("type", itemType);
20+
body.add("id", itemId);
21+
return new BoxJSONResponse(
22+
200,
23+
request.getMethod(),
24+
request.getUrl().toString(),
25+
Collections.emptyMap(),
26+
body
27+
);
28+
}
29+
return null;
30+
});
31+
32+
BoxItem.Info item = BoxItem.getSharedItem(api, "some_link");
33+
MatcherAssert.assertThat(item.getType(), CoreMatchers.is(itemType));
34+
MatcherAssert.assertThat(item.getID(), CoreMatchers.is(itemId));
35+
}
36+
}

0 commit comments

Comments
 (0)