Fixed FIXME on MAC address serialization
[openflowjava.git] / util / src / test / java / org / opendaylight / openflowjava / util / ByteBufUtilsTest.java
index 6ca0e7b0dc4716dea87acc3577503fbf230b7ee0..9bbb0d743b874c43c45ba4bd736ea50603556e50 100644 (file)
@@ -223,8 +223,14 @@ public class ByteBufUtilsTest {
     public void testMacToBytes() {
         Assert.assertArrayEquals("Wrong byte array", new byte[]{0, 1, 2, 3, (byte) 255, 5},
                 ByteBufUtils.macAddressToBytes("00:01:02:03:FF:05"));
-        Assert.assertArrayEquals("Wrong byte array", new byte[]{11, 1, 2, 3, (byte) 255, 10},
-                ByteBufUtils.macAddressToBytes("0b:01:02:03:FF:0a"));
+        Assert.assertArrayEquals("Wrong byte array", new byte[]{1, 2, 3, 4, (byte) 255, 5},
+                ByteBufUtils.macAddressToBytes("01:02:03:04:FF:05"));
+        Assert.assertArrayEquals("Wrong byte array", new byte[]{1, 2, 3, 4, (byte) 255, 5},
+                ByteBufUtils.macAddressToBytes("1:2:3:4:FF:5"));
+        Assert.assertArrayEquals("Wrong byte array", new byte[]{1, 2, 3, 4, 5, (byte) 255},
+                ByteBufUtils.macAddressToBytes("1:2:3:4:5:FF"));
+        Assert.assertArrayEquals("Wrong byte array", new byte[]{1, 15, 3, 4, 5, 6},
+                ByteBufUtils.macAddressToBytes("1:F:3:4:5:6"));
     }
 
     /**
@@ -236,6 +242,70 @@ public class ByteBufUtilsTest {
                 ByteBufUtils.macAddressToBytes("00:01:02:03:FF:0G"));
     }
 
+    /**
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     */
+    @Test(expected=IllegalArgumentException.class)
+    public void testMacToBytesTooShort() {
+        ByteBufUtils.macAddressToBytes("00:01:02:03:FF");
+    }
+
+    /**
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     */
+    @Test(expected=IllegalArgumentException.class)
+    public void testMacToBytesTooShort2() {
+        ByteBufUtils.macAddressToBytes("00:01:02:03:FF:");
+    }
+
+    /**
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     */
+    @Test(expected=IllegalArgumentException.class)
+    public void testIncorrectMacToBytes() {
+        ByteBufUtils.macAddressToBytes("00:01:02:03:FF::");
+    }
+
+    /**
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     */
+    @Test(expected=IllegalArgumentException.class)
+    public void testIncorrectMacToBytes2() {
+        ByteBufUtils.macAddressToBytes("00:01:02:03:FF:::");
+    }
+
+    /**
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     */
+    @Test(expected=IllegalArgumentException.class)
+    public void testMacToBytesTooLong() {
+        ByteBufUtils.macAddressToBytes("00:01:02:03:FF:05:85");
+    }
+
+    /**
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     */
+    @Test(expected=IllegalArgumentException.class)
+    public void testMacToBytesInvalidOctet() {
+        ByteBufUtils.macAddressToBytes("00:01:02:03:FF:05d");
+    }
+
+    /**
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     */
+    @Test(expected=IllegalArgumentException.class)
+    public void testMacToBytesInvalidOctet2() {
+        ByteBufUtils.macAddressToBytes("00:01:rr:03:FF:05");
+    }
+
+    /**
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     */
+    @Test(expected=IllegalArgumentException.class)
+    public void testMacToBytesInvalidOctet3() {
+        ByteBufUtils.macAddressToBytes("00:01:05d:03:FF:02");
+    }
+
     /**
      * Test of {@link ByteBufUtils#macAddressToString(byte[])}
      */