3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
11 * @file EthernetAddressTest.java
13 * @brief Unit Tests for EthernetAddress class
15 * Unit Tests for EthernetAddress class
17 package org.opendaylight.controller.sal.packet.address;
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.opendaylight.controller.liblldp.ConstructionException;
22 import org.opendaylight.controller.liblldp.EthernetAddress;
24 public class EthernetAddressTest {
26 public void testNonValidConstructor() {
27 @SuppressWarnings("unused")
31 ea1 = new EthernetAddress((byte[]) null);
33 // Exception is expected if NOT raised test will fail
34 Assert.assertTrue(false);
35 } catch (ConstructionException e) {
40 ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0 });
42 // Exception is expected if NOT raised test will fail
43 Assert.assertTrue(false);
44 } catch (ConstructionException e) {
49 ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
50 (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0,
53 // Exception is expected if NOT raised test will fail
54 Assert.assertTrue(false);
55 } catch (ConstructionException e) {
60 public void testEquality() {
64 ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
65 (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
67 ea2 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
68 (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
69 Assert.assertTrue(ea1.equals(ea2));
70 } catch (ConstructionException e) {
71 // Exception is NOT expected if raised test will fail
72 Assert.assertTrue(false);
76 ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
77 (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
80 Assert.assertTrue(ea1.equals(ea2));
81 } catch (ConstructionException e) {
82 // Exception is NOT expected if raised test will fail
83 Assert.assertTrue(false);
86 // Check for well knowns
88 ea1 = EthernetAddress.BROADCASTMAC;
89 ea2 = new EthernetAddress(new byte[] { (byte) 0xff, (byte) 0xff,
90 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff });
91 Assert.assertTrue(ea1.equals(ea2));
92 } catch (ConstructionException e) {
93 // Exception is NOT expected if raised test will fail
94 Assert.assertTrue(false);
99 public void testUnEquality() {
103 ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
104 (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x2 });
106 ea2 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
107 (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
108 Assert.assertTrue(!ea1.equals(ea2));
109 } catch (ConstructionException e) {
110 // Exception is NOT expected if raised test will fail
111 Assert.assertTrue(false);