Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 1 | package org.onosproject.net.device; |
| 2 | |
| 3 | import org.junit.Test; |
| 4 | import org.onosproject.net.PortNumber; |
| 5 | |
| 6 | import com.google.common.testing.EqualsTester; |
| 7 | |
| 8 | import static org.hamcrest.MatcherAssert.assertThat; |
| 9 | import static org.hamcrest.Matchers.is; |
| 10 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass; |
| 11 | import static org.onosproject.net.Port.Type.COPPER; |
| 12 | |
| 13 | /** |
| 14 | * Unit tests for the DefaultPortDescription test. |
| 15 | */ |
| 16 | public 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 | } |