Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [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 | |
| 17 | package org.onosproject.net.pi.runtime; |
| 18 | |
| 19 | import com.google.common.testing.EqualsTester; |
| 20 | import org.junit.Test; |
| 21 | |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 22 | import static org.hamcrest.MatcherAssert.assertThat; |
| 23 | import static org.hamcrest.Matchers.is; |
| 24 | import static org.hamcrest.Matchers.notNullValue; |
| 25 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 26 | |
| 27 | /** |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 28 | * Unit tests for PiActionProfileGroupId class. |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 29 | */ |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 30 | public class PiActionProfileGroupIdTest { |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 31 | |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 32 | final PiActionProfileGroupId piActionGroupId1 = PiActionProfileGroupId.of(10); |
| 33 | final PiActionProfileGroupId sameAsPiActionProfileGroupId1 = PiActionProfileGroupId.of(10); |
| 34 | final PiActionProfileGroupId piActionGroupId2 = PiActionProfileGroupId.of(20); |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 35 | |
| 36 | /** |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 37 | * Checks that the PiActionProfileGroupId class is immutable. |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 38 | */ |
| 39 | @Test |
| 40 | public void testImmutability() { |
| 41 | |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 42 | assertThatClassIsImmutable(PiActionProfileGroupId.class); |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Checks the operation of equals(), hashCode() and toString() methods. |
| 47 | */ |
| 48 | @Test |
| 49 | public void testEquals() { |
| 50 | |
| 51 | new EqualsTester() |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 52 | .addEqualityGroup(piActionGroupId1, sameAsPiActionProfileGroupId1) |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 53 | .addEqualityGroup(piActionGroupId2) |
| 54 | .testEquals(); |
| 55 | } |
| 56 | |
| 57 | /** |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 58 | * Checks the methods of PiActionProfileGroupId. |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 59 | */ |
| 60 | @Test |
| 61 | public void testMethods() { |
| 62 | |
| 63 | assertThat(piActionGroupId1, is(notNullValue())); |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 64 | assertThat(piActionGroupId1.type(), is(PiTableAction.Type.ACTION_PROFILE_GROUP_ID)); |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 65 | assertThat(piActionGroupId1.id(), is(10)); |
| 66 | } |
| 67 | } |