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
9 package org.opendaylight.protocol.concepts;
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;
17 import java.util.HashSet;
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;
25 public class BandwidthTest {
26 private Bandwidth b1, b2, b3, b4;
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));
37 public void testBitsBytes() {
38 assertEquals(1000.0, ByteArray.bytesToLong(this.b1.getValue()), 0.1);
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()));
52 public void testHashCode() {
53 final Set<Bandwidth> set = new HashSet<Bandwidth>();
56 assertEquals(1, set.size());
59 assertEquals(2, set.size());
62 assertEquals(2, set.size());
65 assertEquals(3, set.size());