blob: 2069d6b49b5b90f9bedf8f6751bdac29f931d134 [file] [log] [blame]
Ray Milkeydbf59f02016-08-19 12:54:16 -07001package org.onosproject.net.device;
2
3import org.junit.Test;
4import org.onosproject.net.PortNumber;
5
6import com.google.common.testing.EqualsTester;
7
8import static org.hamcrest.MatcherAssert.assertThat;
9import static org.hamcrest.Matchers.is;
10import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass;
11import static org.onosproject.net.Port.Type.COPPER;
12
13/**
14 * Unit tests for the DefaultPortDescription test.
15 */
16public class DefaultPortDescriptionTest {
17
18 private static PortNumber port1 = PortNumber.portNumber(1);
19 private static long portSpeed1 = 111L;
20 private static DefaultPortDescription portDescription1 =
21 new DefaultPortDescription(port1, true, COPPER, portSpeed1);
22
23 private static DefaultPortDescription sameAsPortDescription1 =
24 new DefaultPortDescription(portDescription1,
25 portDescription1.annotations());
26
27 private static PortNumber port2 = PortNumber.portNumber(2);
28 private static DefaultPortDescription portDescription2 =
29 new DefaultPortDescription(port2, true);
30
31 private static DefaultPortDescription portDescription3 =
32 new DefaultPortDescription();
33 /**
34 * Tests the immutability of {@link DefaultPortDescription}.
35 */
36 @Test
37 public void testImmutable() {
38 assertThatClassIsImmutableBaseClass(DefaultPortDescription.class);
39 }
40
41 /**
42 * Tests object construction and fetching of member data.
43 */
44 @Test
45 public void testConstruction() {
46 assertThat(portDescription1.portNumber(), is(port1));
47 assertThat(portDescription1.isEnabled(), is(true));
48 assertThat(portDescription1.portSpeed(), is(portSpeed1));
49 assertThat(portDescription1.type(), is(COPPER));
50 }
51
52 /**
53 * Tests equals(), hashCode(), and toString() methods.
54 */
55 @Test
56 public void testEquals() {
57 new EqualsTester()
58 .addEqualityGroup(portDescription1, sameAsPortDescription1)
59 .addEqualityGroup(portDescription2)
60 .addEqualityGroup(portDescription3)
61 .testEquals();
62 }
63}