Ray Milkey | ec253f8 | 2017-09-20 16:29:19 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | */ |
| 16 | package org.onosproject.net.behaviour; |
| 17 | |
| 18 | import org.junit.Test; |
| 19 | |
| 20 | import com.google.common.testing.EqualsTester; |
| 21 | |
| 22 | import static com.spotify.hamcrest.optional.OptionalMatchers.optionalWithValue; |
| 23 | import static org.hamcrest.MatcherAssert.assertThat; |
| 24 | import static org.hamcrest.Matchers.is; |
| 25 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 26 | |
| 27 | |
| 28 | public class DefaultPatchDescriptionTest { |
| 29 | |
| 30 | private String deviceId1 = "d1"; |
| 31 | private String ifaceName1 = "i1"; |
| 32 | private String peerName1 = "p1"; |
| 33 | |
| 34 | private PatchDescription defaultPatchDescription1 = |
| 35 | DefaultPatchDescription.builder() |
| 36 | .deviceId(deviceId1) |
| 37 | .ifaceName(ifaceName1) |
| 38 | .peer(peerName1) |
| 39 | .build(); |
| 40 | private PatchDescription sameAsDefaultPatchDescription1 = |
| 41 | DefaultPatchDescription.builder() |
| 42 | .deviceId(deviceId1) |
| 43 | .ifaceName(ifaceName1) |
| 44 | .peer(peerName1) |
| 45 | .build(); |
| 46 | private PatchDescription defaultPatchDescription2 = |
| 47 | DefaultPatchDescription.builder() |
| 48 | .deviceId(deviceId1 + "2") |
| 49 | .ifaceName(ifaceName1) |
| 50 | .peer(peerName1) |
| 51 | .build(); |
| 52 | private PatchDescription defaultPatchDescription3 = |
| 53 | DefaultPatchDescription.builder() |
| 54 | .deviceId(deviceId1) |
| 55 | .ifaceName(ifaceName1 + "2") |
| 56 | .peer(peerName1) |
| 57 | .build(); |
| 58 | private PatchDescription defaultPatchDescription4 = |
| 59 | DefaultPatchDescription.builder() |
| 60 | .deviceId(deviceId1) |
| 61 | .ifaceName(ifaceName1) |
| 62 | .peer(peerName1 + "2") |
| 63 | .build(); |
| 64 | private PatchDescription defaultPatchDescriptionNoDeviceId = |
| 65 | DefaultPatchDescription.builder() |
| 66 | .ifaceName(ifaceName1) |
| 67 | .peer(peerName1 + "2") |
| 68 | .build(); |
| 69 | |
| 70 | @Test |
| 71 | public void testImmutability() { |
| 72 | assertThatClassIsImmutable(DefaultPatchDescription.class); |
| 73 | } |
| 74 | |
| 75 | @Test |
| 76 | public void testConstruction() { |
| 77 | assertThat(defaultPatchDescription1.deviceId(), optionalWithValue(is(deviceId1))); |
| 78 | assertThat(defaultPatchDescription1.ifaceName(), is(ifaceName1)); |
| 79 | assertThat(defaultPatchDescription1.peer(), is(peerName1)); |
| 80 | } |
| 81 | |
| 82 | @Test |
| 83 | public void testEquals() { |
| 84 | new EqualsTester() |
| 85 | .addEqualityGroup(defaultPatchDescription1, sameAsDefaultPatchDescription1) |
| 86 | .addEqualityGroup(defaultPatchDescription2) |
| 87 | .addEqualityGroup(defaultPatchDescription3) |
| 88 | .addEqualityGroup(defaultPatchDescription4) |
| 89 | .addEqualityGroup(defaultPatchDescriptionNoDeviceId) |
| 90 | .testEquals(); |
| 91 | } |
| 92 | } |