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 = |
Yuta HIGUCHI | 53e4796 | 2018-03-01 23:50:48 -0800 | [diff] [blame] | 36 | DefaultPortDescription.builder().withPortNumber(port1).isEnabled(true) |
| 37 | .type(COPPER).portSpeed(portSpeed1).build(); |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 38 | |
| 39 | private static DefaultPortDescription sameAsPortDescription1 = |
Yuta HIGUCHI | 53e4796 | 2018-03-01 23:50:48 -0800 | [diff] [blame] | 40 | DefaultPortDescription.builder(portDescription1) |
| 41 | .annotations(portDescription1.annotations()) |
| 42 | .build(); |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 43 | |
| 44 | private static PortNumber port2 = PortNumber.portNumber(2); |
| 45 | private static DefaultPortDescription portDescription2 = |
Yuta HIGUCHI | 53e4796 | 2018-03-01 23:50:48 -0800 | [diff] [blame] | 46 | DefaultPortDescription.builder().withPortNumber(port2).isEnabled(true).build(); |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 47 | |
| 48 | private static DefaultPortDescription portDescription3 = |
| 49 | new DefaultPortDescription(); |
| 50 | /** |
| 51 | * Tests the immutability of {@link DefaultPortDescription}. |
| 52 | */ |
| 53 | @Test |
| 54 | public void testImmutable() { |
| 55 | assertThatClassIsImmutableBaseClass(DefaultPortDescription.class); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Tests object construction and fetching of member data. |
| 60 | */ |
| 61 | @Test |
| 62 | public void testConstruction() { |
| 63 | assertThat(portDescription1.portNumber(), is(port1)); |
| 64 | assertThat(portDescription1.isEnabled(), is(true)); |
| 65 | assertThat(portDescription1.portSpeed(), is(portSpeed1)); |
| 66 | assertThat(portDescription1.type(), is(COPPER)); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Tests equals(), hashCode(), and toString() methods. |
| 71 | */ |
| 72 | @Test |
| 73 | public void testEquals() { |
| 74 | new EqualsTester() |
| 75 | .addEqualityGroup(portDescription1, sameAsPortDescription1) |
| 76 | .addEqualityGroup(portDescription2) |
| 77 | .addEqualityGroup(portDescription3) |
| 78 | .testEquals(); |
| 79 | } |
| 80 | } |