From bd34db14f0e08fe56b85cbfcc9f5e6253ef825b9 Mon Sep 17 00:00:00 2001 From: Kamil Berdychowski Date: Tue, 12 Sep 2023 15:17:42 +0200 Subject: [PATCH] fix: `SharedLinkAPIConnection` uses request interceptor --- .../com/box/sdk/SharedLinkAPIConnection.java | 5 +++ src/test/java/com/box/sdk/BoxItemTest.java | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/test/java/com/box/sdk/BoxItemTest.java diff --git a/src/main/java/com/box/sdk/SharedLinkAPIConnection.java b/src/main/java/com/box/sdk/SharedLinkAPIConnection.java index ec9352b82..22e29ef01 100644 --- a/src/main/java/com/box/sdk/SharedLinkAPIConnection.java +++ b/src/main/java/com/box/sdk/SharedLinkAPIConnection.java @@ -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. * diff --git a/src/test/java/com/box/sdk/BoxItemTest.java b/src/test/java/com/box/sdk/BoxItemTest.java new file mode 100644 index 000000000..01cc7f061 --- /dev/null +++ b/src/test/java/com/box/sdk/BoxItemTest.java @@ -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)); + } +}