Brian Stanke | aa6211a | 2016-02-04 18:22:54 -0500 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Brian Stanke | aa6211a | 2016-02-04 18:22:54 -0500 | [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 | */ |
| 16 | |
Claudine Chiu | 31ad527 | 2016-02-17 20:56:24 +0000 | [diff] [blame] | 17 | package org.onosproject.net.key; |
Brian Stanke | aa6211a | 2016-02-04 18:22:54 -0500 | [diff] [blame] | 18 | |
| 19 | import com.google.common.testing.EqualsTester; |
| 20 | import org.junit.Test; |
| 21 | |
| 22 | import static org.junit.Assert.assertEquals; |
| 23 | import static org.junit.Assert.assertNotNull; |
| 24 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 25 | |
| 26 | /** |
| 27 | * Test class for DeviceDeyId. |
| 28 | */ |
| 29 | public class DeviceKeyIdTest { |
| 30 | |
| 31 | final String deviceKeyIdValue1 = "DeviceKeyId1"; |
| 32 | final String deviceKeyIdValue2 = "DeviceKeyId2"; |
| 33 | |
| 34 | /** |
| 35 | * Checks that the DeviceKeyId class is immutable. |
| 36 | */ |
| 37 | @Test |
| 38 | public void testImmutability() { |
| 39 | assertThatClassIsImmutable(DeviceKeyId.class); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Checks the construction of a DeviceKeyId object throws an |
| 44 | * IllegalArgumentException when the input identifier is null. |
| 45 | */ |
| 46 | @Test(expected = NullPointerException.class) |
| 47 | public void testConstructionUsingNullId() { |
| 48 | DeviceKeyId.deviceKeyId(null); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Checks the construction of a DeviceKeyId object. |
| 53 | */ |
| 54 | @Test |
| 55 | public void testConstruction() { |
| 56 | DeviceKeyId deviceKeyId = DeviceKeyId.deviceKeyId(deviceKeyIdValue1); |
| 57 | assertNotNull("The deviceKeyId should not be null.", deviceKeyId); |
| 58 | assertEquals("The id should match the expected value.", |
| 59 | deviceKeyIdValue1, deviceKeyId.id()); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Tests the equality of device key identifiers. |
| 64 | */ |
| 65 | @Test |
| 66 | public void testEquality() { |
| 67 | DeviceKeyId deviceKeyId1 = DeviceKeyId.deviceKeyId(deviceKeyIdValue1); |
| 68 | DeviceKeyId deviceKeyId2 = DeviceKeyId.deviceKeyId(deviceKeyIdValue1); |
| 69 | DeviceKeyId deviceKeyId3 = DeviceKeyId.deviceKeyId(deviceKeyIdValue2); |
| 70 | |
| 71 | new EqualsTester().addEqualityGroup(deviceKeyId1, deviceKeyId2) |
| 72 | .addEqualityGroup(deviceKeyId3) |
| 73 | .testEquals(); |
| 74 | } |
| 75 | } |