3453972e79cf10399ec7d9759367fa5a56ccad6f
[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 io.netty.buffer.Unpooled;
18 import java.util.HashSet;
19 import java.util.Set;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
23
24 public class BandwidthTest {
25     private Bandwidth b1, b2, b3, b4;
26
27     @Before
28     public void setUp() {
29         this.b1 = new Bandwidth(Unpooled.copyInt(1000).array());
30         this.b2 = new Bandwidth(Unpooled.copyInt(2000).array());
31         this.b3 = new Bandwidth(Unpooled.copyInt(2000).array());
32         this.b4 = new Bandwidth(Unpooled.copyInt(100).array());
33     }
34
35     @Test
36     public void testBitsBytes() {
37         assertEquals(1000.0, Unpooled.wrappedBuffer(this.b1.getValue()).readInt(), 0.1);
38     }
39
40     @Test
41     public void testEquals() {
42         assertFalse(this.b1.equals(null));
43         assertThat(this.b1, not(equalTo(new Object())));
44         assertThat(this.b1, equalTo(this.b1));
45         assertThat(this.b1, not(equalTo(this.b2)));
46         assertEquals(this.b2, this.b3);
47         assertFalse(this.b1.equals(new Object()));
48     }
49
50     @Test
51     public void testHashCode() {
52         final Set<Bandwidth> set = new HashSet<Bandwidth>();
53
54         set.add(this.b1);
55         assertEquals(1, set.size());
56
57         set.add(this.b2);
58         assertEquals(2, set.size());
59
60         set.add(this.b3);
61         assertEquals(2, set.size());
62
63         set.add(this.b4);
64         assertEquals(3, set.size());
65     }
66 }