• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-java-sdk / #4747

19 Aug 2025 10:21AM UTC coverage: 38.858% (+0.03%) from 38.831%
#4747

push

github

web-flow
feat: Support external user deletion API

20 of 167 new or added lines in 8 files covered. (11.98%)

9 existing lines in 4 files now uncovered.

19121 of 49207 relevant lines covered (38.86%)

0.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

44.83
/src/main/java/com/box/sdkgen/networking/retries/BoxRetryStrategy.java
1
package com.box.sdkgen.networking.retries;
2

3
import static com.box.sdkgen.internal.utils.UtilsManager.random;
4

5
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
6
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
7

8
public class BoxRetryStrategy implements RetryStrategy {
9

10
  public int maxAttempts;
11

12
  public double retryRandomizationFactor;
13

14
  public double retryBaseInterval;
15

16
  public int maxRetriesOnException;
17

18
  public BoxRetryStrategy() {
1✔
19
    this.maxAttempts = 5;
1✔
20
    this.retryRandomizationFactor = 0.5;
1✔
21
    this.retryBaseInterval = 1;
1✔
22
    this.maxRetriesOnException = 2;
1✔
23
  }
1✔
24

25
  protected BoxRetryStrategy(Builder builder) {
×
26
    this.maxAttempts = builder.maxAttempts;
×
27
    this.retryRandomizationFactor = builder.retryRandomizationFactor;
×
28
    this.retryBaseInterval = builder.retryBaseInterval;
×
29
    this.maxRetriesOnException = builder.maxRetriesOnException;
×
30
  }
×
31

32
  @Override
33
  public boolean shouldRetry(
34
      FetchOptions fetchOptions, FetchResponse fetchResponse, int attemptNumber) {
35
    if (fetchResponse.getStatus() == 0) {
1✔
36
      return attemptNumber <= this.maxRetriesOnException;
1✔
37
    }
38
    boolean isSuccessful = fetchResponse.getStatus() >= 200 && fetchResponse.getStatus() < 400;
1✔
39
    String retryAfterHeader = fetchResponse.getHeaders().get("Retry-After");
1✔
40
    boolean isAcceptedWithRetryAfter =
1✔
41
        fetchResponse.getStatus() == 202 && !(retryAfterHeader == null);
1✔
42
    if (attemptNumber >= this.maxAttempts) {
1✔
43
      return false;
×
44
    }
45
    if (isAcceptedWithRetryAfter) {
1✔
46
      return true;
×
47
    }
48
    if (fetchResponse.getStatus() >= 500) {
1✔
UNCOV
49
      return true;
×
50
    }
51
    if (fetchResponse.getStatus() == 429) {
1✔
52
      return true;
×
53
    }
54
    if (fetchResponse.getStatus() == 401 && !(fetchOptions.getAuth() == null)) {
1✔
55
      fetchOptions.getAuth().refreshToken(fetchOptions.getNetworkSession());
×
56
      return true;
×
57
    }
58
    if (isSuccessful) {
1✔
59
      return false;
1✔
60
    }
61
    return false;
1✔
62
  }
63

64
  @Override
65
  public double retryAfter(
66
      FetchOptions fetchOptions, FetchResponse fetchResponse, int attemptNumber) {
67
    String retryAfterHeader = fetchResponse.getHeaders().get("Retry-After");
1✔
68
    if (!(retryAfterHeader == null)) {
1✔
69
      return Double.parseDouble(retryAfterHeader);
×
70
    }
71
    double randomization =
1✔
72
        random(1 - this.retryRandomizationFactor, 1 + this.retryRandomizationFactor);
1✔
73
    double exponential = Math.pow(2, attemptNumber);
1✔
74
    return exponential * this.retryBaseInterval * randomization;
1✔
75
  }
76

77
  public int getMaxAttempts() {
78
    return maxAttempts;
×
79
  }
80

81
  public double getRetryRandomizationFactor() {
82
    return retryRandomizationFactor;
×
83
  }
84

85
  public double getRetryBaseInterval() {
86
    return retryBaseInterval;
×
87
  }
88

89
  public int getMaxRetriesOnException() {
90
    return maxRetriesOnException;
×
91
  }
92

93
  public static class Builder {
94

95
    protected int maxAttempts;
96

97
    protected double retryRandomizationFactor;
98

99
    protected double retryBaseInterval;
100

101
    protected int maxRetriesOnException;
102

103
    public Builder() {
×
104
      this.maxAttempts = 5;
×
105
      this.retryRandomizationFactor = 0.5;
×
106
      this.retryBaseInterval = 1;
×
107
      this.maxRetriesOnException = 2;
×
108
    }
×
109

110
    public Builder maxAttempts(int maxAttempts) {
111
      this.maxAttempts = maxAttempts;
×
112
      return this;
×
113
    }
114

115
    public Builder retryRandomizationFactor(double retryRandomizationFactor) {
116
      this.retryRandomizationFactor = retryRandomizationFactor;
×
117
      return this;
×
118
    }
119

120
    public Builder retryBaseInterval(double retryBaseInterval) {
121
      this.retryBaseInterval = retryBaseInterval;
×
122
      return this;
×
123
    }
124

125
    public Builder maxRetriesOnException(int maxRetriesOnException) {
126
      this.maxRetriesOnException = maxRetriesOnException;
×
127
      return this;
×
128
    }
129

130
    public BoxRetryStrategy build() {
131
      return new BoxRetryStrategy(this);
×
132
    }
133
  }
134
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc