X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fcommons%2Fliblldp%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fpacket%2Faddress%2FEthernetAddressTest.java;fp=opendaylight%2Fcommons%2Fliblldp%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fpacket%2Faddress%2FEthernetAddressTest.java;h=cfdc7851e37aab31c631837328edbf0825ce1a7c;hb=4d73514271a9caaa59b7a042d206ba4aad6b3fe0;hp=0000000000000000000000000000000000000000;hpb=9b99e3841bb3f703cc72883ef9a5ef00cfa32f04;p=controller.git diff --git a/opendaylight/commons/liblldp/src/test/java/org/opendaylight/controller/sal/packet/address/EthernetAddressTest.java b/opendaylight/commons/liblldp/src/test/java/org/opendaylight/controller/sal/packet/address/EthernetAddressTest.java new file mode 100644 index 0000000000..cfdc7851e3 --- /dev/null +++ b/opendaylight/commons/liblldp/src/test/java/org/opendaylight/controller/sal/packet/address/EthernetAddressTest.java @@ -0,0 +1,114 @@ + +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +/** + * @file EthernetAddressTest.java + * + * @brief Unit Tests for EthernetAddress class + * + * Unit Tests for EthernetAddress class + */ +package org.opendaylight.controller.sal.packet.address; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.controller.liblldp.ConstructionException; +import org.opendaylight.controller.liblldp.EthernetAddress; + +public class EthernetAddressTest { + @Test + public void testNonValidConstructor() { + @SuppressWarnings("unused") + EthernetAddress ea1; + // Null input array + try { + ea1 = new EthernetAddress((byte[]) null); + + // Exception is expected if NOT raised test will fail + Assert.assertTrue(false); + } catch (ConstructionException e) { + } + + // Array too short + try { + ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0 }); + + // Exception is expected if NOT raised test will fail + Assert.assertTrue(false); + } catch (ConstructionException e) { + } + + // Array too long + try { + ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0, + (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, + (byte) 0x0 }); + + // Exception is expected if NOT raised test will fail + Assert.assertTrue(false); + } catch (ConstructionException e) { + } + } + + @Test + public void testEquality() { + EthernetAddress ea1; + EthernetAddress ea2; + try { + ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0, + (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 }); + + ea2 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0, + (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 }); + Assert.assertTrue(ea1.equals(ea2)); + } catch (ConstructionException e) { + // Exception is NOT expected if raised test will fail + Assert.assertTrue(false); + } + + try { + ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0, + (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 }); + + ea2 = ea1.clone(); + Assert.assertTrue(ea1.equals(ea2)); + } catch (ConstructionException e) { + // Exception is NOT expected if raised test will fail + Assert.assertTrue(false); + } + + // Check for well knowns + try { + ea1 = EthernetAddress.BROADCASTMAC; + ea2 = new EthernetAddress(new byte[] { (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff }); + Assert.assertTrue(ea1.equals(ea2)); + } catch (ConstructionException e) { + // Exception is NOT expected if raised test will fail + Assert.assertTrue(false); + } + } + + @Test + public void testUnEquality() { + EthernetAddress ea1; + EthernetAddress ea2; + try { + ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0, + (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x2 }); + + ea2 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0, + (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 }); + Assert.assertTrue(!ea1.equals(ea2)); + } catch (ConstructionException e) { + // Exception is NOT expected if raised test will fail + Assert.assertTrue(false); + } + } +}