1 package io.fd.honeycomb.translate.v3po.util;
3 import static org.junit.Assert.assertEquals;
7 public class MacTranslatorTest implements MacTranslator {
10 public void testParseMac() throws Exception {
11 byte[] bytes = parseMac("00:fF:7f:15:5e:A9");
15 private void assertMac(final byte[] bytes) {
16 assertEquals(6, bytes.length);
17 assertEquals((byte) 0, bytes[0]);
18 assertEquals((byte) 255, bytes[1]);
19 assertEquals((byte) 127, bytes[2]);
20 assertEquals((byte) 21, bytes[3]);
21 assertEquals((byte) 94, bytes[4]);
22 assertEquals((byte) 169, bytes[5]);
25 @Test(expected = IllegalArgumentException.class)
26 public void testParseMacLonger() throws Exception {
27 byte[] bytes = parseMac("00:fF:7f:15:5e:A9:88:77");
31 @Test(expected = IllegalArgumentException.class)
32 public void testParseMacShorter() throws Exception {
36 @Test(expected = IllegalArgumentException.class)
37 public void testParseRandomString() throws Exception {
38 parseMac("random{}}@$*&*!");
41 @Test(expected = NumberFormatException.class)
42 public void testParseMacNumberFormatEx() throws Exception {
43 parseMac("00:XX:7f:15:5e:77\"");
47 public void testByteArrayToMacUnseparated() {
48 byte[] address = parseMac("aa:bb:cc:dd:ee:ff");
50 String converted = byteArrayToMacUnseparated(address);
52 assertEquals("aabbccddeeff", converted);
56 public void testByteArrayToMacSeparated() {
57 byte[] address = parseMac("aa:bb:cc:dd:ee:ff");
59 String converted = byteArrayToMacSeparated(address);
61 assertEquals("aa:bb:cc:dd:ee:ff", converted);
64 @Test(expected = IllegalArgumentException.class)
65 public void testByteArrayToMacUnseparatedIllegal() {
66 byteArrayToMacUnseparated(new byte[]{54, 26, 87, 32, 14});
69 @Test(expected = IllegalArgumentException.class)
70 public void testByteArrayToMacSeparatedIllegal() {
71 byteArrayToMacSeparated(new byte[]{54, 26, 87, 32, 14});