blob: 5f6c477c42ef79960d04c0bbf9638dd90699cbc8 [file] [log] [blame]
Brian Stankeaa6211a2016-02-04 18:22:54 -05001/*
2 * Copyright 2016 Open Networking Laboratory
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
17package org.onosproject.incubator.net.key;
18
19import com.google.common.testing.EqualsTester;
20import org.junit.Test;
21
22import static org.junit.Assert.assertEquals;
23import static org.junit.Assert.assertNotNull;
24import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
25
26/**
27 * Test class for DeviceDeyId.
28 */
29public 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}