Migrate deprecated assertThat()
[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.Assert.assertEquals;
14 import static org.junit.Assert.assertFalse;
15 import static org.junit.Assert.assertNotEquals;
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;
26     private Bandwidth b2;
27     private Bandwidth b3;
28     private Bandwidth b4;
29
30     @Before
31     public void setUp() {
32         this.b1 = new Bandwidth(Unpooled.copyInt(1000).array());
33         this.b2 = new Bandwidth(Unpooled.copyInt(2000).array());
34         this.b3 = new Bandwidth(Unpooled.copyInt(2000).array());
35         this.b4 = new Bandwidth(Unpooled.copyInt(100).array());
36     }
37
38     @Test
39     public void testBitsBytes() {
40         assertEquals(1000.0, Unpooled.wrappedBuffer(this.b1.getValue()).readInt(), 0.1);
41     }
42
43     @Test
44     public void testEquals() {
45         assertFalse(this.b1.equals(null));
46         assertThat(this.b1, not(equalTo(new Object())));
47         assertThat(this.b1, equalTo(this.b1));
48         assertThat(this.b1, not(equalTo(this.b2)));
49         assertEquals(this.b2, this.b3);
50         assertNotEquals(this.b1, new Object());
51     }
52
53     @Test
54     public void testHashCode() {
55         final Set<Bandwidth> set = new HashSet<>();
56
57         set.add(this.b1);
58         assertEquals(1, set.size());
59
60         set.add(this.b2);
61         assertEquals(2, set.size());
62
63         set.add(this.b3);
64         assertEquals(2, set.size());
65
66         set.add(this.b4);
67         assertEquals(3, set.size());
68     }
69 }