2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.concepts;
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;
17 import io.netty.buffer.Unpooled;
18 import java.util.HashSet;
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;
24 public class BandwidthTest {
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());
39 public void testBitsBytes() {
40 assertEquals(1000.0, Unpooled.wrappedBuffer(this.b1.getValue()).readInt(), 0.1);
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());
54 public void testHashCode() {
55 final Set<Bandwidth> set = new HashSet<>();
58 assertEquals(1, set.size());
61 assertEquals(2, set.size());
64 assertEquals(2, set.size());
67 assertEquals(3, set.size());