View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.commons.compress.compressors;
20  
21  import static org.junit.Assert.*;
22  
23  import org.apache.commons.compress.compressors.bzip2.BZip2Utils;
24  import org.junit.Test;
25  
26  public class BZip2UtilsTestCase {
27  
28      @Test
29      public void testIsCompressedFilename() {
30          assertFalse(BZip2Utils.isCompressedFilename(""));
31          assertFalse(BZip2Utils.isCompressedFilename(".gz"));
32  
33          assertTrue(BZip2Utils.isCompressedFilename("x.tbz2"));
34          assertTrue(BZip2Utils.isCompressedFilename("x.tbz"));
35          assertTrue(BZip2Utils.isCompressedFilename("x.bz2"));
36          assertTrue(BZip2Utils.isCompressedFilename("x.bz"));
37  
38          assertFalse(BZip2Utils.isCompressedFilename("xbz2"));
39          assertFalse(BZip2Utils.isCompressedFilename("xbz"));
40  
41          assertTrue(BZip2Utils.isCompressedFilename("x.TBZ2"));
42          assertTrue(BZip2Utils.isCompressedFilename("x.Tbz2"));
43          assertTrue(BZip2Utils.isCompressedFilename("x.tbZ2"));
44  
45          assertFalse(BZip2Utils.isCompressedFilename("x.bz "));
46          assertFalse(BZip2Utils.isCompressedFilename("x.tbz\n"));
47          assertFalse(BZip2Utils.isCompressedFilename("x.tbz2.y"));
48      }
49  
50      @Test
51      public void testGetUncompressedFilename() {
52          assertEquals("", BZip2Utils.getUncompressedFilename(""));
53          assertEquals(".bz2", BZip2Utils.getUncompressedFilename(".bz2"));
54  
55          assertEquals("x.tar", BZip2Utils.getUncompressedFilename("x.tbz2"));
56          assertEquals("x.tar", BZip2Utils.getUncompressedFilename("x.tbz"));
57          assertEquals("x", BZip2Utils.getUncompressedFilename("x.bz2"));
58          assertEquals("x", BZip2Utils.getUncompressedFilename("x.bz"));
59  
60          assertEquals("x.tar", BZip2Utils.getUncompressedFilename("x.TBZ2"));
61          assertEquals("X.tar", BZip2Utils.getUncompressedFilename("X.Tbz2"));
62          assertEquals("X.tar", BZip2Utils.getUncompressedFilename("X.tbZ2"));
63  
64          assertEquals("x.bz ", BZip2Utils.getUncompressedFilename("x.bz "));
65          assertEquals("x.tbz\n", BZip2Utils.getUncompressedFilename("x.tbz\n"));
66          assertEquals("x.tbz2.y", BZip2Utils.getUncompressedFilename("x.tbz2.y"));
67      }
68  
69      @Test
70      public void testGetCompressedFilename() {
71          assertEquals(".bz2", BZip2Utils.getCompressedFilename(""));
72          assertEquals(" .bz2", BZip2Utils.getCompressedFilename(" "));
73          assertEquals("x.bz2", BZip2Utils.getCompressedFilename("x"));
74          assertEquals("X.bz2", BZip2Utils.getCompressedFilename("X"));
75          assertEquals("x.tar.bz2", BZip2Utils.getCompressedFilename("x.tar"));
76          assertEquals("x.tar.bz2", BZip2Utils.getCompressedFilename("x.TAR"));
77      }
78  
79  }