2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.translate.vpp.util;
19 import static org.junit.Assert.assertEquals;
21 import org.junit.Test;
23 public class MacTranslatorTest implements MacTranslator {
26 public void testParseMac() throws Exception {
27 byte[] bytes = parseMac("00:fF:7f:15:5e:A9");
31 private void assertMac(final byte[] bytes) {
32 assertEquals(6, bytes.length);
33 assertEquals((byte) 0, bytes[0]);
34 assertEquals((byte) 255, bytes[1]);
35 assertEquals((byte) 127, bytes[2]);
36 assertEquals((byte) 21, bytes[3]);
37 assertEquals((byte) 94, bytes[4]);
38 assertEquals((byte) 169, bytes[5]);
41 @Test(expected = IllegalArgumentException.class)
42 public void testParseMacLonger() throws Exception {
43 byte[] bytes = parseMac("00:fF:7f:15:5e:A9:88:77");
47 @Test(expected = IllegalArgumentException.class)
48 public void testParseMacShorter() throws Exception {
52 @Test(expected = IllegalArgumentException.class)
53 public void testParseRandomString() throws Exception {
54 parseMac("random{}}@$*&*!");
57 @Test(expected = NumberFormatException.class)
58 public void testParseMacNumberFormatEx() throws Exception {
59 parseMac("00:XX:7f:15:5e:77\"");
63 public void testByteArrayToMacUnseparated() {
64 byte[] address = parseMac("aa:bb:cc:dd:ee:ff");
66 String converted = byteArrayToMacUnseparated(address);
68 assertEquals("aabbccddeeff", converted);
72 public void testByteArrayToMacSeparated() {
73 byte[] address = parseMac("aa:bb:cc:dd:ee:ff");
75 String converted = byteArrayToMacSeparated(address);
77 assertEquals("aa:bb:cc:dd:ee:ff", converted);
80 @Test(expected = IllegalArgumentException.class)
81 public void testByteArrayToMacUnseparatedIllegal() {
82 byteArrayToMacUnseparated(new byte[]{54, 26, 87, 32, 14});
85 @Test(expected = IllegalArgumentException.class)
86 public void testByteArrayToMacSeparatedIllegal() {
87 byteArrayToMacSeparated(new byte[]{54, 26, 87, 32, 14});