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

box / box-java-sdk-gen / #194

12 Jun 2025 08:30AM UTC coverage: 35.732% (+0.1%) from 35.619%
#194

push

github

web-flow
test: Remove predefined dates from events integration test (box/box-codegen#740) (#329)

1 of 2 new or added lines in 1 file covered. (50.0%)

1156 existing lines in 311 files now uncovered.

16212 of 45371 relevant lines covered (35.73%)

0.36 hits per line

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

34.0
/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 BoxRetryStrategy() {
1✔
17
    this.maxAttempts = 5;
1✔
18
    this.retryRandomizationFactor = 0.5;
1✔
19
    this.retryBaseInterval = 1;
1✔
20
  }
1✔
21

22
  protected BoxRetryStrategy(BoxRetryStrategyBuilder builder) {
×
23
    this.maxAttempts = builder.maxAttempts;
×
24
    this.retryRandomizationFactor = builder.retryRandomizationFactor;
×
25
    this.retryBaseInterval = builder.retryBaseInterval;
×
26
  }
×
27

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

57
  @Override
58
  public double retryAfter(
59
      FetchOptions fetchOptions, FetchResponse fetchResponse, int attemptNumber) {
UNCOV
60
    String retryAfterHeader = fetchResponse.getHeaders().get("Retry-After");
×
UNCOV
61
    if (!(retryAfterHeader == null)) {
×
UNCOV
62
      return Double.parseDouble(retryAfterHeader);
×
63
    }
64
    double randomization =
×
65
        random(1 - this.retryRandomizationFactor, 1 + this.retryRandomizationFactor);
×
66
    double exponential = Math.pow(2, attemptNumber);
×
67
    return exponential * this.retryBaseInterval * randomization;
×
68
  }
69

70
  public int getMaxAttempts() {
71
    return maxAttempts;
×
72
  }
73

74
  public double getRetryRandomizationFactor() {
75
    return retryRandomizationFactor;
×
76
  }
77

78
  public double getRetryBaseInterval() {
79
    return retryBaseInterval;
×
80
  }
81

82
  public static class BoxRetryStrategyBuilder {
83

84
    protected int maxAttempts;
85

86
    protected double retryRandomizationFactor;
87

88
    protected double retryBaseInterval;
89

UNCOV
90
    public BoxRetryStrategyBuilder() {
×
91
      this.maxAttempts = 5;
×
92
      this.retryRandomizationFactor = 0.5;
×
UNCOV
93
      this.retryBaseInterval = 1;
×
UNCOV
94
    }
×
95

96
    public BoxRetryStrategyBuilder maxAttempts(int maxAttempts) {
97
      this.maxAttempts = maxAttempts;
×
UNCOV
98
      return this;
×
99
    }
100

101
    public BoxRetryStrategyBuilder retryRandomizationFactor(double retryRandomizationFactor) {
102
      this.retryRandomizationFactor = retryRandomizationFactor;
×
UNCOV
103
      return this;
×
104
    }
105

106
    public BoxRetryStrategyBuilder retryBaseInterval(double retryBaseInterval) {
UNCOV
107
      this.retryBaseInterval = retryBaseInterval;
×
UNCOV
108
      return this;
×
109
    }
110

111
    public BoxRetryStrategy build() {
UNCOV
112
      return new BoxRetryStrategy(this);
×
113
    }
114
  }
115
}
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