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

box / box-java-sdk / #5076

07 Oct 2025 12:35PM UTC coverage: 37.132% (+0.007%) from 37.125%
#5076

push

github

web-flow
test: Change `Event.additionalDetails` field assertion in events test (box/box-codegen#858) (#1491)

18454 of 49699 relevant lines covered (37.13%)

0.37 hits per line

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

92.54
/src/main/java/com/box/sdkgen/managers/avatars/AvatarsManager.java
1
package com.box.sdkgen.managers.avatars;
2

3
import static com.box.sdkgen.internal.utils.UtilsManager.convertToString;
4
import static com.box.sdkgen.internal.utils.UtilsManager.mapOf;
5
import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps;
6
import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams;
7

8
import com.box.sdkgen.networking.auth.Authentication;
9
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
10
import com.box.sdkgen.networking.fetchoptions.MultipartItem;
11
import com.box.sdkgen.networking.fetchoptions.ResponseFormat;
12
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
13
import com.box.sdkgen.networking.network.NetworkSession;
14
import com.box.sdkgen.schemas.useravatar.UserAvatar;
15
import com.box.sdkgen.serialization.json.JsonManager;
16
import java.io.InputStream;
17
import java.util.Arrays;
18
import java.util.Map;
19

20
public class AvatarsManager {
21

22
  public Authentication auth;
23

24
  public NetworkSession networkSession;
25

26
  public AvatarsManager() {
×
27
    this.networkSession = new NetworkSession();
×
28
  }
×
29

30
  protected AvatarsManager(Builder builder) {
1✔
31
    this.auth = builder.auth;
1✔
32
    this.networkSession = builder.networkSession;
1✔
33
  }
1✔
34

35
  /**
36
   * Retrieves an image of a the user's avatar.
37
   *
38
   * @param userId The ID of the user. Example: "12345"
39
   */
40
  public InputStream getUserAvatar(String userId) {
41
    return getUserAvatar(userId, new GetUserAvatarHeaders());
1✔
42
  }
43

44
  /**
45
   * Retrieves an image of a the user's avatar.
46
   *
47
   * @param userId The ID of the user. Example: "12345"
48
   * @param headers Headers of getUserAvatar method
49
   */
50
  public InputStream getUserAvatar(String userId, GetUserAvatarHeaders headers) {
51
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
52
    FetchResponse response =
1✔
53
        this.networkSession
54
            .getNetworkClient()
1✔
55
            .fetch(
1✔
56
                new FetchOptions.Builder(
57
                        String.join(
1✔
58
                            "",
59
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
60
                            "/2.0/users/",
61
                            convertToString(userId),
1✔
62
                            "/avatar"),
63
                        "GET")
64
                    .headers(headersMap)
1✔
65
                    .responseFormat(ResponseFormat.BINARY)
1✔
66
                    .auth(this.auth)
1✔
67
                    .networkSession(this.networkSession)
1✔
68
                    .build());
1✔
69
    return response.getContent();
1✔
70
  }
71

72
  /**
73
   * Adds or updates a user avatar.
74
   *
75
   * @param userId The ID of the user. Example: "12345"
76
   * @param requestBody Request body of createUserAvatar method
77
   */
78
  public UserAvatar createUserAvatar(String userId, CreateUserAvatarRequestBody requestBody) {
79
    return createUserAvatar(userId, requestBody, new CreateUserAvatarHeaders());
1✔
80
  }
81

82
  /**
83
   * Adds or updates a user avatar.
84
   *
85
   * @param userId The ID of the user. Example: "12345"
86
   * @param requestBody Request body of createUserAvatar method
87
   * @param headers Headers of createUserAvatar method
88
   */
89
  public UserAvatar createUserAvatar(
90
      String userId, CreateUserAvatarRequestBody requestBody, CreateUserAvatarHeaders headers) {
91
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
92
    FetchResponse response =
1✔
93
        this.networkSession
94
            .getNetworkClient()
1✔
95
            .fetch(
1✔
96
                new FetchOptions.Builder(
97
                        String.join(
1✔
98
                            "",
99
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
100
                            "/2.0/users/",
101
                            convertToString(userId),
1✔
102
                            "/avatar"),
103
                        "POST")
104
                    .headers(headersMap)
1✔
105
                    .multipartData(
1✔
106
                        Arrays.asList(
1✔
107
                            new MultipartItem.Builder("pic")
108
                                .fileStream(requestBody.getPic())
1✔
109
                                .fileName(requestBody.getPicFileName())
1✔
110
                                .contentType(requestBody.getPicContentType())
1✔
111
                                .build()))
1✔
112
                    .contentType("multipart/form-data")
1✔
113
                    .responseFormat(ResponseFormat.JSON)
1✔
114
                    .auth(this.auth)
1✔
115
                    .networkSession(this.networkSession)
1✔
116
                    .build());
1✔
117
    return JsonManager.deserialize(response.getData(), UserAvatar.class);
1✔
118
  }
119

120
  /**
121
   * Removes an existing user avatar. You cannot reverse this operation.
122
   *
123
   * @param userId The ID of the user. Example: "12345"
124
   */
125
  public void deleteUserAvatar(String userId) {
126
    deleteUserAvatar(userId, new DeleteUserAvatarHeaders());
1✔
127
  }
1✔
128

129
  /**
130
   * Removes an existing user avatar. You cannot reverse this operation.
131
   *
132
   * @param userId The ID of the user. Example: "12345"
133
   * @param headers Headers of deleteUserAvatar method
134
   */
135
  public void deleteUserAvatar(String userId, DeleteUserAvatarHeaders headers) {
136
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
137
    FetchResponse response =
1✔
138
        this.networkSession
139
            .getNetworkClient()
1✔
140
            .fetch(
1✔
141
                new FetchOptions.Builder(
142
                        String.join(
1✔
143
                            "",
144
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
145
                            "/2.0/users/",
146
                            convertToString(userId),
1✔
147
                            "/avatar"),
148
                        "DELETE")
149
                    .headers(headersMap)
1✔
150
                    .responseFormat(ResponseFormat.NO_CONTENT)
1✔
151
                    .auth(this.auth)
1✔
152
                    .networkSession(this.networkSession)
1✔
153
                    .build());
1✔
154
  }
1✔
155

156
  public Authentication getAuth() {
157
    return auth;
×
158
  }
159

160
  public NetworkSession getNetworkSession() {
161
    return networkSession;
×
162
  }
163

164
  public static class Builder {
165

166
    protected Authentication auth;
167

168
    protected NetworkSession networkSession;
169

170
    public Builder() {
1✔
171
      this.networkSession = new NetworkSession();
1✔
172
    }
1✔
173

174
    public Builder auth(Authentication auth) {
175
      this.auth = auth;
1✔
176
      return this;
1✔
177
    }
178

179
    public Builder networkSession(NetworkSession networkSession) {
180
      this.networkSession = networkSession;
1✔
181
      return this;
1✔
182
    }
183

184
    public AvatarsManager build() {
185
      return new AvatarsManager(this);
1✔
186
    }
187
  }
188
}
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