1 package io.fd.honeycomb.v3po.translate.v3po.util;
3 import static org.junit.Assert.assertArrayEquals;
4 import static org.junit.Assert.assertEquals;
6 import io.fd.honeycomb.v3po.translate.v3po.util.TranslateUtils;
9 public class TranslateUtilsTest {
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());
21 public void testParseMac() throws Exception {
22 byte[] bytes = TranslateUtils.parseMac("00:fF:7f:15:5e:A9");
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]);
36 @Test(expected = IllegalArgumentException.class)
37 public void testParseMacLonger() throws Exception {
38 byte[] bytes = TranslateUtils.parseMac("00:fF:7f:15:5e:A9:88:77");
42 @Test(expected = IllegalArgumentException.class)
43 public void testParseMacShorter() throws Exception {
44 TranslateUtils.parseMac("00:fF:7f");
47 @Test(expected = IllegalArgumentException.class)
48 public void testParseRandomString() throws Exception {
49 TranslateUtils.parseMac("random{}}@$*&*!");
52 @Test(expected = NumberFormatException.class)
53 public void testParseMacNumberFormatEx() throws Exception {
54 TranslateUtils.parseMac("00:XX:7f:15:5e:77\"");
57 public void testBooleanToByte() {
58 assertEquals(0, TranslateUtils.booleanToByte(null));
59 assertEquals(0, TranslateUtils.booleanToByte(false));
60 assertEquals(1, TranslateUtils.booleanToByte(true));