• 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

82.89
/src/main/java/com/box/sdkgen/managers/trashedfiles/TrashedFilesManager.java
1
package com.box.sdkgen.managers.trashedfiles;
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.trashfile.TrashFile;
15
import com.box.sdkgen.schemas.trashfilerestored.TrashFileRestored;
16
import com.box.sdkgen.serialization.json.JsonManager;
17
import java.util.Map;
18

19
public class TrashedFilesManager {
20

21
  public Authentication auth;
22

23
  public NetworkSession networkSession;
24

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

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

34
  /**
35
   * Restores a file that has been moved to the trash.
36
   *
37
   * <p>An optional new parent ID can be provided to restore the file to in case the original folder
38
   * has been deleted.
39
   *
40
   * @param fileId The unique identifier that represents a file.
41
   *     <p>The ID for any file can be determined by visiting a file in the web application and
42
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
43
   *     `file_id` is `123`. Example: "12345"
44
   */
45
  public TrashFileRestored restoreFileFromTrash(String fileId) {
46
    return restoreFileFromTrash(
1✔
47
        fileId,
48
        new RestoreFileFromTrashRequestBody(),
49
        new RestoreFileFromTrashQueryParams(),
50
        new RestoreFileFromTrashHeaders());
51
  }
52

53
  /**
54
   * Restores a file that has been moved to the trash.
55
   *
56
   * <p>An optional new parent ID can be provided to restore the file to in case the original folder
57
   * has been deleted.
58
   *
59
   * @param fileId The unique identifier that represents a file.
60
   *     <p>The ID for any file can be determined by visiting a file in the web application and
61
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
62
   *     `file_id` is `123`. Example: "12345"
63
   * @param requestBody Request body of restoreFileFromTrash method
64
   */
65
  public TrashFileRestored restoreFileFromTrash(
66
      String fileId, RestoreFileFromTrashRequestBody requestBody) {
67
    return restoreFileFromTrash(
×
68
        fileId,
69
        requestBody,
70
        new RestoreFileFromTrashQueryParams(),
71
        new RestoreFileFromTrashHeaders());
72
  }
73

74
  /**
75
   * Restores a file that has been moved to the trash.
76
   *
77
   * <p>An optional new parent ID can be provided to restore the file to in case the original folder
78
   * has been deleted.
79
   *
80
   * @param fileId The unique identifier that represents a file.
81
   *     <p>The ID for any file can be determined by visiting a file in the web application and
82
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
83
   *     `file_id` is `123`. Example: "12345"
84
   * @param queryParams Query parameters of restoreFileFromTrash method
85
   */
86
  public TrashFileRestored restoreFileFromTrash(
87
      String fileId, RestoreFileFromTrashQueryParams queryParams) {
88
    return restoreFileFromTrash(
×
89
        fileId,
90
        new RestoreFileFromTrashRequestBody(),
91
        queryParams,
92
        new RestoreFileFromTrashHeaders());
93
  }
94

95
  /**
96
   * Restores a file that has been moved to the trash.
97
   *
98
   * <p>An optional new parent ID can be provided to restore the file to in case the original folder
99
   * has been deleted.
100
   *
101
   * @param fileId The unique identifier that represents a file.
102
   *     <p>The ID for any file can be determined by visiting a file in the web application and
103
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
104
   *     `file_id` is `123`. Example: "12345"
105
   * @param requestBody Request body of restoreFileFromTrash method
106
   * @param queryParams Query parameters of restoreFileFromTrash method
107
   */
108
  public TrashFileRestored restoreFileFromTrash(
109
      String fileId,
110
      RestoreFileFromTrashRequestBody requestBody,
111
      RestoreFileFromTrashQueryParams queryParams) {
112
    return restoreFileFromTrash(
×
113
        fileId, requestBody, queryParams, new RestoreFileFromTrashHeaders());
114
  }
115

116
  /**
117
   * Restores a file that has been moved to the trash.
118
   *
119
   * <p>An optional new parent ID can be provided to restore the file to in case the original folder
120
   * has been deleted.
121
   *
122
   * @param fileId The unique identifier that represents a file.
123
   *     <p>The ID for any file can be determined by visiting a file in the web application and
124
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
125
   *     `file_id` is `123`. Example: "12345"
126
   * @param headers Headers of restoreFileFromTrash method
127
   */
128
  public TrashFileRestored restoreFileFromTrash(
129
      String fileId, RestoreFileFromTrashHeaders headers) {
130
    return restoreFileFromTrash(
×
131
        fileId,
132
        new RestoreFileFromTrashRequestBody(),
133
        new RestoreFileFromTrashQueryParams(),
134
        headers);
135
  }
136

137
  /**
138
   * Restores a file that has been moved to the trash.
139
   *
140
   * <p>An optional new parent ID can be provided to restore the file to in case the original folder
141
   * has been deleted.
142
   *
143
   * @param fileId The unique identifier that represents a file.
144
   *     <p>The ID for any file can be determined by visiting a file in the web application and
145
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
146
   *     `file_id` is `123`. Example: "12345"
147
   * @param requestBody Request body of restoreFileFromTrash method
148
   * @param headers Headers of restoreFileFromTrash method
149
   */
150
  public TrashFileRestored restoreFileFromTrash(
151
      String fileId,
152
      RestoreFileFromTrashRequestBody requestBody,
153
      RestoreFileFromTrashHeaders headers) {
154
    return restoreFileFromTrash(
×
155
        fileId, requestBody, new RestoreFileFromTrashQueryParams(), headers);
156
  }
157

158
  /**
159
   * Restores a file that has been moved to the trash.
160
   *
161
   * <p>An optional new parent ID can be provided to restore the file to in case the original folder
162
   * has been deleted.
163
   *
164
   * @param fileId The unique identifier that represents a file.
165
   *     <p>The ID for any file can be determined by visiting a file in the web application and
166
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
167
   *     `file_id` is `123`. Example: "12345"
168
   * @param queryParams Query parameters of restoreFileFromTrash method
169
   * @param headers Headers of restoreFileFromTrash method
170
   */
171
  public TrashFileRestored restoreFileFromTrash(
172
      String fileId,
173
      RestoreFileFromTrashQueryParams queryParams,
174
      RestoreFileFromTrashHeaders headers) {
175
    return restoreFileFromTrash(
×
176
        fileId, new RestoreFileFromTrashRequestBody(), queryParams, headers);
177
  }
178

179
  /**
180
   * Restores a file that has been moved to the trash.
181
   *
182
   * <p>An optional new parent ID can be provided to restore the file to in case the original folder
183
   * has been deleted.
184
   *
185
   * @param fileId The unique identifier that represents a file.
186
   *     <p>The ID for any file can be determined by visiting a file in the web application and
187
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
188
   *     `file_id` is `123`. Example: "12345"
189
   * @param requestBody Request body of restoreFileFromTrash method
190
   * @param queryParams Query parameters of restoreFileFromTrash method
191
   * @param headers Headers of restoreFileFromTrash method
192
   */
193
  public TrashFileRestored restoreFileFromTrash(
194
      String fileId,
195
      RestoreFileFromTrashRequestBody requestBody,
196
      RestoreFileFromTrashQueryParams queryParams,
197
      RestoreFileFromTrashHeaders headers) {
198
    Map<String, String> queryParamsMap =
1✔
199
        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
1✔
200
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
201
    FetchResponse response =
1✔
202
        this.networkSession
203
            .getNetworkClient()
1✔
204
            .fetch(
1✔
205
                new FetchOptions.Builder(
206
                        String.join(
1✔
207
                            "",
208
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
209
                            "/2.0/files/",
210
                            convertToString(fileId)),
1✔
211
                        "POST")
212
                    .params(queryParamsMap)
1✔
213
                    .headers(headersMap)
1✔
214
                    .data(JsonManager.serialize(requestBody))
1✔
215
                    .contentType("application/json")
1✔
216
                    .responseFormat(ResponseFormat.JSON)
1✔
217
                    .auth(this.auth)
1✔
218
                    .networkSession(this.networkSession)
1✔
219
                    .build());
1✔
220
    return JsonManager.deserialize(response.getData(), TrashFileRestored.class);
1✔
221
  }
222

223
  /**
224
   * Retrieves a file that has been moved to the trash.
225
   *
226
   * <p>Please note that only if the file itself has been moved to the trash can it be retrieved
227
   * with this API call. If instead one of its parent folders was moved to the trash, only that
228
   * folder can be inspected using the [`GET /folders/:id/trash`](e://get_folders_id_trash) API.
229
   *
230
   * <p>To list all items that have been moved to the trash, please use the [`GET
231
   * /folders/trash/items`](e://get-folders-trash-items/) API.
232
   *
233
   * @param fileId The unique identifier that represents a file.
234
   *     <p>The ID for any file can be determined by visiting a file in the web application and
235
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
236
   *     `file_id` is `123`. Example: "12345"
237
   */
238
  public TrashFile getTrashedFileById(String fileId) {
239
    return getTrashedFileById(
1✔
240
        fileId, new GetTrashedFileByIdQueryParams(), new GetTrashedFileByIdHeaders());
241
  }
242

243
  /**
244
   * Retrieves a file that has been moved to the trash.
245
   *
246
   * <p>Please note that only if the file itself has been moved to the trash can it be retrieved
247
   * with this API call. If instead one of its parent folders was moved to the trash, only that
248
   * folder can be inspected using the [`GET /folders/:id/trash`](e://get_folders_id_trash) API.
249
   *
250
   * <p>To list all items that have been moved to the trash, please use the [`GET
251
   * /folders/trash/items`](e://get-folders-trash-items/) API.
252
   *
253
   * @param fileId The unique identifier that represents a file.
254
   *     <p>The ID for any file can be determined by visiting a file in the web application and
255
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
256
   *     `file_id` is `123`. Example: "12345"
257
   * @param queryParams Query parameters of getTrashedFileById method
258
   */
259
  public TrashFile getTrashedFileById(String fileId, GetTrashedFileByIdQueryParams queryParams) {
260
    return getTrashedFileById(fileId, queryParams, new GetTrashedFileByIdHeaders());
×
261
  }
262

263
  /**
264
   * Retrieves a file that has been moved to the trash.
265
   *
266
   * <p>Please note that only if the file itself has been moved to the trash can it be retrieved
267
   * with this API call. If instead one of its parent folders was moved to the trash, only that
268
   * folder can be inspected using the [`GET /folders/:id/trash`](e://get_folders_id_trash) API.
269
   *
270
   * <p>To list all items that have been moved to the trash, please use the [`GET
271
   * /folders/trash/items`](e://get-folders-trash-items/) API.
272
   *
273
   * @param fileId The unique identifier that represents a file.
274
   *     <p>The ID for any file can be determined by visiting a file in the web application and
275
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
276
   *     `file_id` is `123`. Example: "12345"
277
   * @param headers Headers of getTrashedFileById method
278
   */
279
  public TrashFile getTrashedFileById(String fileId, GetTrashedFileByIdHeaders headers) {
280
    return getTrashedFileById(fileId, new GetTrashedFileByIdQueryParams(), headers);
×
281
  }
282

283
  /**
284
   * Retrieves a file that has been moved to the trash.
285
   *
286
   * <p>Please note that only if the file itself has been moved to the trash can it be retrieved
287
   * with this API call. If instead one of its parent folders was moved to the trash, only that
288
   * folder can be inspected using the [`GET /folders/:id/trash`](e://get_folders_id_trash) API.
289
   *
290
   * <p>To list all items that have been moved to the trash, please use the [`GET
291
   * /folders/trash/items`](e://get-folders-trash-items/) API.
292
   *
293
   * @param fileId The unique identifier that represents a file.
294
   *     <p>The ID for any file can be determined by visiting a file in the web application and
295
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
296
   *     `file_id` is `123`. Example: "12345"
297
   * @param queryParams Query parameters of getTrashedFileById method
298
   * @param headers Headers of getTrashedFileById method
299
   */
300
  public TrashFile getTrashedFileById(
301
      String fileId, GetTrashedFileByIdQueryParams queryParams, GetTrashedFileByIdHeaders headers) {
302
    Map<String, String> queryParamsMap =
1✔
303
        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
1✔
304
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
305
    FetchResponse response =
1✔
306
        this.networkSession
307
            .getNetworkClient()
1✔
308
            .fetch(
1✔
309
                new FetchOptions.Builder(
310
                        String.join(
1✔
311
                            "",
312
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
313
                            "/2.0/files/",
314
                            convertToString(fileId),
1✔
315
                            "/trash"),
316
                        "GET")
317
                    .params(queryParamsMap)
1✔
318
                    .headers(headersMap)
1✔
319
                    .responseFormat(ResponseFormat.JSON)
1✔
320
                    .auth(this.auth)
1✔
321
                    .networkSession(this.networkSession)
1✔
322
                    .build());
1✔
323
    return JsonManager.deserialize(response.getData(), TrashFile.class);
1✔
324
  }
325

326
  /**
327
   * Permanently deletes a file that is in the trash. This action cannot be undone.
328
   *
329
   * @param fileId The unique identifier that represents a file.
330
   *     <p>The ID for any file can be determined by visiting a file in the web application and
331
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
332
   *     `file_id` is `123`. Example: "12345"
333
   */
334
  public void deleteTrashedFileById(String fileId) {
335
    deleteTrashedFileById(fileId, new DeleteTrashedFileByIdHeaders());
1✔
336
  }
1✔
337

338
  /**
339
   * Permanently deletes a file that is in the trash. This action cannot be undone.
340
   *
341
   * @param fileId The unique identifier that represents a file.
342
   *     <p>The ID for any file can be determined by visiting a file in the web application and
343
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
344
   *     `file_id` is `123`. Example: "12345"
345
   * @param headers Headers of deleteTrashedFileById method
346
   */
347
  public void deleteTrashedFileById(String fileId, DeleteTrashedFileByIdHeaders headers) {
348
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
349
    FetchResponse response =
1✔
350
        this.networkSession
351
            .getNetworkClient()
1✔
352
            .fetch(
1✔
353
                new FetchOptions.Builder(
354
                        String.join(
1✔
355
                            "",
356
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
357
                            "/2.0/files/",
358
                            convertToString(fileId),
1✔
359
                            "/trash"),
360
                        "DELETE")
361
                    .headers(headersMap)
1✔
362
                    .responseFormat(ResponseFormat.NO_CONTENT)
1✔
363
                    .auth(this.auth)
1✔
364
                    .networkSession(this.networkSession)
1✔
365
                    .build());
1✔
366
  }
1✔
367

368
  public Authentication getAuth() {
369
    return auth;
×
370
  }
371

372
  public NetworkSession getNetworkSession() {
373
    return networkSession;
×
374
  }
375

376
  public static class Builder {
377

378
    protected Authentication auth;
379

380
    protected NetworkSession networkSession;
381

382
    public Builder() {
1✔
383
      this.networkSession = new NetworkSession();
1✔
384
    }
1✔
385

386
    public Builder auth(Authentication auth) {
387
      this.auth = auth;
1✔
388
      return this;
1✔
389
    }
390

391
    public Builder networkSession(NetworkSession networkSession) {
392
      this.networkSession = networkSession;
1✔
393
      return this;
1✔
394
    }
395

396
    public TrashedFilesManager build() {
397
      return new TrashedFilesManager(this);
1✔
398
    }
399
  }
400
}
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