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.Ignore;
22 import org.junit.Test;
23 import org.opendaylight.protocol.util.ByteArray;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Bandwidth;
26 public class BandwidthTest {
27 private Bandwidth b1, b2, b3, b4;
31 this.b1 = new Bandwidth(ByteArray.intToBytes(1000));
32 this.b2 = new Bandwidth(ByteArray.intToBytes(2000));
33 this.b3 = new Bandwidth(ByteArray.intToBytes(2000));
34 this.b4 = new Bandwidth(ByteArray.intToBytes(100));
38 public void testBitsBytes() {
39 assertEquals(1000.0, ByteArray.bytesToLong(this.b1.getValue()), 0.1);
43 public void testEquals() {
44 assertFalse(this.b1.equals(null));
45 assertThat(this.b1, not(equalTo(new Object())));
46 assertThat(this.b1, equalTo(this.b1));
47 assertThat(this.b1, not(equalTo(this.b2)));
48 assertEquals(this.b2, this.b3);
49 assertFalse(this.b1.equals(new Object()));
53 public void testHashCode() {
54 final Set<Bandwidth> set = new HashSet<Bandwidth>();
57 assertEquals(1, set.size());
60 assertEquals(2, set.size());
63 assertEquals(2, set.size());
66 assertEquals(3, set.size());