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