Bump versions to 0.21.8-SNAPSHOT
[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 package org.opendaylight.protocol.concepts;
9
10 import static org.hamcrest.CoreMatchers.equalTo;
11 import static org.hamcrest.CoreMatchers.not;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.jupiter.api.Assertions.assertEquals;
14 import static org.junit.jupiter.api.Assertions.assertFalse;
15 import static org.junit.jupiter.api.Assertions.assertNotEquals;
16
17 import io.netty.buffer.Unpooled;
18 import java.util.HashSet;
19 import org.junit.jupiter.api.Test;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
21
22 class BandwidthTest {
23     private static final Bandwidth B1 = new Bandwidth(Unpooled.copyInt(1000).array());
24     private static final Bandwidth B2 = new Bandwidth(Unpooled.copyInt(2000).array());
25     private static final Bandwidth B3 = new Bandwidth(Unpooled.copyInt(2000).array());
26     private static final Bandwidth B4 = new Bandwidth(Unpooled.copyInt(100).array());
27
28     @Test
29     void testBitsBytes() {
30         assertEquals(1000.0, Unpooled.wrappedBuffer(B1.getValue()).readInt(), 0.1);
31     }
32
33     @Test
34     void testEquals() {
35         assertFalse(B1.equals(null));
36         assertThat(B1, not(equalTo(new Object())));
37         assertThat(B1, equalTo(B1));
38         assertThat(B1, not(equalTo(B2)));
39         assertEquals(B2, B3);
40         assertNotEquals(B1, new Object());
41     }
42
43     @Test
44     void testHashCode() {
45         final var set = new HashSet<Bandwidth>();
46
47         set.add(B1);
48         assertEquals(1, set.size());
49
50         set.add(B2);
51         assertEquals(2, set.size());
52
53         set.add(B3);
54         assertEquals(2, set.size());
55
56         set.add(B4);
57         assertEquals(3, set.size());
58     }
59 }