View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one or more
3    *  contributor license agreements.  See the NOTICE file distributed with
4    *  this work for additional information regarding copyright ownership.
5    *  The ASF licenses this file to You under the Apache License, Version 2.0
6    *  (the "License"); you may not use this file except in compliance with
7    *  the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  package org.apache.commons.compress.archivers.sevenz;
18  
19  import static org.junit.jupiter.api.Assertions.assertEquals;
20  import static org.junit.jupiter.api.Assertions.assertNotEquals;
21  import static org.junit.jupiter.api.Assertions.assertThrows;
22  
23  import org.junit.jupiter.api.Test;
24  
25  /**
26   * Tests {@link SevenZArchiveEntry}.
27   */
28  public class SevenZArchiveEntryTest {
29  
30      @Test
31      public void testMethodConfigurationMattersInEquals() {
32          final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
33          final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
34          final SevenZArchiveEntry z3 = new SevenZArchiveEntry();
35          z1.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 1));
36          z2.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 2));
37          z3.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 2));
38          assertNotEquals(z1, z2);
39          assertNotEquals(z2, z1);
40          assertEquals(z3, z2);
41          assertEquals(z2, z3);
42      }
43  
44      @Test
45      public void testMethodOrderMattersInEquals() {
46          final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
47          final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
48          z1.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.LZMA2), new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER));
49          z2.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER), new SevenZMethodConfiguration(SevenZMethod.LZMA2));
50          assertNotEquals(z1, z2);
51          assertNotEquals(z2, z1);
52      }
53  
54      @Test
55      public void testNoMethodsIsDifferentFromSomeMethods() {
56          final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
57          final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
58          z2.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.COPY));
59          assertNotEquals(z1, z2);
60          assertNotEquals(z2, z1);
61      }
62  
63      @Test
64      public void testOneMethodsIsDifferentFromTwoMethods() {
65          final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
66          final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
67          z1.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.COPY));
68          z2.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER), new SevenZMethodConfiguration(SevenZMethod.LZMA2));
69          assertNotEquals(z1, z2);
70          assertNotEquals(z2, z1);
71      }
72  
73      @Test
74      public void testSameMethodsYieldEqualEntries() {
75          final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
76          final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
77          z1.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER), new SevenZMethodConfiguration(SevenZMethod.LZMA2));
78          z2.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER), new SevenZMethodConfiguration(SevenZMethod.LZMA2));
79          assertEquals(z1, z2);
80          assertEquals(z2, z1);
81      }
82  
83      @Test
84      public void testShouldThrowIfAccessDateIsSetToNull() {
85          assertThrows(UnsupportedOperationException.class, () -> {
86              final SevenZArchiveEntry entry = new SevenZArchiveEntry();
87              entry.setAccessDate(null);
88              entry.getAccessDate();
89          });
90      }
91  
92      @Test
93      public void testShouldThrowIfCreationDateIsSetToNull() {
94          assertThrows(UnsupportedOperationException.class, () -> {
95              final SevenZArchiveEntry entry = new SevenZArchiveEntry();
96              entry.setCreationDate(null);
97              entry.getCreationDate();
98          });
99      }
100 
101     @Test
102     public void testShouldThrowIfLastModifiedDateIsSetToNull() {
103         assertThrows(UnsupportedOperationException.class, () -> {
104             final SevenZArchiveEntry entry = new SevenZArchiveEntry();
105             entry.setLastModifiedDate(null);
106             entry.getLastModifiedDate();
107         });
108     }
109 
110     @Test
111     public void testShouldThrowIfNoAccessDateIsSet() {
112         assertThrows(UnsupportedOperationException.class, () -> new SevenZArchiveEntry().getAccessDate());
113     }
114 
115     @Test
116     public void testShouldThrowIfNoCreationDateIsSet() {
117         assertThrows(UnsupportedOperationException.class, () -> new SevenZArchiveEntry().getCreationDate());
118     }
119 
120     @Test
121     public void testShouldThrowIfNoLastModifiedDateIsSet() {
122         assertThrows(UnsupportedOperationException.class, () -> new SevenZArchiveEntry().getLastModifiedDate());
123     }
124 
125 }