Clean all unused and redundant imports in controller.
[controller.git] / opendaylight / sal / api / src / test / java / org / opendaylight / controller / sal / packet / address / EthernetAddressTest.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
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
8  */
9
10 /**
11  * @file   EthernetAddressTest.java
12  *
13  * @brief  Unit Tests for EthernetAddress class
14  *
15  * Unit Tests for EthernetAddress class
16  */
17 package org.opendaylight.controller.sal.packet.address;
18
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.opendaylight.controller.sal.core.ConstructionException;
22
23 public class EthernetAddressTest {
24     @Test
25     public void testNonValidConstructor() {
26         EthernetAddress ea1;
27         // Null input array
28         try {
29             ea1 = new EthernetAddress((byte[]) null);
30
31             // Exception is expected if NOT raised test will fail
32             Assert.assertTrue(false);
33         } catch (ConstructionException e) {
34         }
35
36         // Array too short
37         try {
38             ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0 });
39
40             // Exception is expected if NOT raised test will fail
41             Assert.assertTrue(false);
42         } catch (ConstructionException e) {
43         }
44
45         // Array too long
46         try {
47             ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
48                     (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0,
49                     (byte) 0x0 });
50
51             // Exception is expected if NOT raised test will fail
52             Assert.assertTrue(false);
53         } catch (ConstructionException e) {
54         }
55     }
56
57     @Test
58     public void testEquality() {
59         EthernetAddress ea1;
60         EthernetAddress ea2;
61         try {
62             ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
63                     (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
64
65             ea2 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
66                     (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
67             Assert.assertTrue(ea1.equals(ea2));
68         } catch (ConstructionException e) {
69             // Exception is NOT expected if raised test will fail
70             Assert.assertTrue(false);
71         }
72
73         try {
74             ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
75                     (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
76
77             ea2 = ea1.clone();
78             Assert.assertTrue(ea1.equals(ea2));
79         } catch (ConstructionException e) {
80             // Exception is NOT expected if raised test will fail
81             Assert.assertTrue(false);
82         }
83
84         // Check for well knowns
85         try {
86             ea1 = EthernetAddress.BROADCASTMAC;
87             ea2 = new EthernetAddress(new byte[] { (byte) 0xff, (byte) 0xff,
88                     (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff });
89             Assert.assertTrue(ea1.equals(ea2));
90         } catch (ConstructionException e) {
91             // Exception is NOT expected if raised test will fail
92             Assert.assertTrue(false);
93         }
94     }
95
96     @Test
97     public void testUnEquality() {
98         EthernetAddress ea1;
99         EthernetAddress ea2;
100         try {
101             ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
102                     (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x2 });
103
104             ea2 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
105                     (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
106             Assert.assertTrue(!ea1.equals(ea2));
107         } catch (ConstructionException e) {
108             // Exception is NOT expected if raised test will fail
109             Assert.assertTrue(false);
110         }
111     }
112 }