Ray Milkey | 8526700 | 2016-11-16 11:06:35 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Ray Milkey | 8526700 | 2016-11-16 11:06:35 -0800 | [diff] [blame] | 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 Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 16 | package org.onosproject.net.device; |
| 17 | |
| 18 | import org.junit.Test; |
| 19 | import org.onosproject.net.PortNumber; |
| 20 | |
| 21 | import com.google.common.testing.EqualsTester; |
| 22 | |
| 23 | import static org.hamcrest.MatcherAssert.assertThat; |
| 24 | import static org.hamcrest.Matchers.is; |
| 25 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass; |
| 26 | import static org.onosproject.net.Port.Type.COPPER; |
| 27 | |
| 28 | /** |
| 29 | * Unit tests for the DefaultPortDescription test. |
| 30 | */ |
| 31 | public 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 | } |