Skip to content

Commit 2a10e5d

Browse files
authored
fix: Fallback to default value of maxRetryAttempts when restoring BoxAPIConnection (#1161)
Closes: SDK-3109 Fixes: #1160
1 parent d85e755 commit 2a10e5d

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,8 @@ public void restore(String state) {
862862
// Try to use deprecated value "maxRequestAttempts", else use newer value "maxRetryAttempts"
863863
if (maxRequestAttempts > -1) {
864864
this.maxRetryAttempts = maxRequestAttempts - 1;
865-
} else {
865+
}
866+
if (maxRetryAttempts > -1) {
866867
this.maxRetryAttempts = maxRetryAttempts;
867868
}
868869

src/test/java/com/box/sdk/BoxAPIConnectionTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,31 @@ public void restoresProperUrlsWhenSomeAreMissing() {
624624
assertThat("https://upload.box.com/api/2.0/", is(restoredApi.getBaseUploadURL()));
625625
}
626626

627+
@Test
628+
public void restoresDefaultMaxRequestAttemptsWhenMissing() {
629+
// given
630+
String accessToken = "access_token";
631+
String clientId = "some_client_id";
632+
String clientSecret = "some_client_secret";
633+
String refreshToken = "some_refresh_token";
634+
635+
String savedConnection = "{"
636+
+ "\"accessToken\":\"access_token\","
637+
+ "\"refreshToken\":\"some_refresh_token\","
638+
+ "\"lastRefresh\":0,"
639+
+ "\"expires\":0,"
640+
+ "\"userAgent\":\"Box Java SDK v3.8.0 (Java 1.8.0_345)\","
641+
+ "\"baseURL\":\"https://api.box.com/\","
642+
+ "\"authorizationURL\":\"https://account.box.com/api/\","
643+
+ "\"autoRefresh\":true"
644+
+ "}";
645+
// when
646+
BoxAPIConnection restoredApi = BoxAPIConnection.restore(clientId, clientSecret, savedConnection);
647+
648+
// then
649+
assertThat(BoxGlobalSettings.getMaxRetryAttempts(), is(restoredApi.getMaxRetryAttempts()));
650+
}
651+
627652
@Test
628653
public void successfullyRestoresConnectionWithDeprecatedSettings() {
629654
String restoreState = TestUtils.getFixture("BoxAPIConnection/State");

0 commit comments

Comments
 (0)