blob: eb1de71f3d9876e7832af2bdeee4bf150b64002b [file] [log] [blame]
Frank Wange33e4ed2017-06-28 10:01:07 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Frank Wange33e4ed2017-06-28 10:01:07 +08003 *
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.net.pi.runtime;
18
19import com.google.common.testing.EqualsTester;
20import org.junit.Test;
Carmelo Cascone87892e22017-11-13 16:01:29 -080021import org.onosproject.net.pi.model.PiTableId;
Frank Wange33e4ed2017-06-28 10:01:07 +080022
23import static org.hamcrest.MatcherAssert.assertThat;
24import static org.hamcrest.Matchers.is;
25import static org.hamcrest.Matchers.notNullValue;
26import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
27
28/**
29 * Unit tests for PiTableId class.
30 */
31public class PiTableIdTest {
Carmelo Cascone87892e22017-11-13 16:01:29 -080032 private final String table10 = "table10";
33 private final String table20 = "table20";
34 private final PiTableId piTableId1 = PiTableId.of(table10);
35 private final PiTableId sameAsPiTableId1 = PiTableId.of(table10);
36 private final PiTableId piTableId2 = PiTableId.of(table20);
Frank Wange33e4ed2017-06-28 10:01:07 +080037
Frank Wange33e4ed2017-06-28 10:01:07 +080038 /**
39 * Checks that the PiTableId class is immutable.
40 */
41 @Test
42 public void testImmutability() {
43 assertThatClassIsImmutable(PiTableId.class);
44 }
45
46 /**
47 * Checks the operation of equals(), hashCode() and toString() methods.
48 */
49 @Test
50 public void testEquals() {
51 new EqualsTester()
52 .addEqualityGroup(piTableId1, sameAsPiTableId1)
53 .addEqualityGroup(piTableId2)
54 .testEquals();
55 }
56
57 /**
Frank Wange33e4ed2017-06-28 10:01:07 +080058 * Checks the construction of a PiTableId object.
59 */
60 @Test
61 public void testConstruction() {
Carmelo Cascone87892e22017-11-13 16:01:29 -080062 assertThat(piTableId1, is(notNullValue()));
63 assertThat(piTableId1.id(), is(table10));
Frank Wange33e4ed2017-06-28 10:01:07 +080064 }
65}