1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
/*
* Copyright (c) 2012, Isode Limited, London, England.
* All rights reserved.
*/
/*
* Copyright (c) 2010, Remko Tronçon.
* All rights reserved.
*/
package com.isode.stroke.stringcodecs;
import com.isode.stroke.base.ByteArray;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class HexifyTest {
private ByteArray fix(int[] vals) {
byte[] fixed = new byte[vals.length];
for (int i = 0; i < fixed.length; i++) {
fixed[i] = (byte) vals[i];
}
return new ByteArray(fixed);
}
@Test
public void testHexify() {
assertEquals("4206b23ca6b0a643d20d89b04ff58cf78b8096ed", Hexify.hexify(fix(new int[]{0x42, 0x06, 0xb2, 0x3c, 0xa6, 0xb0, 0xa6, 0x43, 0xd2, 0x0d, 0x89, 0xb0, 0x4f, 0xf5, 0x8c, 0xf7, 0x8b, 0x80, 0x96, 0xed})));
}
@Test
public void testHexify_Byte() {
assertEquals("b2", Hexify.hexify((byte) 0xb2));
}
@Test
public void testUnhexify() {
assertEquals("ffaf02", Hexify.hexify(Hexify.unhexify("ffaf02")));
assertEquals(new ByteArray(fix(new int[]{0x01, 0x23, 0xf2})), Hexify.unhexify("0123f2"));
}
};
|