1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.commons.compress.archivers.zip;
21
22 import static org.junit.jupiter.api.Assertions.assertEquals;
23 import static org.junit.jupiter.api.Assertions.assertNotEquals;
24 import static org.junit.jupiter.api.Assertions.assertNotSame;
25
26 import org.junit.jupiter.api.Test;
27
28
29
30
31 class ZipShortTest {
32
33 @Test
34 void testClone() {
35 final ZipShort s1 = new ZipShort(42);
36 final ZipShort s2 = (ZipShort) s1.clone();
37 assertNotSame(s1, s2);
38 assertEquals(s1, s2);
39 assertEquals(s1.getValue(), s2.getValue());
40 }
41
42
43
44
45 @Test
46 void testEquals() {
47 final ZipShort zs = new ZipShort(0x1234);
48 final ZipShort zs2 = new ZipShort(0x1234);
49 final ZipShort zs3 = new ZipShort(0x5678);
50
51 assertEquals(zs, zs, "reflexive");
52
53 assertEquals(zs, zs2, "works");
54 assertNotEquals(zs, zs3, "works, part two");
55
56 assertEquals(zs2, zs, "symmetric");
57
58 assertNotEquals(null, zs, "null handling");
59 assertNotEquals(zs, Integer.valueOf(0x1234), "non ZipShort handling");
60 }
61
62
63
64
65 @Test
66 void testFromBytes() {
67 final byte[] val = { 0x34, 0x12 };
68 final ZipShort zs = new ZipShort(val);
69 assertEquals(0x1234, zs.getValue(), "value from bytes");
70 }
71
72
73
74
75 @Test
76 void testPut() {
77 final byte[] arr = new byte[3];
78 ZipShort.putShort(0x1234, arr, 1);
79 assertEquals(0x34, arr[1], "first byte getBytes");
80 assertEquals(0x12, arr[2], "second byte getBytes");
81 }
82
83
84
85
86 @Test
87 void testSign() {
88 final ZipShort zs = new ZipShort(new byte[] { (byte) 0xFF, (byte) 0xFF });
89 assertEquals(0x0000FFFF, zs.getValue());
90 }
91
92
93
94
95 @Test
96 void testToBytes() {
97 final ZipShort zs = new ZipShort(0x1234);
98 final byte[] result = zs.getBytes();
99 assertEquals(2, result.length, "length getBytes");
100 assertEquals(0x34, result[0], "first byte getBytes");
101 assertEquals(0x12, result[1], "second byte getBytes");
102 }
103 }