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 junit.framework.TestCase;
22  
23  import org.apache.commons.compress.compressors.bzip2.BZip2Utils;
24  
25  public class BZip2UtilsTestCase extends TestCase {
26  
27      public void testIsCompressedFilename() {
28          assertFalse(BZip2Utils.isCompressedFilename(""));
29          assertFalse(BZip2Utils.isCompressedFilename(".gz"));
30  
31          assertTrue(BZip2Utils.isCompressedFilename("x.tbz2"));
32          assertTrue(BZip2Utils.isCompressedFilename("x.tbz"));
33          assertTrue(BZip2Utils.isCompressedFilename("x.bz2"));
34          assertTrue(BZip2Utils.isCompressedFilename("x.bz"));
35  
36          assertFalse(BZip2Utils.isCompressedFilename("xbz2"));
37          assertFalse(BZip2Utils.isCompressedFilename("xbz"));
38  
39          assertTrue(BZip2Utils.isCompressedFilename("x.TBZ2"));
40          assertTrue(BZip2Utils.isCompressedFilename("x.Tbz2"));
41          assertTrue(BZip2Utils.isCompressedFilename("x.tbZ2"));
42  
43          assertFalse(BZip2Utils.isCompressedFilename("x.bz "));
44          assertFalse(BZip2Utils.isCompressedFilename("x.tbz\n"));
45          assertFalse(BZip2Utils.isCompressedFilename("x.tbz2.y"));
46      }
47  
48      public void testGetUncompressedFilename() {
49          assertEquals("", BZip2Utils.getUncompressedFilename(""));
50          assertEquals(".bz2", BZip2Utils.getUncompressedFilename(".bz2"));
51  
52          assertEquals("x.tar", BZip2Utils.getUncompressedFilename("x.tbz2"));
53          assertEquals("x.tar", BZip2Utils.getUncompressedFilename("x.tbz"));
54          assertEquals("x", BZip2Utils.getUncompressedFilename("x.bz2"));
55          assertEquals("x", BZip2Utils.getUncompressedFilename("x.bz"));
56  
57          assertEquals("x.tar", BZip2Utils.getUncompressedFilename("x.TBZ2"));
58          assertEquals("X.tar", BZip2Utils.getUncompressedFilename("X.Tbz2"));
59          assertEquals("X.tar", BZip2Utils.getUncompressedFilename("X.tbZ2"));
60  
61          assertEquals("x.bz ", BZip2Utils.getUncompressedFilename("x.bz "));
62          assertEquals("x.tbz\n", BZip2Utils.getUncompressedFilename("x.tbz\n"));
63          assertEquals("x.tbz2.y", BZip2Utils.getUncompressedFilename("x.tbz2.y"));
64      }
65  
66      public void testGetCompressedFilename() {
67          assertEquals(".bz2", BZip2Utils.getCompressedFilename(""));
68          assertEquals(" .bz2", BZip2Utils.getCompressedFilename(" "));
69          assertEquals("x.bz2", BZip2Utils.getCompressedFilename("x"));
70          assertEquals("X.bz2", BZip2Utils.getCompressedFilename("X"));
71          assertEquals("x.tar.bz2", BZip2Utils.getCompressedFilename("x.tar"));
72          assertEquals("x.tar.bz2", BZip2Utils.getCompressedFilename("x.TAR"));
73      }
74  
75  }