e8a1e254e0aea117759016dcbed2c12c0a329e64
[hc2vpp.git] /
1 package io.fd.honeycomb.translate.vpp.util;
2
3 import static org.junit.Assert.assertEquals;
4
5 import org.junit.Test;
6
7 public class MacTranslatorTest implements MacTranslator {
8
9     @Test
10     public void testParseMac() throws Exception {
11         byte[] bytes = parseMac("00:fF:7f:15:5e:A9");
12         assertMac(bytes);
13     }
14
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]);
23     }
24
25     @Test(expected = IllegalArgumentException.class)
26     public void testParseMacLonger() throws Exception {
27         byte[] bytes = parseMac("00:fF:7f:15:5e:A9:88:77");
28         assertMac(bytes);
29     }
30
31     @Test(expected = IllegalArgumentException.class)
32     public void testParseMacShorter() throws Exception {
33         parseMac("00:fF:7f");
34     }
35
36     @Test(expected = IllegalArgumentException.class)
37     public void testParseRandomString() throws Exception {
38         parseMac("random{}}@$*&*!");
39     }
40
41     @Test(expected = NumberFormatException.class)
42     public void testParseMacNumberFormatEx() throws Exception {
43         parseMac("00:XX:7f:15:5e:77\"");
44     }
45
46     @Test
47     public void testByteArrayToMacUnseparated() {
48         byte[] address = parseMac("aa:bb:cc:dd:ee:ff");
49
50         String converted = byteArrayToMacUnseparated(address);
51
52         assertEquals("aabbccddeeff", converted);
53     }
54
55     @Test
56     public void testByteArrayToMacSeparated() {
57         byte[] address = parseMac("aa:bb:cc:dd:ee:ff");
58
59         String converted = byteArrayToMacSeparated(address);
60
61         assertEquals("aa:bb:cc:dd:ee:ff", converted);
62     }
63
64     @Test(expected = IllegalArgumentException.class)
65     public void testByteArrayToMacUnseparatedIllegal() {
66         byteArrayToMacUnseparated(new byte[]{54, 26, 87, 32, 14});
67     }
68
69     @Test(expected = IllegalArgumentException.class)
70     public void testByteArrayToMacSeparatedIllegal() {
71         byteArrayToMacSeparated(new byte[]{54, 26, 87, 32, 14});
72     }
73 }