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.xz.XZUtils;
24  
25  public class XZUtilsTestCase extends TestCase {
26  
27      public void testIsCompressedFilename() {
28          assertFalse(XZUtils.isCompressedFilename(""));
29          assertFalse(XZUtils.isCompressedFilename(".xz"));
30  
31          assertTrue(XZUtils.isCompressedFilename("x.txz"));
32          assertTrue(XZUtils.isCompressedFilename("x.xz"));
33          assertTrue(XZUtils.isCompressedFilename("x-xz"));
34  
35          assertFalse(XZUtils.isCompressedFilename("xxgz"));
36          assertFalse(XZUtils.isCompressedFilename("xzz"));
37          assertFalse(XZUtils.isCompressedFilename("xaz"));
38  
39          assertFalse(XZUtils.isCompressedFilename("x.txz "));
40          assertFalse(XZUtils.isCompressedFilename("x.txz\n"));
41          assertFalse(XZUtils.isCompressedFilename("x.txz.y"));
42      }
43  
44      public void testGetUncompressedFilename() {
45          assertEquals("", XZUtils.getUncompressedFilename(""));
46          assertEquals(".xz", XZUtils.getUncompressedFilename(".xz"));
47  
48          assertEquals("x.tar", XZUtils.getUncompressedFilename("x.txz"));
49          assertEquals("x", XZUtils.getUncompressedFilename("x.xz"));
50          assertEquals("x", XZUtils.getUncompressedFilename("x-xz"));
51  
52          assertEquals("x.txz ", XZUtils.getUncompressedFilename("x.txz "));
53          assertEquals("x.txz\n", XZUtils.getUncompressedFilename("x.txz\n"));
54          assertEquals("x.txz.y", XZUtils.getUncompressedFilename("x.txz.y"));
55      }
56  
57      public void testGetCompressedFilename() {
58          assertEquals(".xz", XZUtils.getCompressedFilename(""));
59          assertEquals("x.xz", XZUtils.getCompressedFilename("x"));
60  
61          assertEquals("x.txz", XZUtils.getCompressedFilename("x.tar"));
62  
63          assertEquals("x.wmf .xz", XZUtils.getCompressedFilename("x.wmf "));
64          assertEquals("x.wmf\n.xz", XZUtils.getCompressedFilename("x.wmf\n"));
65          assertEquals("x.wmf.y.xz", XZUtils.getCompressedFilename("x.wmf.y"));
66      }
67  
68  }