• 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

85.71
/src/main/java/com/box/sdkgen/managers/comments/CommentsManager.java
1
package com.box.sdkgen.managers.comments;
2

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

9
import com.box.sdkgen.networking.auth.Authentication;
10
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
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.commentfull.CommentFull;
15
import com.box.sdkgen.schemas.comments.Comments;
16
import com.box.sdkgen.serialization.json.JsonManager;
17
import java.util.Map;
18

19
public class CommentsManager {
20

21
  public Authentication auth;
22

23
  public NetworkSession networkSession;
24

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

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

34
  /**
35
   * Retrieves a list of comments for a file.
36
   *
37
   * @param fileId The unique identifier that represents a file.
38
   *     <p>The ID for any file can be determined by visiting a file in the web application and
39
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
40
   *     `file_id` is `123`. Example: "12345"
41
   */
42
  public Comments getFileComments(String fileId) {
43
    return getFileComments(fileId, new GetFileCommentsQueryParams(), new GetFileCommentsHeaders());
1✔
44
  }
45

46
  /**
47
   * Retrieves a list of comments for a file.
48
   *
49
   * @param fileId The unique identifier that represents a file.
50
   *     <p>The ID for any file can be determined by visiting a file in the web application and
51
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
52
   *     `file_id` is `123`. Example: "12345"
53
   * @param queryParams Query parameters of getFileComments method
54
   */
55
  public Comments getFileComments(String fileId, GetFileCommentsQueryParams queryParams) {
56
    return getFileComments(fileId, queryParams, new GetFileCommentsHeaders());
×
57
  }
58

59
  /**
60
   * Retrieves a list of comments for a file.
61
   *
62
   * @param fileId The unique identifier that represents a file.
63
   *     <p>The ID for any file can be determined by visiting a file in the web application and
64
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
65
   *     `file_id` is `123`. Example: "12345"
66
   * @param headers Headers of getFileComments method
67
   */
68
  public Comments getFileComments(String fileId, GetFileCommentsHeaders headers) {
69
    return getFileComments(fileId, new GetFileCommentsQueryParams(), headers);
×
70
  }
71

72
  /**
73
   * Retrieves a list of comments for a file.
74
   *
75
   * @param fileId The unique identifier that represents a file.
76
   *     <p>The ID for any file can be determined by visiting a file in the web application and
77
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
78
   *     `file_id` is `123`. Example: "12345"
79
   * @param queryParams Query parameters of getFileComments method
80
   * @param headers Headers of getFileComments method
81
   */
82
  public Comments getFileComments(
83
      String fileId, GetFileCommentsQueryParams queryParams, GetFileCommentsHeaders headers) {
84
    Map<String, String> queryParamsMap =
1✔
85
        prepareParams(
1✔
86
            mapOf(
1✔
87
                entryOf("fields", convertToString(queryParams.getFields())),
1✔
88
                entryOf("limit", convertToString(queryParams.getLimit())),
1✔
89
                entryOf("offset", convertToString(queryParams.getOffset()))));
1✔
90
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
91
    FetchResponse response =
1✔
92
        this.networkSession
93
            .getNetworkClient()
1✔
94
            .fetch(
1✔
95
                new FetchOptions.Builder(
96
                        String.join(
1✔
97
                            "",
98
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
99
                            "/2.0/files/",
100
                            convertToString(fileId),
1✔
101
                            "/comments"),
102
                        "GET")
103
                    .params(queryParamsMap)
1✔
104
                    .headers(headersMap)
1✔
105
                    .responseFormat(ResponseFormat.JSON)
1✔
106
                    .auth(this.auth)
1✔
107
                    .networkSession(this.networkSession)
1✔
108
                    .build());
1✔
109
    return JsonManager.deserialize(response.getData(), Comments.class);
1✔
110
  }
111

112
  /**
113
   * Retrieves the message and metadata for a specific comment, as well as information on the user
114
   * who created the comment.
115
   *
116
   * @param commentId The ID of the comment. Example: "12345"
117
   */
118
  public CommentFull getCommentById(String commentId) {
119
    return getCommentById(commentId, new GetCommentByIdQueryParams(), new GetCommentByIdHeaders());
1✔
120
  }
121

122
  /**
123
   * Retrieves the message and metadata for a specific comment, as well as information on the user
124
   * who created the comment.
125
   *
126
   * @param commentId The ID of the comment. Example: "12345"
127
   * @param queryParams Query parameters of getCommentById method
128
   */
129
  public CommentFull getCommentById(String commentId, GetCommentByIdQueryParams queryParams) {
130
    return getCommentById(commentId, queryParams, new GetCommentByIdHeaders());
×
131
  }
132

133
  /**
134
   * Retrieves the message and metadata for a specific comment, as well as information on the user
135
   * who created the comment.
136
   *
137
   * @param commentId The ID of the comment. Example: "12345"
138
   * @param headers Headers of getCommentById method
139
   */
140
  public CommentFull getCommentById(String commentId, GetCommentByIdHeaders headers) {
141
    return getCommentById(commentId, new GetCommentByIdQueryParams(), headers);
×
142
  }
143

144
  /**
145
   * Retrieves the message and metadata for a specific comment, as well as information on the user
146
   * who created the comment.
147
   *
148
   * @param commentId The ID of the comment. Example: "12345"
149
   * @param queryParams Query parameters of getCommentById method
150
   * @param headers Headers of getCommentById method
151
   */
152
  public CommentFull getCommentById(
153
      String commentId, GetCommentByIdQueryParams queryParams, GetCommentByIdHeaders headers) {
154
    Map<String, String> queryParamsMap =
1✔
155
        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
1✔
156
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
157
    FetchResponse response =
1✔
158
        this.networkSession
159
            .getNetworkClient()
1✔
160
            .fetch(
1✔
161
                new FetchOptions.Builder(
162
                        String.join(
1✔
163
                            "",
164
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
165
                            "/2.0/comments/",
166
                            convertToString(commentId)),
1✔
167
                        "GET")
168
                    .params(queryParamsMap)
1✔
169
                    .headers(headersMap)
1✔
170
                    .responseFormat(ResponseFormat.JSON)
1✔
171
                    .auth(this.auth)
1✔
172
                    .networkSession(this.networkSession)
1✔
173
                    .build());
1✔
174
    return JsonManager.deserialize(response.getData(), CommentFull.class);
1✔
175
  }
176

177
  /**
178
   * Update the message of a comment.
179
   *
180
   * @param commentId The ID of the comment. Example: "12345"
181
   */
182
  public CommentFull updateCommentById(String commentId) {
183
    return updateCommentById(
×
184
        commentId,
185
        new UpdateCommentByIdRequestBody(),
186
        new UpdateCommentByIdQueryParams(),
187
        new UpdateCommentByIdHeaders());
188
  }
189

190
  /**
191
   * Update the message of a comment.
192
   *
193
   * @param commentId The ID of the comment. Example: "12345"
194
   * @param requestBody Request body of updateCommentById method
195
   */
196
  public CommentFull updateCommentById(String commentId, UpdateCommentByIdRequestBody requestBody) {
197
    return updateCommentById(
1✔
198
        commentId, requestBody, new UpdateCommentByIdQueryParams(), new UpdateCommentByIdHeaders());
199
  }
200

201
  /**
202
   * Update the message of a comment.
203
   *
204
   * @param commentId The ID of the comment. Example: "12345"
205
   * @param queryParams Query parameters of updateCommentById method
206
   */
207
  public CommentFull updateCommentById(String commentId, UpdateCommentByIdQueryParams queryParams) {
208
    return updateCommentById(
×
209
        commentId, new UpdateCommentByIdRequestBody(), queryParams, new UpdateCommentByIdHeaders());
210
  }
211

212
  /**
213
   * Update the message of a comment.
214
   *
215
   * @param commentId The ID of the comment. Example: "12345"
216
   * @param requestBody Request body of updateCommentById method
217
   * @param queryParams Query parameters of updateCommentById method
218
   */
219
  public CommentFull updateCommentById(
220
      String commentId,
221
      UpdateCommentByIdRequestBody requestBody,
222
      UpdateCommentByIdQueryParams queryParams) {
223
    return updateCommentById(commentId, requestBody, queryParams, new UpdateCommentByIdHeaders());
×
224
  }
225

226
  /**
227
   * Update the message of a comment.
228
   *
229
   * @param commentId The ID of the comment. Example: "12345"
230
   * @param headers Headers of updateCommentById method
231
   */
232
  public CommentFull updateCommentById(String commentId, UpdateCommentByIdHeaders headers) {
233
    return updateCommentById(
×
234
        commentId, new UpdateCommentByIdRequestBody(), new UpdateCommentByIdQueryParams(), headers);
235
  }
236

237
  /**
238
   * Update the message of a comment.
239
   *
240
   * @param commentId The ID of the comment. Example: "12345"
241
   * @param requestBody Request body of updateCommentById method
242
   * @param headers Headers of updateCommentById method
243
   */
244
  public CommentFull updateCommentById(
245
      String commentId,
246
      UpdateCommentByIdRequestBody requestBody,
247
      UpdateCommentByIdHeaders headers) {
248
    return updateCommentById(commentId, requestBody, new UpdateCommentByIdQueryParams(), headers);
×
249
  }
250

251
  /**
252
   * Update the message of a comment.
253
   *
254
   * @param commentId The ID of the comment. Example: "12345"
255
   * @param queryParams Query parameters of updateCommentById method
256
   * @param headers Headers of updateCommentById method
257
   */
258
  public CommentFull updateCommentById(
259
      String commentId,
260
      UpdateCommentByIdQueryParams queryParams,
261
      UpdateCommentByIdHeaders headers) {
262
    return updateCommentById(commentId, new UpdateCommentByIdRequestBody(), queryParams, headers);
×
263
  }
264

265
  /**
266
   * Update the message of a comment.
267
   *
268
   * @param commentId The ID of the comment. Example: "12345"
269
   * @param requestBody Request body of updateCommentById method
270
   * @param queryParams Query parameters of updateCommentById method
271
   * @param headers Headers of updateCommentById method
272
   */
273
  public CommentFull updateCommentById(
274
      String commentId,
275
      UpdateCommentByIdRequestBody requestBody,
276
      UpdateCommentByIdQueryParams queryParams,
277
      UpdateCommentByIdHeaders headers) {
278
    Map<String, String> queryParamsMap =
1✔
279
        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
1✔
280
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
281
    FetchResponse response =
1✔
282
        this.networkSession
283
            .getNetworkClient()
1✔
284
            .fetch(
1✔
285
                new FetchOptions.Builder(
286
                        String.join(
1✔
287
                            "",
288
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
289
                            "/2.0/comments/",
290
                            convertToString(commentId)),
1✔
291
                        "PUT")
292
                    .params(queryParamsMap)
1✔
293
                    .headers(headersMap)
1✔
294
                    .data(JsonManager.serialize(requestBody))
1✔
295
                    .contentType("application/json")
1✔
296
                    .responseFormat(ResponseFormat.JSON)
1✔
297
                    .auth(this.auth)
1✔
298
                    .networkSession(this.networkSession)
1✔
299
                    .build());
1✔
300
    return JsonManager.deserialize(response.getData(), CommentFull.class);
1✔
301
  }
302

303
  /**
304
   * Permanently deletes a comment.
305
   *
306
   * @param commentId The ID of the comment. Example: "12345"
307
   */
308
  public void deleteCommentById(String commentId) {
309
    deleteCommentById(commentId, new DeleteCommentByIdHeaders());
1✔
310
  }
1✔
311

312
  /**
313
   * Permanently deletes a comment.
314
   *
315
   * @param commentId The ID of the comment. Example: "12345"
316
   * @param headers Headers of deleteCommentById method
317
   */
318
  public void deleteCommentById(String commentId, DeleteCommentByIdHeaders headers) {
319
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
320
    FetchResponse response =
1✔
321
        this.networkSession
322
            .getNetworkClient()
1✔
323
            .fetch(
1✔
324
                new FetchOptions.Builder(
325
                        String.join(
1✔
326
                            "",
327
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
328
                            "/2.0/comments/",
329
                            convertToString(commentId)),
1✔
330
                        "DELETE")
331
                    .headers(headersMap)
1✔
332
                    .responseFormat(ResponseFormat.NO_CONTENT)
1✔
333
                    .auth(this.auth)
1✔
334
                    .networkSession(this.networkSession)
1✔
335
                    .build());
1✔
336
  }
1✔
337

338
  /**
339
   * Adds a comment by the user to a specific file, or as a reply to an other comment.
340
   *
341
   * @param requestBody Request body of createComment method
342
   */
343
  public CommentFull createComment(CreateCommentRequestBody requestBody) {
344
    return createComment(requestBody, new CreateCommentQueryParams(), new CreateCommentHeaders());
1✔
345
  }
346

347
  /**
348
   * Adds a comment by the user to a specific file, or as a reply to an other comment.
349
   *
350
   * @param requestBody Request body of createComment method
351
   * @param queryParams Query parameters of createComment method
352
   */
353
  public CommentFull createComment(
354
      CreateCommentRequestBody requestBody, CreateCommentQueryParams queryParams) {
355
    return createComment(requestBody, queryParams, new CreateCommentHeaders());
×
356
  }
357

358
  /**
359
   * Adds a comment by the user to a specific file, or as a reply to an other comment.
360
   *
361
   * @param requestBody Request body of createComment method
362
   * @param headers Headers of createComment method
363
   */
364
  public CommentFull createComment(
365
      CreateCommentRequestBody requestBody, CreateCommentHeaders headers) {
366
    return createComment(requestBody, new CreateCommentQueryParams(), headers);
×
367
  }
368

369
  /**
370
   * Adds a comment by the user to a specific file, or as a reply to an other comment.
371
   *
372
   * @param requestBody Request body of createComment method
373
   * @param queryParams Query parameters of createComment method
374
   * @param headers Headers of createComment method
375
   */
376
  public CommentFull createComment(
377
      CreateCommentRequestBody requestBody,
378
      CreateCommentQueryParams queryParams,
379
      CreateCommentHeaders headers) {
380
    Map<String, String> queryParamsMap =
1✔
381
        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
1✔
382
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
383
    FetchResponse response =
1✔
384
        this.networkSession
385
            .getNetworkClient()
1✔
386
            .fetch(
1✔
387
                new FetchOptions.Builder(
388
                        String.join(
1✔
389
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/comments"),
1✔
390
                        "POST")
391
                    .params(queryParamsMap)
1✔
392
                    .headers(headersMap)
1✔
393
                    .data(JsonManager.serialize(requestBody))
1✔
394
                    .contentType("application/json")
1✔
395
                    .responseFormat(ResponseFormat.JSON)
1✔
396
                    .auth(this.auth)
1✔
397
                    .networkSession(this.networkSession)
1✔
398
                    .build());
1✔
399
    return JsonManager.deserialize(response.getData(), CommentFull.class);
1✔
400
  }
401

402
  public Authentication getAuth() {
403
    return auth;
×
404
  }
405

406
  public NetworkSession getNetworkSession() {
407
    return networkSession;
×
408
  }
409

410
  public static class Builder {
411

412
    protected Authentication auth;
413

414
    protected NetworkSession networkSession;
415

416
    public Builder() {
1✔
417
      this.networkSession = new NetworkSession();
1✔
418
    }
1✔
419

420
    public Builder auth(Authentication auth) {
421
      this.auth = auth;
1✔
422
      return this;
1✔
423
    }
424

425
    public Builder networkSession(NetworkSession networkSession) {
426
      this.networkSession = networkSession;
1✔
427
      return this;
1✔
428
    }
429

430
    public CommentsManager build() {
431
      return new CommentsManager(this);
1✔
432
    }
433
  }
434
}
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