Skip to content

Commit

Permalink
fix: SharedLinkAPIConnection uses request interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
antusus committed Sep 12, 2023
1 parent 2e931d8 commit bd34db1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/box/sdk/SharedLinkAPIConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ void unlockAccessToken() {
this.wrappedConnection.unlockAccessToken();
}

@Override
public RequestInterceptor getRequestInterceptor() {
return this.wrappedConnection.getRequestInterceptor();
}

/**
* Gets the shared link used for accessing shared items.
*
Expand Down
36 changes: 36 additions & 0 deletions src/test/java/com/box/sdk/BoxItemTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.box.sdk;

import com.eclipsesource.json.JsonObject;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Test;

import java.util.Collections;

public class BoxItemTest {
@Test
public void shouldUseRequestInterceptor() {
String itemType = "file";
String itemId = "some_id";
BoxAPIConnection api = new BoxAPIConnection("");
api.setRequestInterceptor(request -> {
if ("https://api.box.com/2.0/shared_items".equals(request.getUrl().toString())) {
JsonObject body = new JsonObject();
body.add("type", itemType);
body.add("id", itemId);
return new BoxJSONResponse(
200,
request.getMethod(),
request.getUrl().toString(),
Collections.emptyMap(),
body
);
}
return null;
});

BoxItem.Info item = BoxItem.getSharedItem(api, "some_link");
MatcherAssert.assertThat(item.getType(), CoreMatchers.is(itemType));
MatcherAssert.assertThat(item.getID(), CoreMatchers.is(itemId));
}
}

0 comments on commit bd34db1

Please sign in to comment.