a3c37bade4175502471749d80f581ac3f9ae8429
[hc2vpp.git] /
1 package io.fd.honeycomb.v3po.translate.v3po.util;
2
3 import static org.junit.Assert.assertArrayEquals;
4 import static org.junit.Assert.assertEquals;
5
6 import io.fd.honeycomb.v3po.translate.v3po.util.TranslateUtils;
7 import org.junit.Test;
8
9 public class TranslateUtilsTest {
10
11     @Test
12     public void testToString() {
13         final byte[] expected = "test".getBytes();
14         final byte[] cString = new byte[expected.length+10];
15         System.arraycopy(expected, 0, cString, 0, expected.length);
16         final String jString = TranslateUtils.toString(cString);
17         assertArrayEquals(expected, jString.getBytes());
18     }
19
20     @Test
21     public void testParseMac() throws Exception {
22         byte[] bytes = TranslateUtils.parseMac("00:fF:7f:15:5e:A9");
23         assertMac(bytes);
24     }
25
26     private void assertMac(final byte[] bytes) {
27         assertEquals(6, bytes.length);
28         assertEquals((byte)0, bytes[0]);
29         assertEquals((byte)255, bytes[1]);
30         assertEquals((byte)127, bytes[2]);
31         assertEquals((byte)21, bytes[3]);
32         assertEquals((byte)94, bytes[4]);
33         assertEquals((byte)169, bytes[5]);
34     }
35
36     @Test(expected = IllegalArgumentException.class)
37     public void testParseMacLonger() throws Exception {
38         byte[] bytes = TranslateUtils.parseMac("00:fF:7f:15:5e:A9:88:77");
39         assertMac(bytes);
40     }
41
42     @Test(expected = IllegalArgumentException.class)
43     public void testParseMacShorter() throws Exception {
44         TranslateUtils.parseMac("00:fF:7f");
45     }
46
47     @Test(expected = IllegalArgumentException.class)
48     public void testParseRandomString() throws Exception {
49         TranslateUtils.parseMac("random{}}@$*&*!");
50     }
51
52     @Test(expected = NumberFormatException.class)
53     public void testParseMacNumberFormatEx() throws Exception {
54         TranslateUtils.parseMac("00:XX:7f:15:5e:77\"");
55     }
56
57    public void testBooleanToByte() {
58        assertEquals(0, TranslateUtils.booleanToByte(null));
59        assertEquals(0, TranslateUtils.booleanToByte(false));
60        assertEquals(1, TranslateUtils.booleanToByte(true));
61    }
62 }