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   *   https://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.archivers.sevenz;
20  
21  import static org.junit.jupiter.api.Assertions.assertEquals;
22  import static org.junit.jupiter.api.Assertions.assertNotEquals;
23  import static org.junit.jupiter.api.Assertions.assertThrows;
24  
25  import org.junit.jupiter.api.Test;
26  
27  /**
28   * Tests {@link SevenZArchiveEntry}.
29   */
30  class SevenZArchiveEntryTest {
31  
32      @Test
33      void testMethodConfigurationMattersInEquals() {
34          final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
35          final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
36          final SevenZArchiveEntry z3 = new SevenZArchiveEntry();
37          z1.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 1));
38          z2.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 2));
39          z3.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 2));
40          assertNotEquals(z1, z2);
41          assertNotEquals(z2, z1);
42          assertEquals(z3, z2);
43          assertEquals(z2, z3);
44      }
45  
46      @Test
47      void testMethodOrderMattersInEquals() {
48          final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
49          final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
50          z1.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.LZMA2), new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER));
51          z2.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER), new SevenZMethodConfiguration(SevenZMethod.LZMA2));
52          assertNotEquals(z1, z2);
53          assertNotEquals(z2, z1);
54      }
55  
56      @Test
57      void testNoMethodsIsDifferentFromSomeMethods() {
58          final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
59          final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
60          z2.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.COPY));
61          assertNotEquals(z1, z2);
62          assertNotEquals(z2, z1);
63      }
64  
65      @Test
66      void testOneMethodsIsDifferentFromTwoMethods() {
67          final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
68          final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
69          z1.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.COPY));
70          z2.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER), new SevenZMethodConfiguration(SevenZMethod.LZMA2));
71          assertNotEquals(z1, z2);
72          assertNotEquals(z2, z1);
73      }
74  
75      @Test
76      void testSameMethodsYieldEqualEntries() {
77          final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
78          final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
79          z1.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER), new SevenZMethodConfiguration(SevenZMethod.LZMA2));
80          z2.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER), new SevenZMethodConfiguration(SevenZMethod.LZMA2));
81          assertEquals(z1, z2);
82          assertEquals(z2, z1);
83      }
84  
85      @Test
86      void testShouldThrowIfAccessDateIsSetToNull() {
87          assertThrows(UnsupportedOperationException.class, () -> {
88              final SevenZArchiveEntry entry = new SevenZArchiveEntry();
89              entry.setAccessDate(null);
90              entry.getAccessDate();
91          });
92      }
93  
94      @Test
95      void testShouldThrowIfCreationDateIsSetToNull() {
96          assertThrows(UnsupportedOperationException.class, () -> {
97              final SevenZArchiveEntry entry = new SevenZArchiveEntry();
98              entry.setCreationDate(null);
99              entry.getCreationDate();
100         });
101     }
102 
103     @Test
104     void testShouldThrowIfLastModifiedDateIsSetToNull() {
105         assertThrows(UnsupportedOperationException.class, () -> {
106             final SevenZArchiveEntry entry = new SevenZArchiveEntry();
107             entry.setLastModifiedDate(null);
108             entry.getLastModifiedDate();
109         });
110     }
111 
112     @Test
113     void testShouldThrowIfNoAccessDateIsSet() {
114         assertThrows(UnsupportedOperationException.class, () -> new SevenZArchiveEntry().getAccessDate());
115     }
116 
117     @Test
118     void testShouldThrowIfNoCreationDateIsSet() {
119         assertThrows(UnsupportedOperationException.class, () -> new SevenZArchiveEntry().getCreationDate());
120     }
121 
122     @Test
123     void testShouldThrowIfNoLastModifiedDateIsSet() {
124         assertThrows(UnsupportedOperationException.class, () -> new SevenZArchiveEntry().getLastModifiedDate());
125     }
126 
127 }