b1c1b476b9544ac244052d33a51a4770b0d4da92
[bgpcep.git] / concepts / src / test / java / org / opendaylight / protocol / concepts / BandwidthTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.protocol.concepts;
10
11 import static org.hamcrest.CoreMatchers.equalTo;
12 import static org.hamcrest.CoreMatchers.not;
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertFalse;
15 import static org.junit.Assert.assertThat;
16
17 import java.util.HashSet;
18 import java.util.Set;
19
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.protocol.util.ByteArray;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
24
25 public class BandwidthTest {
26     private Bandwidth b1, b2, b3, b4;
27
28     @Before
29     public void setUp() {
30         this.b1 = new Bandwidth(ByteArray.intToBytes(1000, 4));
31         this.b2 = new Bandwidth(ByteArray.intToBytes(2000, 4));
32         this.b3 = new Bandwidth(ByteArray.intToBytes(2000, 4));
33         this.b4 = new Bandwidth(ByteArray.intToBytes(100, 4));
34     }
35
36     @Test
37     public void testBitsBytes() {
38         assertEquals(1000.0, ByteArray.bytesToLong(this.b1.getValue()), 0.1);
39     }
40
41     @Test
42     public void testEquals() {
43         assertFalse(this.b1.equals(null));
44         assertThat(this.b1, not(equalTo(new Object())));
45         assertThat(this.b1, equalTo(this.b1));
46         assertThat(this.b1, not(equalTo(this.b2)));
47         assertEquals(this.b2, this.b3);
48         assertFalse(this.b1.equals(new Object()));
49     }
50
51     @Test
52     public void testHashCode() {
53         final Set<Bandwidth> set = new HashSet<Bandwidth>();
54
55         set.add(this.b1);
56         assertEquals(1, set.size());
57
58         set.add(this.b2);
59         assertEquals(2, set.size());
60
61         set.add(this.b3);
62         assertEquals(2, set.size());
63
64         set.add(this.b4);
65         assertEquals(3, set.size());
66     }
67 }