blob: 58418b2877aa076e43b13e31f9d72200656aa5be [file] [log] [blame]
Ray Milkey85267002016-11-16 11:06:35 -08001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Ray Milkeydbf59f02016-08-19 12:54:16 -070016package org.onosproject.net.device;
17
18import org.junit.Test;
19import org.onosproject.net.PortNumber;
20
21import com.google.common.testing.EqualsTester;
22
23import static org.hamcrest.MatcherAssert.assertThat;
24import static org.hamcrest.Matchers.is;
25import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass;
26import static org.onosproject.net.Port.Type.COPPER;
27
28/**
29 * Unit tests for the DefaultPortDescription test.
30 */
31public class DefaultPortDescriptionTest {
32
33 private static PortNumber port1 = PortNumber.portNumber(1);
34 private static long portSpeed1 = 111L;
35 private static DefaultPortDescription portDescription1 =
36 new DefaultPortDescription(port1, true, COPPER, portSpeed1);
37
38 private static DefaultPortDescription sameAsPortDescription1 =
39 new DefaultPortDescription(portDescription1,
40 portDescription1.annotations());
41
42 private static PortNumber port2 = PortNumber.portNumber(2);
43 private static DefaultPortDescription portDescription2 =
44 new DefaultPortDescription(port2, true);
45
46 private static DefaultPortDescription portDescription3 =
47 new DefaultPortDescription();
48 /**
49 * Tests the immutability of {@link DefaultPortDescription}.
50 */
51 @Test
52 public void testImmutable() {
53 assertThatClassIsImmutableBaseClass(DefaultPortDescription.class);
54 }
55
56 /**
57 * Tests object construction and fetching of member data.
58 */
59 @Test
60 public void testConstruction() {
61 assertThat(portDescription1.portNumber(), is(port1));
62 assertThat(portDescription1.isEnabled(), is(true));
63 assertThat(portDescription1.portSpeed(), is(portSpeed1));
64 assertThat(portDescription1.type(), is(COPPER));
65 }
66
67 /**
68 * Tests equals(), hashCode(), and toString() methods.
69 */
70 @Test
71 public void testEquals() {
72 new EqualsTester()
73 .addEqualityGroup(portDescription1, sameAsPortDescription1)
74 .addEqualityGroup(portDescription2)
75 .addEqualityGroup(portDescription3)
76 .testEquals();
77 }
78}