1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.buildcache.hash;
20
21 import org.junit.jupiter.api.Test;
22
23 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25
26 public class HexUtilsTest {
27
28 @Test
29 public void testEncodeToHex() {
30
31 assertEquals("0000000000000000", HexUtils.encode(new byte[8]));
32 assertEquals("00", HexUtils.encode(new byte[1]));
33
34 assertEquals("0a", HexUtils.encode(new byte[] {10}));
35 assertEquals("000000000000000a", HexUtils.encode(new byte[] {0, 0, 0, 0, 0, 0, 0, 10}));
36
37 assertEquals("0100", HexUtils.encode(new byte[] {1, 0}));
38 assertEquals("0000000000000101", HexUtils.encode(new byte[] {0, 0, 0, 0, 0, 0, 1, 1}));
39 }
40
41 @Test
42 public void testDecodeHex() {
43 assertArrayEquals(new byte[] {0}, HexUtils.decode("00"));
44 assertArrayEquals(new byte[] {10}, HexUtils.decode("0a"));
45 assertArrayEquals(new byte[] {10}, HexUtils.decode("0A"));
46 assertArrayEquals(new byte[] {1, 0}, HexUtils.decode("0100"));
47 }
48 }