1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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 }