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