1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.documentsui.archives;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import static org.junit.Assert.fail;
22 import static org.mockito.Mockito.mock;
23 import static org.mockito.Mockito.when;
24 
25 import android.os.ParcelFileDescriptor;
26 
27 import androidx.annotation.NonNull;
28 import androidx.annotation.Nullable;
29 import androidx.test.runner.AndroidJUnit4;
30 
31 import org.apache.commons.compress.archivers.ArchiveEntry;
32 import org.apache.commons.compress.archivers.ArchiveException;
33 import org.apache.commons.compress.compressors.CompressorException;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 
38 import java.io.FileInputStream;
39 import java.io.IOException;
40 import java.io.InputStream;
41 import java.util.ArrayList;
42 import java.util.Date;
43 import java.util.Enumeration;
44 import java.util.List;
45 import java.util.Locale;
46 
47 @RunWith(AndroidJUnit4.class)
48 public class ArchiveHandleTest {
49     @Rule
50     public ArchiveFileTestRule mArchiveFileTestRule = new ArchiveFileTestRule();
51 
52 
prepareArchiveHandle(String archivePath, String suffix, String mimeType)53     private ArchiveHandle prepareArchiveHandle(String archivePath, String suffix,
54             String mimeType) throws IOException, CompressorException, ArchiveException {
55         ParcelFileDescriptor parcelFileDescriptor = mArchiveFileTestRule
56                 .openAssetFile(archivePath, suffix);
57 
58         return ArchiveHandle.create(parcelFileDescriptor, mimeType);
59     }
60 
getFileInArchive(Enumeration<ArchiveEntry> enumeration, String pathInArchive)61     private static ArchiveEntry getFileInArchive(Enumeration<ArchiveEntry> enumeration,
62             String pathInArchive) {
63         while (enumeration.hasMoreElements()) {
64             ArchiveEntry entry = enumeration.nextElement();
65             if (entry.getName().equals(pathInArchive)) {
66                 return entry;
67             }
68         }
69         return null;
70     }
71 
72 
73     private static class ArchiveEntryRecord implements ArchiveEntry {
74         private final String mName;
75         private final long mSize;
76         private final boolean mIsDirectory;
77 
ArchiveEntryRecord(ArchiveEntry archiveEntry)78         private ArchiveEntryRecord(ArchiveEntry archiveEntry) {
79             this(archiveEntry.getName(), archiveEntry.getSize(), archiveEntry.isDirectory());
80         }
81 
ArchiveEntryRecord(String name, long size, boolean isDirectory)82         private ArchiveEntryRecord(String name, long size, boolean isDirectory) {
83             mName = name;
84             mSize = size;
85             mIsDirectory = isDirectory;
86         }
87 
88         @Override
equals(@ullable Object obj)89         public boolean equals(@Nullable Object obj) {
90             if (obj == null) {
91                 return false;
92             }
93 
94             if (obj instanceof ArchiveEntryRecord) {
95                 ArchiveEntryRecord recordB = (ArchiveEntryRecord) obj;
96                 return mName.equals(recordB.mName)
97                         && mSize == recordB.mSize
98                         && mIsDirectory == recordB.mIsDirectory;
99             }
100 
101             return false;
102         }
103 
104         @Override
getName()105         public String getName() {
106             return mName;
107         }
108 
109         @Override
getSize()110         public long getSize() {
111             return mSize;
112         }
113 
114         @Override
isDirectory()115         public boolean isDirectory() {
116             return mIsDirectory;
117         }
118 
119         @Override
getLastModifiedDate()120         public Date getLastModifiedDate() {
121             return null;
122         }
123 
124         @NonNull
125         @Override
toString()126         public String toString() {
127             return String.format(Locale.ENGLISH, "name: %s, size: %d, isDirectory: %b",
128                     mName, mSize, mIsDirectory);
129         }
130     }
131 
transformToIterable(Enumeration<ArchiveEntry> enumeration)132     private static List<ArchiveEntry> transformToIterable(Enumeration<ArchiveEntry> enumeration) {
133         List list = new ArrayList<ArchiveEntry>();
134         while (enumeration.hasMoreElements()) {
135             list.add(new ArchiveEntryRecord(enumeration.nextElement()));
136         }
137         return list;
138     }
139 
140     private static final List<ArchiveEntryRecord> sExpectEntries =
141             new ArrayList<ArchiveEntryRecord>() {
142         {
143             add(new ArchiveEntryRecord("hello/hello.txt", 48, false));
144             add(new ArchiveEntryRecord("hello/inside_folder/hello_insside.txt",
145                             14, false));
146             add(new ArchiveEntryRecord("hello/hello2.txt", 48, false));
147         }
148     };
149 
150 
151     @Test
buildArchiveHandle_withoutFileDescriptor_shouldBeIllegal()152     public void buildArchiveHandle_withoutFileDescriptor_shouldBeIllegal() throws Exception {
153         try {
154             ArchiveHandle.create(null,
155                     "application/x-7z-compressed");
156             fail("It should not be here!");
157         } catch (NullPointerException e) {
158             /* do nothing */
159         }
160     }
161 
162     @Test
buildArchiveHandle_withWrongMimeType_shouldBeIllegal()163     public void buildArchiveHandle_withWrongMimeType_shouldBeIllegal() throws Exception {
164         ParcelFileDescriptor parcelFileDescriptor = mArchiveFileTestRule
165                 .openAssetFile("archives/7z/hello.7z", ".7z");
166 
167         try {
168             ArchiveHandle.create(parcelFileDescriptor, null);
169             fail("It should not be here!");
170         } catch (IllegalArgumentException e) {
171             /* do nothing */
172         }
173     }
174 
175     @Test
buildArchiveHandle_sevenZFile_shouldNotNull()176     public void buildArchiveHandle_sevenZFile_shouldNotNull() throws Exception {
177         ArchiveHandle archiveHandle = prepareArchiveHandle("archives/7z/hello.7z",
178                 ".7z", "application/x-7z-compressed");
179 
180         assertThat(archiveHandle).isNotNull();
181     }
182 
183     @Test
buildArchiveHandle_zipFile_shouldNotNull()184     public void buildArchiveHandle_zipFile_shouldNotNull() throws Exception {
185         ArchiveHandle archiveHandle = prepareArchiveHandle("archives/zip/hello.zip",
186                 ".zip", "application/zip");
187 
188         assertThat(archiveHandle).isNotNull();
189     }
190 
191     @Test
buildArchiveHandle_zipWithWrongMimeType_shouldBeNull()192     public void buildArchiveHandle_zipWithWrongMimeType_shouldBeNull() throws Exception {
193         try {
194             prepareArchiveHandle("archives/zip/hello.zip",
195                     ".zip", "application/xxxzip");
196             fail("It should not be here!");
197         } catch (UnsupportedOperationException e) {
198             /* do nothing */
199         }
200     }
201 
202     @Test
buildArchiveHandle_tarFile_shouldNotNull()203     public void buildArchiveHandle_tarFile_shouldNotNull() throws Exception {
204         ArchiveHandle archiveHandle = prepareArchiveHandle("archives/tar/hello.tar",
205                 ".tar", "application/x-gtar");
206 
207         assertThat(archiveHandle).isNotNull();
208     }
209 
210     @Test
buildArchiveHandle_tgzFile_shouldNotNull()211     public void buildArchiveHandle_tgzFile_shouldNotNull() throws Exception {
212         ArchiveHandle archiveHandle = prepareArchiveHandle("archives/tar_gz/hello.tgz",
213                 ".tgz", "application/x-compressed-tar");
214 
215         assertThat(archiveHandle).isNotNull();
216     }
217 
218     @Test
buildArchiveHandle_tarGzFile_shouldNotNull()219     public void buildArchiveHandle_tarGzFile_shouldNotNull() throws Exception {
220         ArchiveHandle archiveHandle =
221                 prepareArchiveHandle("archives/tar_gz/hello_tar_gz", ".tar.gz",
222                         "application/x-compressed-tar");
223 
224         assertThat(archiveHandle).isNotNull();
225     }
226 
227     @Test
buildArchiveHandle_tarBzipFile_shouldNotNull()228     public void buildArchiveHandle_tarBzipFile_shouldNotNull() throws Exception {
229         ArchiveHandle archiveHandle =
230                 prepareArchiveHandle("archives/tar_bz2/hello.tar.bz2",
231                         ".tar.bz2", "application/x-bzip-compressed-tar");
232 
233         assertThat(archiveHandle).isNotNull();
234     }
235 
236     @Test
buildArchiveHandle_tarXzFile_shouldNotNull()237     public void buildArchiveHandle_tarXzFile_shouldNotNull() throws Exception {
238         ArchiveHandle archiveHandle =
239                 prepareArchiveHandle("archives/xz/hello.tar.xz", ".tar.xz",
240                         "application/x-xz-compressed-tar");
241 
242         assertThat(archiveHandle).isNotNull();
243     }
244 
245     @Test
buildArchiveHandle_tarBrFile_shouldNotNull()246     public void buildArchiveHandle_tarBrFile_shouldNotNull() throws Exception {
247         ArchiveHandle archiveHandle =
248                 prepareArchiveHandle("archives/brotli/hello.tar.br", ".tar.br",
249                 "application/x-brotli-compressed-tar");
250 
251         assertThat(archiveHandle).isNotNull();
252     }
253 
254     @Test
getMimeType_sevenZFile_shouldBeSevenZ()255     public void getMimeType_sevenZFile_shouldBeSevenZ()
256             throws CompressorException, ArchiveException, IOException {
257         ArchiveHandle archiveHandle = prepareArchiveHandle("archives/7z/hello.7z",
258                 ".7z", "application/x-7z-compressed");
259 
260         assertThat(archiveHandle.getMimeType()).isEqualTo("application/x-7z-compressed");
261     }
262 
263     @Test
getMimeType_tarBrotli_shouldBeBrotliCompressedTar()264     public void getMimeType_tarBrotli_shouldBeBrotliCompressedTar()
265             throws CompressorException, ArchiveException, IOException {
266         ArchiveHandle archiveHandle =
267                 prepareArchiveHandle("archives/brotli/hello.tar.br", ".tar.br",
268                         "application/x-brotli-compressed-tar");
269 
270         assertThat(archiveHandle.getMimeType())
271                 .isEqualTo("application/x-brotli-compressed-tar");
272     }
273 
274     @Test
getMimeType_tarXz_shouldBeXzCompressedTar()275     public void getMimeType_tarXz_shouldBeXzCompressedTar()
276             throws CompressorException, ArchiveException, IOException {
277         ArchiveHandle archiveHandle =
278                 prepareArchiveHandle("archives/xz/hello.tar.xz", ".tar.xz",
279                         "application/x-xz-compressed-tar");
280 
281         assertThat(archiveHandle.getMimeType())
282                 .isEqualTo("application/x-xz-compressed-tar");
283     }
284 
285     @Test
getMimeType_tarGz_shouldBeCompressedTar()286     public void getMimeType_tarGz_shouldBeCompressedTar()
287             throws CompressorException, ArchiveException, IOException {
288         ArchiveHandle archiveHandle =
289                 prepareArchiveHandle("archives/tar_gz/hello_tar_gz", ".tar.gz",
290                         "application/x-compressed-tar");
291 
292         assertThat(archiveHandle.getMimeType())
293                 .isEqualTo("application/x-compressed-tar");
294     }
295 
296     @Test
getCommonArchive_tarBrFile_shouldBeCommonArchiveInputHandle()297     public void getCommonArchive_tarBrFile_shouldBeCommonArchiveInputHandle() throws Exception {
298         ArchiveHandle archiveHandle =
299                 prepareArchiveHandle("archives/brotli/hello.tar.br", ".tar.br",
300                         "application/x-brotli-compressed-tar");
301 
302         assertThat(archiveHandle.toString()).contains("CommonArchiveInputHandle");
303     }
304 
305     @Test
getCommonArchive_sevenZFile_shouldBeSevenZFileHandle()306     public void getCommonArchive_sevenZFile_shouldBeSevenZFileHandle() throws Exception {
307         ArchiveHandle archiveHandle = prepareArchiveHandle("archives/7z/hello.7z",
308                 ".7z", "application/x-7z-compressed");
309 
310         assertThat(archiveHandle.toString()).contains("SevenZFileHandle");
311     }
312 
313 
314     @Test
getCommonArchive_zipFile_shouldBeZipFileHandle()315     public void getCommonArchive_zipFile_shouldBeZipFileHandle() throws Exception {
316         ArchiveHandle archiveHandle = prepareArchiveHandle("archives/zip/hello.zip",
317                 ".zip", "application/zip");
318 
319         assertThat(archiveHandle.toString()).contains("ZipFileHandle");
320     }
321 
322     @Test
close_zipFile_shouldBeSuccess()323     public void close_zipFile_shouldBeSuccess() throws Exception {
324         ArchiveHandle archiveHandle = prepareArchiveHandle("archives/zip/hello.zip",
325                 ".zip", "application/zip");
326 
327         archiveHandle.close();
328     }
329 
330     @Test
close_sevenZFile_shouldBeSuccess()331     public void close_sevenZFile_shouldBeSuccess() throws Exception {
332         ArchiveHandle archiveHandle = prepareArchiveHandle("archives/7z/hello.7z",
333                 ".7z", "application/x-7z-compressed");
334 
335         archiveHandle.close();
336     }
337 
338     @Test
closeInputStream_zipFile_shouldBeSuccess()339     public void closeInputStream_zipFile_shouldBeSuccess() throws Exception {
340         ArchiveHandle archiveHandle = prepareArchiveHandle("archives/zip/hello.zip",
341                 ".zip", "application/zip");
342 
343         InputStream inputStream = archiveHandle.getInputStream(
344                 getFileInArchive(archiveHandle.getEntries(),
345                         "hello/inside_folder/hello_insside.txt"));
346 
347         assertThat(inputStream).isNotNull();
348 
349         inputStream.close();
350     }
351 
352     @Test
close_zipFile_shouldNotOpen()353     public void close_zipFile_shouldNotOpen() throws Exception {
354         ParcelFileDescriptor parcelFileDescriptor =  mArchiveFileTestRule
355                 .openAssetFile("archives/zip/hello.zip", ".zip");
356 
357         ArchiveHandle archiveHandle = ArchiveHandle.create(parcelFileDescriptor,
358                 "application/zip");
359 
360         archiveHandle.close();
361 
362         FileInputStream fileInputStream =
363                 new FileInputStream(parcelFileDescriptor.getFileDescriptor());
364         assertThat(fileInputStream).isNotNull();
365     }
366 
367     @Test
getInputStream_zipFile_shouldHaveTheSameContent()368     public void getInputStream_zipFile_shouldHaveTheSameContent() throws Exception {
369         ParcelFileDescriptor parcelFileDescriptor = mArchiveFileTestRule
370                 .openAssetFile("archives/zip/hello.zip", ".zip");
371 
372         String expectedContent = mArchiveFileTestRule.getAssetText(
373                 "archives/original/hello/inside_folder/hello_insside.txt");
374 
375         ArchiveHandle archiveHandle = ArchiveHandle.create(parcelFileDescriptor,
376                 "application/zip");
377 
378         InputStream inputStream = archiveHandle.getInputStream(
379                 getFileInArchive(archiveHandle.getEntries(),
380                         "hello/inside_folder/hello_insside.txt"));
381 
382         assertThat(ArchiveFileTestRule.getStringFromInputStream(inputStream))
383                 .isEqualTo(expectedContent);
384     }
385 
386     @Test
getInputStream_zipFileNotExistEntry_shouldFail()387     public void getInputStream_zipFileNotExistEntry_shouldFail() throws Exception {
388         ArchiveHandle archiveHandle = prepareArchiveHandle("archives/zip/hello.zip",
389                 ".zip", "application/zip");
390 
391         ArchiveEntry archiveEntry = mock(ArchiveEntry.class);
392         when(archiveEntry.getName()).thenReturn("/not_exist_entry");
393 
394         try {
395             archiveHandle.getInputStream(archiveEntry);
396             fail("It should not be here.");
397         } catch (IllegalArgumentException | ArchiveException | CompressorException e) {
398             /* do nothing */
399         }
400     }
401 
402     @Test
getInputStream_directoryEntry_shouldFail()403     public void getInputStream_directoryEntry_shouldFail() throws Exception {
404         ArchiveHandle archiveHandle = prepareArchiveHandle("archives/zip/hello.zip",
405                 ".zip", "application/zip");
406 
407         ArchiveEntry archiveEntry = mock(ArchiveEntry.class);
408         when(archiveEntry.isDirectory()).thenReturn(true);
409 
410         try {
411             archiveHandle.getInputStream(archiveEntry);
412             fail("It should not be here.");
413         } catch (IllegalArgumentException e) {
414             /* expected, do nothing */
415         }
416     }
417 
418     @Test
getInputStream_zeroSizeEntry_shouldFail()419     public void getInputStream_zeroSizeEntry_shouldFail() throws Exception {
420         ArchiveHandle archiveHandle = prepareArchiveHandle("archives/zip/hello.zip",
421                 ".zip", "application/zip");
422 
423         ArchiveEntry archiveEntry = mock(ArchiveEntry.class);
424         when(archiveEntry.isDirectory()).thenReturn(false);
425         when(archiveEntry.getSize()).thenReturn(0L);
426 
427         try {
428             archiveHandle.getInputStream(archiveEntry);
429             fail("It should not be here.");
430         } catch (IllegalArgumentException e) {
431             /* expected, do nothing */
432         }
433     }
434 
435     @Test
getInputStream_emptyStringEntry_shouldFail()436     public void getInputStream_emptyStringEntry_shouldFail() throws Exception {
437         ArchiveHandle archiveHandle = prepareArchiveHandle("archives/zip/hello.zip",
438                 ".zip", "application/zip");
439 
440         ArchiveEntry archiveEntry = mock(ArchiveEntry.class);
441         when(archiveEntry.isDirectory()).thenReturn(false);
442         when(archiveEntry.getSize()).thenReturn(14L);
443         when(archiveEntry.getName()).thenReturn("");
444 
445         try {
446             archiveHandle.getInputStream(archiveEntry);
447             fail("It should not be here.");
448         } catch (IllegalArgumentException e) {
449             /* expected, do nothing */
450         }
451     }
452 
453     @Test
getInputStream_sevenZFile_shouldHaveTheSameContent()454     public void getInputStream_sevenZFile_shouldHaveTheSameContent() throws Exception {
455         ParcelFileDescriptor parcelFileDescriptor = mArchiveFileTestRule
456                 .openAssetFile("archives/7z/hello.7z", ".7z");
457 
458         String expectedContent = mArchiveFileTestRule.getAssetText(
459                 "archives/original/hello/inside_folder/hello_insside.txt");
460 
461         ArchiveHandle archiveHandle = ArchiveHandle.create(parcelFileDescriptor,
462                 "application/x-7z-compressed");
463 
464         InputStream inputStream = archiveHandle.getInputStream(
465                 getFileInArchive(archiveHandle.getEntries(),
466                         "hello/inside_folder/hello_insside.txt"));
467 
468         assertThat(ArchiveFileTestRule.getStringFromInputStream(inputStream))
469                 .isEqualTo(expectedContent);
470     }
471 
472     @Test
getInputStream_tarGzFile_shouldHaveTheSameContent()473     public void getInputStream_tarGzFile_shouldHaveTheSameContent() throws Exception {
474         ParcelFileDescriptor parcelFileDescriptor = mArchiveFileTestRule
475                 .openAssetFile("archives/tar_gz/hello.tgz", ".tar.gz");
476 
477         String expectedContent = mArchiveFileTestRule.getAssetText(
478                 "archives/original/hello/inside_folder/hello_insside.txt");
479 
480         ArchiveHandle archiveHandle = ArchiveHandle.create(parcelFileDescriptor,
481                 "application/x-compressed-tar");
482 
483         InputStream inputStream = archiveHandle.getInputStream(
484                 getFileInArchive(archiveHandle.getEntries(),
485                         "hello/inside_folder/hello_insside.txt"));
486 
487         assertThat(ArchiveFileTestRule.getStringFromInputStream(inputStream))
488                 .isEqualTo(expectedContent);
489     }
490 
491     @Test
getInputStream_tarGzFileNullEntry_getNullInputStream()492     public void getInputStream_tarGzFileNullEntry_getNullInputStream() throws Exception {
493         ParcelFileDescriptor parcelFileDescriptor = mArchiveFileTestRule
494                 .openAssetFile("archives/tar_gz/hello.tgz", ".tar.gz");
495 
496         String expectedContent = mArchiveFileTestRule.getAssetText(
497                 "archives/original/hello/inside_folder/hello_insside.txt");
498 
499         ArchiveHandle archiveHandle = ArchiveHandle.create(parcelFileDescriptor,
500                 "application/x-compressed-tar");
501 
502         try {
503             archiveHandle.getInputStream(null);
504             fail("It should not here");
505         } catch (IllegalArgumentException | ArchiveException | CompressorException e) {
506             /* expected, do nothing */
507         }
508     }
509 
510 
511     @Test
getInputStream_tarGzFileInvalidEntry_getNullInputStream()512     public void getInputStream_tarGzFileInvalidEntry_getNullInputStream() throws Exception {
513         ParcelFileDescriptor parcelFileDescriptor = mArchiveFileTestRule
514                 .openAssetFile("archives/tar_gz/hello.tgz", ".tar.gz");
515 
516         String expectedContent = mArchiveFileTestRule.getAssetText(
517                 "archives/original/hello/inside_folder/hello_insside.txt");
518 
519         ArchiveHandle archiveHandle = ArchiveHandle.create(parcelFileDescriptor,
520                 "application/x-compressed-tar");
521 
522         ArchiveEntry archiveEntry = mock(ArchiveEntry.class);
523         when(archiveEntry.getName()).thenReturn("");
524         try {
525             archiveHandle.getInputStream(archiveEntry);
526             fail("It should not here");
527         } catch (IllegalArgumentException | ArchiveException | CompressorException e) {
528             /* expected, do nothing */
529         }
530     }
531 
532     @Test
getInputStream_tarBrotliFile_shouldHaveTheSameContent()533     public void getInputStream_tarBrotliFile_shouldHaveTheSameContent() throws Exception {
534         ParcelFileDescriptor parcelFileDescriptor = mArchiveFileTestRule
535                 .openAssetFile("archives/brotli/hello.tar.br", ".tar.br");
536 
537         String expectedContent = mArchiveFileTestRule.getAssetText(
538                 "archives/original/hello/inside_folder/hello_insside.txt");
539 
540         ArchiveHandle archiveHandle = ArchiveHandle.create(parcelFileDescriptor,
541                 "application/x-brotli-compressed-tar");
542 
543         InputStream inputStream = archiveHandle.getInputStream(
544                 getFileInArchive(archiveHandle.getEntries(),
545                         "hello/inside_folder/hello_insside.txt"));
546 
547         assertThat(ArchiveFileTestRule.getStringFromInputStream(inputStream))
548                 .isEqualTo(expectedContent);
549     }
550 
551     @Test
getEntries_zipFile_shouldTheSameWithList()552     public void getEntries_zipFile_shouldTheSameWithList() throws Exception {
553         ArchiveHandle archiveHandle =
554                 prepareArchiveHandle("archives/zip/hello.zip", ".zip",
555                         "application/zip");
556 
557         assertThat(transformToIterable(archiveHandle.getEntries()))
558                 .containsAllIn(sExpectEntries);
559     }
560 
561     @Test
getEntries_tarFile_shouldTheSameWithList()562     public void getEntries_tarFile_shouldTheSameWithList() throws Exception {
563         ArchiveHandle archiveHandle =
564                 prepareArchiveHandle("archives/tar/hello.tar", ".tar",
565                 "application/x-gtar");
566 
567         assertThat(transformToIterable(archiveHandle.getEntries()))
568                 .containsAllIn(sExpectEntries);
569     }
570 
571     @Test
getEntries_tgzFile_shouldTheSameWithList()572     public void getEntries_tgzFile_shouldTheSameWithList() throws Exception {
573         ArchiveHandle archiveHandle =
574                 prepareArchiveHandle("archives/tar_gz/hello.tgz", ".tgz",
575                         "application/x-compressed-tar");
576 
577         assertThat(transformToIterable(archiveHandle.getEntries()))
578                 .containsAllIn(sExpectEntries);
579     }
580 
581     @Test
getEntries_tarBzFile_shouldTheSameWithList()582     public void getEntries_tarBzFile_shouldTheSameWithList() throws Exception {
583         ArchiveHandle archiveHandle =
584                 prepareArchiveHandle("archives/tar_bz2/hello.tar.bz2", ".tar.bz2",
585                         "application/x-bzip-compressed-tar");
586 
587         assertThat(transformToIterable(archiveHandle.getEntries()))
588                 .containsAllIn(sExpectEntries);
589     }
590 
591     @Test
getEntries_tarBrotliFile_shouldTheSameWithList()592     public void getEntries_tarBrotliFile_shouldTheSameWithList() throws Exception {
593         ArchiveHandle archiveHandle =
594                 prepareArchiveHandle("archives/brotli/hello.tar.br", ".tar.br",
595                         "application/x-brotli-compressed-tar");
596 
597         assertThat(transformToIterable(archiveHandle.getEntries()))
598                 .containsAllIn(sExpectEntries);
599     }
600 
601     @Test
getEntries_tarXzFile_shouldTheSameWithList()602     public void getEntries_tarXzFile_shouldTheSameWithList() throws Exception {
603         ArchiveHandle archiveHandle =
604                 prepareArchiveHandle("archives/xz/hello.tar.xz", ".tar.xz",
605                         "application/x-xz-compressed-tar");
606 
607         assertThat(transformToIterable(archiveHandle.getEntries()))
608                 .containsAllIn(sExpectEntries);
609     }
610 }
611